Skip to content

Commit a268833

Browse files
AmronosJuliaj
andauthored
Apply suggestions from code review
Co-authored-by: Julia Jia <[email protected]>
1 parent b474fde commit a268833

File tree

3 files changed

+17
-9
lines changed

3 files changed

+17
-9
lines changed

diff_drive_controller/include/diff_drive_controller/odometry.hpp

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,17 +40,16 @@ class Odometry
4040
[[deprecated]]
4141
void init(const rclcpp::Time & time);
4242
[[deprecated(
43-
"Replaced by bool update_from_pos(double left_pos, double right_pos, const "
44-
"rclcpp::Time & time).")]]
43+
"Replaced by bool update_from_pos(double left_pos, double right_pos, double "
44+
"dt).")]]
4545
bool update(double left_pos, double right_pos, const rclcpp::Time & time);
46-
[[deprecated(
47-
"Replaced by bool update_from_vel(double left_vel, double right_vel, const "
48-
"rclcpp::Time & time).")]]
46+
[[deprecated(
47+
"Replaced by bool update_from_vel(double left_vel, double right_vel, double "
48+
"dt).")]]
4949
bool updateFromVelocity(double left_vel, double right_vel, const rclcpp::Time & time);
5050
[[deprecated(
51-
"Replaced by bool try_update_open_loop(double linear_vel, double angular_vel, const "
52-
"rclcpp::Time "
53-
"& time).")]]
51+
"Replaced by bool try_update_open_loop(double linear_vel, double angular_vel, double "
52+
"dt).")]]
5453
void updateOpenLoop(double linear, double angular, const rclcpp::Time & time);
5554

5655
bool update_from_pos(double left_pos, double right_pos, double dt);

diff_drive_controller/src/diff_drive_controller.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ controller_interface::return_type DiffDriveController::update_and_write_commands
221221
bool should_publish = false;
222222
try
223223
{
224-
if (previous_publish_timestamp_ + publish_period_ < time)
224+
if (previous_publish_timestamp_ + publish_period_ <= time)
225225
{
226226
previous_publish_timestamp_ += publish_period_;
227227
should_publish = true;

diff_drive_controller/src/odometry.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,10 @@ bool Odometry::updateFromVelocity(double left_vel, double right_vel, const rclcp
121121

122122
bool Odometry::update_from_vel(double left_vel, double right_vel, double dt)
123123
{
124+
if (std::fabs(dt) < 1e-6)
125+
{
126+
return false; // Interval too small to integrate with
127+
}
124128
// Compute linear and angular velocities of the robot:
125129
const double linear_vel = (left_vel * left_wheel_radius_ + right_vel * right_wheel_radius_) * 0.5;
126130
const double angular_vel =
@@ -214,6 +218,11 @@ void Odometry::integrateExact(double linear, double angular)
214218

215219
void Odometry::integrate(double linear_vel, double angular_vel, double dt)
216220
{
221+
// Skip integration for invalid time intervals
222+
if (std::fabs(dt) < 1e-6)
223+
{
224+
return;
225+
}
217226
const double dx = linear_vel * dt;
218227
const double dheading = angular_vel * dt;
219228
if (fabs(dheading) < 1e-6)

0 commit comments

Comments
 (0)