Skip to content

Commit 4ecfb64

Browse files
go-sakayorishmpwk
andauthored
feat(motion_velocity_smoother)!: added force acceleration (#1329)
* add feature for force acceleration Signed-off-by: Go Sakayori <go.sakayori@tier4.jp> * Add log info when force acceleration is activated/deactivated Signed-off-by: Go Sakayori <go.sakayori@tier4.jp> * fix enagage velocity/acceleration Signed-off-by: Go Sakayori <gsakayori@gmail.com> * Update planning/motion_velocity_smoother/src/motion_velocity_smoother_node.cpp * Update planning/motion_velocity_smoother/src/motion_velocity_smoother_node.cpp --------- Signed-off-by: Go Sakayori <go.sakayori@tier4.jp> Signed-off-by: Go Sakayori <gsakayori@gmail.com> Co-authored-by: Shumpei Wakabayashi <42209144+shmpwk@users.noreply.github.com>
1 parent fa6540a commit 4ecfb64

File tree

5 files changed

+106
-0
lines changed

5 files changed

+106
-0
lines changed

planning/motion_velocity_smoother/include/motion_velocity_smoother/motion_velocity_smoother_node.hpp

+20
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
#include "autoware_auto_planning_msgs/msg/trajectory_point.hpp"
4242
#include "geometry_msgs/msg/accel_with_covariance_stamped.hpp"
4343
#include "nav_msgs/msg/odometry.hpp"
44+
#include "std_srvs/srv/set_bool.hpp"
4445
#include "tier4_debug_msgs/msg/float32_stamped.hpp" // temporary
4546
#include "tier4_planning_msgs/msg/stop_speed_exceeded.hpp" // temporary
4647
#include "tier4_planning_msgs/msg/velocity_limit.hpp" // temporary
@@ -63,6 +64,7 @@ using geometry_msgs::msg::AccelWithCovarianceStamped;
6364
using geometry_msgs::msg::Pose;
6465
using geometry_msgs::msg::PoseStamped;
6566
using nav_msgs::msg::Odometry;
67+
using std_srvs::srv::SetBool;
6668
using tier4_debug_msgs::msg::Float32Stamped; // temporary
6769
using tier4_planning_msgs::msg::StopSpeedExceeded; // temporary
6870
using tier4_planning_msgs::msg::VelocityLimit; // temporary
@@ -91,6 +93,8 @@ class MotionVelocitySmootherNode : public rclcpp::Node
9193
rclcpp::Subscription<Trajectory>::SharedPtr sub_current_trajectory_;
9294
rclcpp::Subscription<VelocityLimit>::SharedPtr sub_external_velocity_limit_;
9395
rclcpp::Subscription<OperationModeState>::SharedPtr sub_operation_mode_;
96+
rclcpp::Service<SetBool>::SharedPtr srv_force_acceleration_;
97+
rclcpp::Service<SetBool>::SharedPtr srv_slow_driving_;
9498

9599
Odometry::ConstSharedPtr current_odometry_ptr_; // current odometry
96100
AccelWithCovarianceStamped::ConstSharedPtr current_acceleration_ptr_;
@@ -128,6 +132,15 @@ class MotionVelocitySmootherNode : public rclcpp::Node
128132
NORMAL = 3,
129133
};
130134

135+
struct ForceAccelerationParam
136+
{
137+
double max_acceleration;
138+
double max_jerk;
139+
double max_lateral_acceleration;
140+
double engage_velocity;
141+
double engage_acceleration;
142+
};
143+
131144
struct Param
132145
{
133146
bool enable_lateral_acc_limit;
@@ -153,6 +166,8 @@ class MotionVelocitySmootherNode : public rclcpp::Node
153166
AlgorithmType algorithm_type; // Option : JerkFiltered, Linf, L2
154167

155168
bool plan_from_ego_speed_on_manual_mode = true;
169+
170+
ForceAccelerationParam force_acceleration_param;
156171
} node_param_{};
157172

158173
struct ExternalVelocityLimit
@@ -242,6 +257,11 @@ class MotionVelocitySmootherNode : public rclcpp::Node
242257

