@@ -134,29 +134,23 @@ class DriveOnHeading : public TimedBehavior<ActionT>
134134 cmd_vel->header .frame_id = this ->robot_base_frame_ ;
135135 cmd_vel->twist .linear .y = 0.0 ;
136136 cmd_vel->twist .angular .z = 0.0 ;
137- if (acceleration_limit_ <= 0.0 && deceleration_limit_ <= 0.0 ) {
137+ if (acceleration_limit_ <= 0.0 || deceleration_limit_ <= 0.0 ) {
138138 cmd_vel->twist .linear .x = command_speed_;
139139 } else {
140140 double current_speed = last_vel_ == std::numeric_limits<double >::max () ? 0.0 : last_vel_;
141- auto remaining_distance = std::fabs (command_x_) - distance;
142- double min_feasible_speed = -std::numeric_limits<double >::infinity ();
143- double max_feasible_speed = std::numeric_limits<double >::infinity ();
144- if (deceleration_limit_ > 0.0 ) {
145- min_feasible_speed = current_speed - deceleration_limit_ / this ->cycle_frequency_ ;
146- }
147- if (acceleration_limit_ > 0.0 ) {
148- max_feasible_speed = current_speed + acceleration_limit_ / this ->cycle_frequency_ ;
149- }
141+
142+ double min_feasible_speed = current_speed - deceleration_limit_ / this ->cycle_frequency_ ;
143+ double max_feasible_speed = current_speed + acceleration_limit_ / this ->cycle_frequency_ ;
150144 cmd_vel->twist .linear .x = std::clamp (command_speed_, min_feasible_speed, max_feasible_speed);
151145
152146 // Check if we need to slow down to avoid overshooting
153- bool forward = command_speed_ > 0.0 ;
154- if (forward && deceleration_limit_ > 0.0 ) {
147+ auto remaining_distance = std::fabs (command_x_) - distance ;
148+ if (command_speed_ > 0.0 ) {
155149 double max_vel_to_stop = std::sqrt (2.0 * deceleration_limit_ * remaining_distance);
156150 if (max_vel_to_stop < cmd_vel->twist .linear .x ) {
157151 cmd_vel->twist .linear .x = max_vel_to_stop;
158152 }
159- } else if (!forward && acceleration_limit_ > 0.0 ) {
153+ } else {
160154 double max_vel_to_stop = -std::sqrt (2.0 * acceleration_limit_ * remaining_distance);
161155 if (max_vel_to_stop > cmd_vel->twist .linear .x ) {
162156 cmd_vel->twist .linear .x = max_vel_to_stop;
0 commit comments