@@ -137,7 +137,7 @@ class DriveOnHeading : public TimedBehavior<ActionT>
137
137
if (acceleration_limit_ <= 0.0 && deceleration_limit_ <= 0.0 ) {
138
138
cmd_vel->twist .linear .x = command_speed_;
139
139
} else {
140
- double current_speed = last_vel_ ? *last_vel_ : 0.0 ;
140
+ double current_speed = last_vel_ == std::numeric_limits< double >:: max () ? 0.0 : last_vel_ ;
141
141
auto remaining_distance = std::fabs (command_x_) - distance;
142
142
double min_feasible_speed = -std::numeric_limits<double >::infinity ();
143
143
double max_feasible_speed = std::numeric_limits<double >::infinity ();
@@ -150,7 +150,7 @@ class DriveOnHeading : public TimedBehavior<ActionT>
150
150
cmd_vel->twist .linear .x = std::clamp (command_speed_, min_feasible_speed, max_feasible_speed);
151
151
152
152
// Check if we need to slow down to avoid overshooting
153
- bool forward = command_speed_ > 0.0 ? true : false ;
153
+ bool forward = command_speed_ > 0.0 ;
154
154
if (forward && deceleration_limit_ > 0.0 ) {
155
155
double max_vel_to_stop = std::sqrt (2.0 * deceleration_limit_ * remaining_distance);
156
156
if (max_vel_to_stop < cmd_vel->twist .linear .x ) {
@@ -175,7 +175,7 @@ class DriveOnHeading : public TimedBehavior<ActionT>
175
175
return ResultStatus{Status::FAILED, ActionT::Result::COLLISION_AHEAD};
176
176
}
177
177
178
- last_vel_ = std::make_shared< double >( cmd_vel->twist .linear .x ) ;
178
+ last_vel_ = cmd_vel->twist .linear .x ;
179
179
180
180
this ->vel_pub_ ->publish (std::move (cmd_vel));
181
181
@@ -188,9 +188,9 @@ class DriveOnHeading : public TimedBehavior<ActionT>
188
188
*/
189
189
CostmapInfoType getResourceInfo () override {return CostmapInfoType::LOCAL;}
190
190
191
- void onCleanup () override {last_vel_. reset ();}
191
+ void onCleanup () override {last_vel_ = std::numeric_limits< double >:: max ();}
192
192
193
- void onActionCompletion () override {last_vel_. reset ();}
193
+ void onActionCompletion () override {last_vel_ = std::numeric_limits< double >:: max ();}
194
194
195
195
protected:
196
196
/* *
@@ -271,7 +271,7 @@ class DriveOnHeading : public TimedBehavior<ActionT>
271
271
double simulate_ahead_time_;
272
272
double acceleration_limit_;
273
273
double deceleration_limit_;
274
- std::shared_ptr <double > last_vel_ ;
274
+ double last_vel_ = std::numeric_limits <double >::max() ;
275
275
};
276
276
277
277
} // namespace nav2_behaviors
0 commit comments