Skip to content

Commit 6c92aa4

Browse files
curtipa-dmo
authored andcommitted
make velocity smoother keep curvature
1 parent 4d28c13 commit 6c92aa4

File tree

1 file changed

+22
-4
lines changed

1 file changed

+22
-4
lines changed

nav2_velocity_smoother/src/velocity_smoother.cpp

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -274,12 +274,16 @@ double VelocitySmoother::findEtaConstraint(
274274
v_component_min = decel / smoothing_frequency_;
275275
}
276276

277+
if (v_cmd == 0.0) {
278+
return -1.0;
279+
}
280+
277281
if (dv > v_component_max) {
278-
return v_component_max / dv;
282+
return ( v_component_max + v_curr ) / v_cmd;
279283
}
280284

281285
if (dv < v_component_min) {
282-
return v_component_min / dv;
286+
return ( v_component_min + v_curr ) / v_cmd;
283287
}
284288

285289
return -1.0;
@@ -289,7 +293,8 @@ double VelocitySmoother::applyConstraints(
289293
const double v_curr, const double v_cmd,
290294
const double accel, const double decel, const double eta)
291295
{
292-
double dv = v_cmd - v_curr;
296+
double scaled = eta * v_cmd;
297+
double diff = scaled - v_curr;
293298

294299
double v_component_max;
295300
double v_component_min;
@@ -305,7 +310,14 @@ double VelocitySmoother::applyConstraints(
305310
v_component_min = decel / smoothing_frequency_;
306311
}
307312

308-
return v_curr + std::clamp(eta * dv, v_component_min, v_component_max);
313+
auto clamped_diff = std::clamp(diff, v_component_min, v_component_max);
314+
auto restricted_command = v_curr + clamped_diff;
315+
316+
if(std::abs(scaled - restricted_command) > 0.0001){
317+
RCLCPP_WARN(get_logger(), "Clamped velocity change: eta * v_cmd = %f, clamped to %f", scaled, restricted_command);
318+
}
319+
320+
return restricted_command;
309321
}
310322

311323
void VelocitySmoother::smootherTimer()
@@ -338,6 +350,9 @@ void VelocitySmoother::smootherTimer()
338350
current_ = odom_smoother_->getTwistStamped();
339351
}
340352

353+
RCLCPP_INFO(get_logger(), "current (odom) velocity: [%f, %f, %f]", current_.twist.linear.x, current_.twist.linear.y, current_.twist.angular.z);
354+
RCLCPP_INFO(get_logger(), "input velocity: [%f, %f, %f]", command_->twist.linear.x, command_->twist.linear.y, command_->twist.angular.z);
355+
341356
// Apply absolute velocity restrictions to the command
342357
if(!is_6dof_) {
343358
command_->twist.linear.x = std::clamp(
@@ -370,12 +385,15 @@ void VelocitySmoother::smootherTimer()
370385
max_velocities_[5]);
371386
}
372387

388+
RCLCPP_INFO(get_logger(), "clamped velocity: [%f, %f, %f]", command_->twist.linear.x, command_->twist.linear.y, command_->twist.angular.z);
389+
373390
// Find if any component is not within the acceleration constraints. If so, store the most
374391
// significant scale factor to apply to the vector <dvx, dvy, dvw>, eta, to reduce all axes
375392
// proportionally to follow the same direction, within change of velocity bounds.
376393
// In case eta reduces another axis out of its own limit, apply accel constraint to guarantee
377394
// output is within limits, even if it deviates from requested command slightly.
378395
double eta = 1.0;
396+
RCLCPP_INFO(get_logger(), "scale_velocities_ = %d", (int) scale_velocities_);
379397
if (scale_velocities_) {
380398
double curr_eta = -1.0;
381399
if(!is_6dof_) {

0 commit comments

Comments
 (0)