243258
// parameter handling
244259
void initCommonParam();
260+
void onForceAcceleration(
261+
const std::shared_ptr<SetBool::Request> request, std::shared_ptr<SetBool::Response> response);
262+
bool force_acceleration_mode_;
263+
void onSlowDriving(
264+
const std::shared_ptr<SetBool::Request> request, std::shared_ptr<SetBool::Response> response);
245265

246266
// debug
247267
tier4_autoware_utils::StopWatch<std::chrono::milliseconds> stop_watch_;

planning/motion_velocity_smoother/include/motion_velocity_smoother/smoother/smoother_base.hpp

+3
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,9 @@ class SmootherBase
7979
double getMinJerk() const;
8080

8181
void setWheelBase(const double wheel_base);
82+
void setMaxAccel(const double max_accel);
83+
void setMaxJerk(const double max_jerk);
84+
void setMaxLatAccel(const double max_accel);
8285

8386
void setParam(const BaseParam & param);
8487
BaseParam getBaseParam() const;

planning/motion_velocity_smoother/package.xml

+1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
<depend>osqp_interface</depend>
2929
<depend>planning_test_utils</depend>
3030
<depend>rclcpp</depend>
31+
<depend>std_srvs</depend>
3132
<depend>tf2</depend>
3233
<depend>tf2_ros</depend>
3334
<depend>tier4_autoware_utils</depend>

planning/motion_velocity_smoother/src/motion_velocity_smoother_node.cpp

