@@ -134,29 +134,23 @@ class DriveOnHeading : public TimedBehavior<ActionT>
134
134
cmd_vel->header .frame_id = this ->robot_base_frame_ ;
135
135
cmd_vel->twist .linear .y = 0.0 ;
136
136
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 ) {
138
138
cmd_vel->twist .linear .x = command_speed_;
139
139
} else {
140
140
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_ ;
150
144
cmd_vel->twist .linear .x = std::clamp (command_speed_, min_feasible_speed, max_feasible_speed);
151
145
152
146
// 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 ) {
155
149
double max_vel_to_stop = std::sqrt (2.0 * deceleration_limit_ * remaining_distance);
156
150
if (max_vel_to_stop < cmd_vel->twist .linear .x ) {
157
151
cmd_vel->twist .linear .x = max_vel_to_stop;
158
152
}
159
- } else if (!forward && acceleration_limit_ > 0.0 ) {
153
+ } else {
160
154
double max_vel_to_stop = -std::sqrt (2.0 * acceleration_limit_ * remaining_distance);
161
155
if (max_vel_to_stop > cmd_vel->twist .linear .x ) {
162
156
cmd_vel->twist .linear .x = max_vel_to_stop;
0 commit comments