Skip to content

Commit f122d37

Browse files
committed
feat(motion_velocity_smoother): force slow driving (#1409)
* add force slow driving function Signed-off-by: Go Sakayori <gsakayori@gmail.com> * fix state Signed-off-by: Go Sakayori <go.sakayori@tier4.jp> * erase log info Signed-off-by: Go Sakayori <gsakayori@gmail.com> --------- Signed-off-by: Go Sakayori <gsakayori@gmail.com> Signed-off-by: Go Sakayori <go.sakayori@tier4.jp>
1 parent e3b68d5 commit f122d37

File tree

2 files changed

+41
-1
lines changed
  • planning/autoware_velocity_smoother

2 files changed

+41
-1
lines changed

planning/autoware_velocity_smoother/include/autoware/velocity_smoother/node.hpp

+12
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,12 @@ class VelocitySmootherNode : public rclcpp::Node
138138
NORMAL = 3,
139139
};
140140

141+
enum class ForceSlowDrivingType {
142+
DEACTIVATED = 0,
143+
READY = 1,
144+
ACTIVATED = 2,
145+
};
146+
141147
struct ForceAccelerationParam
142148
{
143149
double max_acceleration;
@@ -174,6 +180,7 @@ class VelocitySmootherNode : public rclcpp::Node
174180
bool plan_from_ego_speed_on_manual_mode = true;
175181

176182
ForceAccelerationParam force_acceleration_param;
183+
double force_slow_driving_velocity;
177184
} node_param_{};
178185

179186
struct ExternalVelocityLimit
@@ -259,11 +266,16 @@ class VelocitySmootherNode : public rclcpp::Node
259266

260267
// parameter handling
261268
void initCommonParam();
269+
270+
// Related to force acceleration
262271
void onForceAcceleration(
263272
const std::shared_ptr<SetBool::Request> request, std::shared_ptr<SetBool::Response> response);
264273
bool force_acceleration_mode_;
274+
275+
// Related to force slow driving
265276
void onSlowDriving(
266277
const std::shared_ptr<SetBool::Request> request, std::shared_ptr<SetBool::Response> response);
278+
ForceSlowDrivingType force_slow_driving_mode_;
267279

268280
// debug
269281
autoware::universe_utils::StopWatch<std::chrono::milliseconds> stop_watch_;

planning/autoware_velocity_smoother/src/node.cpp

+29-1
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ VelocitySmootherNode::VelocitySmootherNode(const rclcpp::NodeOptions & node_opti
7373
srv_slow_driving_ = create_service<SetBool>(
7474
"~/slow_driving", std::bind(&MotionVelocitySmootherNode::onSlowDriving, this, _1, _2));
7575
force_acceleration_mode_ = false;
76+
force_slow_driving_mode_ = ForceSlowDrivingType::DEACTIVATED;
7677

7778
// parameter update
7879
set_param_res_ =
@@ -200,6 +201,7 @@ rcl_interfaces::msg::SetParametersResult VelocitySmootherNode::onParameter(
200201
update_param("force_acceleration.engage_velocity", p.force_acceleration_param.engage_velocity);
201202
update_param(
202203
"force_acceleration.engage_acceleration", p.force_acceleration_param.engage_acceleration);
204+
update_param("force_slow_driving.velocity", p.force_slow_driving_velocity);
203205
}
204206

205207
{
@@ -329,6 +331,8 @@ void VelocitySmootherNode::initCommonParam()
329331
declare_parameter<double>("force_acceleration.engage_velocity");
330332
p.force_acceleration_param.engage_acceleration =
331333
declare_parameter<double>("force_acceleration.engage_acceleration");
334+
335+
p.force_slow_driving_velocity = declare_parameter<double>("force_slow_driving.velocity");
332336
}
333337

334338
void VelocitySmootherNode::publishTrajectory(const TrajectoryPoints & trajectory) const
@@ -502,6 +506,14 @@ void VelocitySmootherNode::onCurrentTrajectory(const Trajectory::ConstSharedPtr
502506
flipVelocity(input_points);
503507
}
504508

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+
505517
const auto output = calcTrajectoryVelocity(input_points);
506518
if (output.empty()) {
507519
RCLCPP_WARN(get_logger(), "Output Point is empty");
@@ -591,6 +603,13 @@ TrajectoryPoints VelocitySmootherNode::calcTrajectoryVelocity(
591603
// Apply velocity to approach stop point
592604
applyStopApproachingVelocity(traj_extracted);
593605

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+
594613
// Debug
595614
if (publish_debug_trajs_) {
596615
auto tmp = traj_extracted;
@@ -1172,12 +1191,21 @@ void MotionVelocitySmootherNode::onForceAcceleration(
11721191
}
11731192

11741193
response->success = true;
1194+
response->message = message;
11751195
}
11761196

11771197
void MotionVelocitySmootherNode::onSlowDriving(
11781198
const std::shared_ptr<SetBool::Request> request, std::shared_ptr<SetBool::Response> response)
11791199
{
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+
}
11811209

11821210
response->success = true;
11831211
response->message = message;

0 commit comments

Comments
 (0)