+67
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ MotionVelocitySmootherNode::MotionVelocitySmootherNode(const rclcpp::NodeOptions
3838
: Node("motion_velocity_smoother", node_options)
3939
{
4040
using std::placeholders::_1;
41+
using std::placeholders::_2;
4142

4243
// set common params
4344
const auto vehicle_info = vehicle_info_util::VehicleInfoUtil(*this).getVehicleInfo();
@@ -72,6 +73,13 @@ MotionVelocitySmootherNode::MotionVelocitySmootherNode(const rclcpp::NodeOptions
7273
"~/input/operation_mode_state", 1,
7374
[this](const OperationModeState::ConstSharedPtr msg) { operation_mode_ = *msg; });
7475

76+
srv_force_acceleration_ = create_service<SetBool>(
77+
"~/adjust_common_param",
78+
std::bind(&MotionVelocitySmootherNode::onForceAcceleration, this, _1, _2));
79+
srv_slow_driving_ = create_service<SetBool>(
80+
"~/slow_driving", std::bind(&MotionVelocitySmootherNode::onSlowDriving, this, _1, _2));
81+
force_acceleration_mode_ = false;
82+
7583
// parameter update
7684
set_param_res_ = this->add_on_set_parameters_callback(
7785
std::bind(&MotionVelocitySmootherNode::onParameter, this, _1));
@@ -189,6 +197,14 @@ rcl_interfaces::msg::SetParametersResult MotionVelocitySmootherNode::onParameter
189197
update_param("ego_nearest_dist_threshold", p.ego_nearest_dist_threshold);
190198
update_param("ego_nearest_yaw_threshold", p.ego_nearest_yaw_threshold);
191199
update_param_bool("plan_from_ego_speed_on_manual_mode", p.plan_from_ego_speed_on_manual_mode);
200+
201+
update_param("force_acceleration.max_acc", p.force_acceleration_param.max_acceleration);
202+
update_param("force_acceleration.max_jerk", p.force_acceleration_param.max_jerk);
203+
update_param(
204+
"force_acceleration.max_lateral_acc", p.force_acceleration_param.max_lateral_acceleration);
205+
update_param("force_acceleration.engage_velocity", p.force_acceleration_param.engage_velocity);
206+
update_param(
207+
"force_acceleration.engage_acceleration", p.force_acceleration_param.engage_acceleration);
192208
}
193209

194210
{
@@ -308,6 +324,16 @@ void MotionVelocitySmootherNode::initCommonParam()
308324

309325
p.plan_from_ego_speed_on_manual_mode =
310326
declare_parameter<bool>("plan_from_ego_speed_on_manual_mode");
327+
328+
p.force_acceleration_param.max_acceleration =
329+
declare_parameter<double>("force_acceleration.max_acc");
330+
p.force_acceleration_param.max_jerk = declare_parameter<double>("force_acceleration.max_jerk");
331+
p.force_acceleration_param.max_lateral_acceleration =
332+
declare_parameter<double>("force_acceleration.max_lateral_acc");
333+
p.force_acceleration_param.engage_velocity =
334+
declare_parameter<double>("force_acceleration.engage_velocity");
335+
p.force_acceleration_param.engage_acceleration =
336+
declare_parameter<double>("force_acceleration.engage_acceleration");
311337
}
312338

313339
void MotionVelocitySmootherNode::publishTrajectory(const TrajectoryPoints & trajectory) const
@@ -1100,6 +1126,47 @@ TrajectoryPoint MotionVelocitySmootherNode::calcProjectedTrajectoryPointFromEgo(
11001126
return calcProjectedTrajectoryPoint(trajectory, current_odometry_ptr_->pose.pose);
11011127
}
11021128

1129+
void MotionVelocitySmootherNode::onForceAcceleration(
1130+
const std::shared_ptr<SetBool::Request> request, std::shared_ptr<SetBool::Response> response)
1131+
{
1132+
std::string message = "default";
1133+
1134+
if (request->data && !force_acceleration_mode_) {
1135+
RCLCPP_INFO(get_logger(), "Force acceleration is activated");
1136+
smoother_->setMaxAccel(get_parameter("force_acceleration.max_acc").as_double());
1137+
smoother_->setMaxJerk(get_parameter("force_acceleration.max_jerk").as_double());
1138+
smoother_->setMaxLatAccel(get_parameter("force_acceleration.max_lateral_acc").as_double());
1139+
node_param_.engage_velocity = get_parameter("force_acceleration.engage_velocity").as_double();
1140+
node_param_.engage_acceleration =
1141+
get_parameter("force_acceleration.engage_acceleration").as_double();
1142+
1143+
force_acceleration_mode_ = true;
1144+
message = "Trigger force acceleration";
1145+
} else if (!request->data && force_acceleration_mode_) {
1146+
RCLCPP_INFO(get_logger(), "Force acceleration is deactivated");
1147+
smoother_->setMaxAccel(get_parameter("normal.max_acc").as_double());
1148+
smoother_->setMaxJerk(get_parameter("normal.max_jerk").as_double());
1149+
smoother_->setMaxLatAccel(get_parameter("max_lateral_accel").as_double());
1150+
1151+
node_param_.engage_velocity = get_parameter("engage_velocity").as_double();
1152+
node_param_.engage_acceleration = get_parameter("engage_acceleration").as_double();
1153+
1154+
force_acceleration_mode_ = false;
1155+
message = "Trigger normal acceleration";
1156+
}
1157+
1158+
response->success = true;
1159+
}
1160+
1161+
void MotionVelocitySmootherNode::onSlowDriving(
1162+
const std::shared_ptr<SetBool::Request> request, std::shared_ptr<SetBool::Response> response)
1163+
{
1164+
const std::string message = request->data ? "Slow driving" : "Default";
1165+
1166+
response->success = true;
1167+
response->message = message;
1168+
}
1169+
11031170
} // namespace motion_velocity_smoother
11041171

11051172
#include "rclcpp_components/register_node_macro.hpp"

planning/motion_velocity_smoother/src/smoother/smoother_base.cpp

+15
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,21 @@ void SmootherBase::setWheelBase(const double wheel_base)
9595
base_param_.wheel_base = wheel_base;
9696
}
9797

98+
void SmootherBase::setMaxAccel(const double max_accel)
99+
{
100+
base_param_.max_accel = max_accel;
101+
}
102+
103+
void SmootherBase::setMaxJerk(const double max_jerk)
104+
{
105+
base_param_.max_jerk = max_jerk;
106+
}
107+
108+
void SmootherBase::setMaxLatAccel(const double max_accel)
109+
{
110+
base_param_.max_lateral_accel = max_accel;
111+
}
112+
98113
void SmootherBase::setParam(const BaseParam & param)
99114
{
100115
base_param_ = param;

0 commit comments

Comments
 (0)