Skip to content

Commit fe58475

Browse files
committed
Remove vel pointer
1 parent 228de3b commit fe58475

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

nav2_behaviors/include/nav2_behaviors/plugins/drive_on_heading.hpp

+6-6
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ class DriveOnHeading : public TimedBehavior<ActionT>
137137
if (acceleration_limit_ <= 0.0 && deceleration_limit_ <= 0.0) {
138138
cmd_vel->twist.linear.x = command_speed_;
139139
} 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_;
141141
auto remaining_distance = std::fabs(command_x_) - distance;
142142
double min_feasible_speed = -std::numeric_limits<double>::infinity();
143143
double max_feasible_speed = std::numeric_limits<double>::infinity();
@@ -150,7 +150,7 @@ class DriveOnHeading : public TimedBehavior<ActionT>
150150
cmd_vel->twist.linear.x = std::clamp(command_speed_, min_feasible_speed, max_feasible_speed);
151151

152152
// 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;
154154
if (forward && deceleration_limit_ > 0.0) {
155155
double max_vel_to_stop = std::sqrt(2.0 * deceleration_limit_ * remaining_distance);
156156
if (max_vel_to_stop < cmd_vel->twist.linear.x) {
@@ -175,7 +175,7 @@ class DriveOnHeading : public TimedBehavior<ActionT>
175175
return ResultStatus{Status::FAILED, ActionT::Result::COLLISION_AHEAD};
176176
}
177177

178-
last_vel_ = std::make_shared<double>(cmd_vel->twist.linear.x);
178+
last_vel_ = cmd_vel->twist.linear.x;
179179

180180
this->vel_pub_->publish(std::move(cmd_vel));
181181

@@ -188,9 +188,9 @@ class DriveOnHeading : public TimedBehavior<ActionT>
188188
*/
189189
CostmapInfoType getResourceInfo() override {return CostmapInfoType::LOCAL;}
190190

191-
void onCleanup() override {last_vel_.reset();}
191+
void onCleanup() override {last_vel_ = std::numeric_limits<double>::max();}
192192

193-
void onActionCompletion() override {last_vel_.reset();}
193+
void onActionCompletion() override {last_vel_ = std::numeric_limits<double>::max();}
194194

195195
protected:
196196
/**
@@ -271,7 +271,7 @@ class DriveOnHeading : public TimedBehavior<ActionT>
271271
double simulate_ahead_time_;
272272
double acceleration_limit_;
273273
double deceleration_limit_;
274-
std::shared_ptr<double> last_vel_;
274+
double last_vel_ = std::numeric_limits<double>::max();
275275
};
276276

277277
} // namespace nav2_behaviors

0 commit comments

Comments
 (0)