-
Notifications
You must be signed in to change notification settings - Fork 431
Update odometry implementation in diff_drive #1854
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 23 commits
fe3a568
13edbec
629cf5e
d387750
bd1283b
3048023
93806d6
1d47fed
a52855b
77eade3
831c9c7
a95a450
8ecb548
ec25473
3e04f37
93b0c0c
620aec5
574c3ba
f52b6b1
5c2620c
6a6c38c
e28abfa
b474fde
a268833
d85632f
8dc9951
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -160,9 +160,12 @@ controller_interface::return_type DiffDriveController::update_and_write_commands | |
| const double left_wheel_radius = params_.left_wheel_radius_multiplier * params_.wheel_radius; | ||
| const double right_wheel_radius = params_.right_wheel_radius_multiplier * params_.wheel_radius; | ||
|
|
||
| // Update odometry | ||
| bool odometry_updated = false; | ||
| if (params_.open_loop) | ||
| { | ||
| odometry_.updateOpenLoop(linear_command, angular_command, time); | ||
| odometry_updated = | ||
| odometry_.try_update_open_loop(linear_command, angular_command, period.seconds()); | ||
| } | ||
| else | ||
| { | ||
|
|
@@ -200,62 +203,65 @@ controller_interface::return_type DiffDriveController::update_and_write_commands | |
|
|
||
| if (params_.position_feedback) | ||
| { | ||
| odometry_.update(left_feedback_mean, right_feedback_mean, time); | ||
| odometry_updated = | ||
| odometry_.update_from_pos(left_feedback_mean, right_feedback_mean, period.seconds()); | ||
| } | ||
| else | ||
| { | ||
| odometry_.updateFromVelocity( | ||
| left_feedback_mean * left_wheel_radius * period.seconds(), | ||
| right_feedback_mean * right_wheel_radius * period.seconds(), time); | ||
| odometry_updated = | ||
| odometry_.update_from_vel(left_feedback_mean, right_feedback_mean, period.seconds()); | ||
| } | ||
| } | ||
|
|
||
| tf2::Quaternion orientation; | ||
| orientation.setRPY(0.0, 0.0, odometry_.getHeading()); | ||
|
|
||
| bool should_publish = false; | ||
| try | ||
| if (odometry_updated) | ||
| { | ||
| if (previous_publish_timestamp_ + publish_period_ < time) | ||
| tf2::Quaternion orientation; | ||
| orientation.setRPY(0.0, 0.0, odometry_.getHeading()); | ||
|
|
||
| bool should_publish = false; | ||
| try | ||
| { | ||
| previous_publish_timestamp_ += publish_period_; | ||
| should_publish = true; | ||
| if (previous_publish_timestamp_ + publish_period_ < time) | ||
Amronos marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| { | ||
| previous_publish_timestamp_ += publish_period_; | ||
| should_publish = true; | ||
| } | ||
| } | ||
| } | ||
| catch (const std::runtime_error &) | ||
| { | ||
| // Handle exceptions when the time source changes and initialize publish timestamp | ||
| previous_publish_timestamp_ = time; | ||
| should_publish = true; | ||
| } | ||
|
|
||
| if (should_publish) | ||
| { | ||
| if (realtime_odometry_publisher_) | ||
| catch (const std::runtime_error &) | ||
| { | ||
| odometry_message_.header.stamp = time; | ||
| odometry_message_.pose.pose.position.x = odometry_.getX(); | ||
| odometry_message_.pose.pose.position.y = odometry_.getY(); | ||
| odometry_message_.pose.pose.orientation.x = orientation.x(); | ||
| odometry_message_.pose.pose.orientation.y = orientation.y(); | ||
| odometry_message_.pose.pose.orientation.z = orientation.z(); | ||
| odometry_message_.pose.pose.orientation.w = orientation.w(); | ||
| odometry_message_.twist.twist.linear.x = odometry_.getLinear(); | ||
| odometry_message_.twist.twist.angular.z = odometry_.getAngular(); | ||
| realtime_odometry_publisher_->try_publish(odometry_message_); | ||
| // Handle exceptions when the time source changes and initialize publish timestamp | ||
| previous_publish_timestamp_ = time; | ||
| should_publish = true; | ||
| } | ||
|
Comment on lines
+230
to
235
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this block meant to catch the error of previous_publish_timestamp as unintialized ? if so, we should initialize it in on_configure. If not, this block may not be reachable.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This isn't really a part of the changes made in this PR, perhaps create a separate issue? A similar pattern exists in other controllers as well, so the change will need to be propagated to them as well.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You are right, this existed before and the diff is just not properly rendered by the UI. @Juliaj please open a (first) issue with this.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
|
||
| if (params_.enable_odom_tf && realtime_odometry_transform_publisher_) | ||
| if (should_publish) | ||
| { | ||
| auto & transform = odometry_transform_message_.transforms.front(); | ||
| transform.header.stamp = time; | ||
| transform.transform.translation.x = odometry_.getX(); | ||
| transform.transform.translation.y = odometry_.getY(); | ||
| transform.transform.rotation.x = orientation.x(); | ||
| transform.transform.rotation.y = orientation.y(); | ||
| transform.transform.rotation.z = orientation.z(); | ||
| transform.transform.rotation.w = orientation.w(); | ||
| realtime_odometry_transform_publisher_->try_publish(odometry_transform_message_); | ||
| if (realtime_odometry_publisher_) | ||
| { | ||
| odometry_message_.header.stamp = time; | ||
| odometry_message_.pose.pose.position.x = odometry_.getX(); | ||
| odometry_message_.pose.pose.position.y = odometry_.getY(); | ||
| odometry_message_.pose.pose.orientation.x = orientation.x(); | ||
| odometry_message_.pose.pose.orientation.y = orientation.y(); | ||
| odometry_message_.pose.pose.orientation.z = orientation.z(); | ||
| odometry_message_.pose.pose.orientation.w = orientation.w(); | ||
| odometry_message_.twist.twist.linear.x = odometry_.getLinear(); | ||
| odometry_message_.twist.twist.angular.z = odometry_.getAngular(); | ||
| realtime_odometry_publisher_->try_publish(odometry_message_); | ||
| } | ||
|
|
||
| if (params_.enable_odom_tf && realtime_odometry_transform_publisher_) | ||
| { | ||
| auto & transform = odometry_transform_message_.transforms.front(); | ||
| transform.header.stamp = time; | ||
| transform.transform.translation.x = odometry_.getX(); | ||
| transform.transform.translation.y = odometry_.getY(); | ||
| transform.transform.rotation.x = orientation.x(); | ||
| transform.transform.rotation.y = orientation.y(); | ||
| transform.transform.rotation.z = orientation.z(); | ||
| transform.transform.rotation.w = orientation.w(); | ||
| realtime_odometry_transform_publisher_->try_publish(odometry_transform_message_); | ||
| } | ||
| } | ||
| } | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.