@@ -73,6 +73,7 @@ VelocitySmootherNode::VelocitySmootherNode(const rclcpp::NodeOptions & node_opti
73
73
srv_slow_driving_ = create_service<SetBool>(
74
74
" ~/slow_driving" , std::bind (&MotionVelocitySmootherNode::onSlowDriving, this , _1, _2));
75
75
force_acceleration_mode_ = false ;
76
+ force_slow_driving_mode_ = ForceSlowDrivingType::DEACTIVATED;
76
77
77
78
// parameter update
78
79
set_param_res_ =
@@ -200,6 +201,7 @@ rcl_interfaces::msg::SetParametersResult VelocitySmootherNode::onParameter(
200
201
update_param (" force_acceleration.engage_velocity" , p.force_acceleration_param .engage_velocity );
201
202
update_param (
202
203
" force_acceleration.engage_acceleration" , p.force_acceleration_param .engage_acceleration );
204
+ update_param (" force_slow_driving.velocity" , p.force_slow_driving_velocity );
203
205
}
204
206
205
207
{
@@ -329,6 +331,8 @@ void VelocitySmootherNode::initCommonParam()
329
331
declare_parameter<double >(" force_acceleration.engage_velocity" );
330
332
p.force_acceleration_param .engage_acceleration =
331
333
declare_parameter<double >(" force_acceleration.engage_acceleration" );
334
+
335
+ p.force_slow_driving_velocity = declare_parameter<double >(" force_slow_driving.velocity" );
332
336
}
333
337
334
338
void VelocitySmootherNode::publishTrajectory (const TrajectoryPoints & trajectory) const
@@ -502,6 +506,14 @@ void VelocitySmootherNode::onCurrentTrajectory(const Trajectory::ConstSharedPtr
502
506
flipVelocity (input_points);
503
507
}
504
508
509
+ // Only activate slow driving when velocity is below threshold
510
+ double slow_driving_vel_threshold = get_parameter (" force_slow_driving.velocity" ).as_double ();
511
+ if (
512
+ force_slow_driving_mode_ == ForceSlowDrivingType::READY &&
513
+ current_odometry_ptr_->twist .twist .linear .x < slow_driving_vel_threshold) {
514
+ force_slow_driving_mode_ = ForceSlowDrivingType::ACTIVATED;
515
+ }
516
+
505
517
const auto output = calcTrajectoryVelocity (input_points);
506
518
if (output.empty ()) {
507
519
RCLCPP_WARN (get_logger (), " Output Point is empty" );
@@ -591,6 +603,13 @@ TrajectoryPoints VelocitySmootherNode::calcTrajectoryVelocity(
591
603
// Apply velocity to approach stop point
592
604
applyStopApproachingVelocity (traj_extracted);
593
605
606
+ // Apply force slow driving if activated
607
+ if (force_slow_driving_mode_ == ForceSlowDrivingType::ACTIVATED) {
608
+ for (auto & tp : traj_extracted) {
609
+ tp.longitudinal_velocity_mps = get_parameter (" force_slow_driving.velocity" ).as_double ();
610
+ }
611
+ }
612
+
594
613
// Debug
595
614
if (publish_debug_trajs_) {
596
615
auto tmp = traj_extracted;
@@ -1172,12 +1191,21 @@ void MotionVelocitySmootherNode::onForceAcceleration(
1172
1191
}
1173
1192
1174
1193
response->success = true ;
1194
+ response->message = message;
1175
1195
}
1176
1196
1177
1197
void MotionVelocitySmootherNode::onSlowDriving (
1178
1198
const std::shared_ptr<SetBool::Request> request, std::shared_ptr<SetBool::Response> response)
1179
1199
{
1180
- const std::string message = request->data ? " Slow driving" : " Default" ;
1200
+ std::string message = " default" ;
1201
+ if (request->data && force_slow_driving_mode_ == ForceSlowDrivingType::DEACTIVATED) {
1202
+ force_slow_driving_mode_ = ForceSlowDrivingType::READY;
1203
+
1204
+ message = " Activated force slow drving" ;
1205
+ } else if (!request->data ) {
1206
+ force_slow_driving_mode_ = ForceSlowDrivingType::DEACTIVATED;
1207
+ message = " Deactivated force slow driving" ;
1208
+ }
1181
1209
1182
1210
response->success = true ;
1183
1211
response->message = message;
0 commit comments