21 namespace std_ph = std::placeholders;
70 auto error_double = update_params<double>({
95 auto error_int = update_params<int>({
99 auto error_bool = update_params<bool>({
108 rcl_interfaces::msg::SetParametersResult result;
110 result.successful = !error_double && !error_int && !error_bool;
161 pure_pursuit::Config cfg{
172 pure_pursuit::IntegratorConfig i_cfg;
177 i_cfg.integral = 0.0;
180 pp_ = std::make_shared<pure_pursuit::PurePursuit>(cfg, i_cfg);
187 trajectory_plan_sub_ = create_subscription<carma_planning_msgs::msg::TrajectoryPlan>(
"platooning_control/plan_trajectory", 1,
195 platoon_info_pub_ = create_publisher<carma_planning_msgs::msg::PlatooningInfo>(
"platooning_info", 1);
199 return CallbackReturn::SUCCESS;
206 autoware_msgs::msg::ControlCommandStamped ctrl_msg;
213 double current_time_ms = this->now().nanoseconds() / 1e6;
218 RCLCPP_DEBUG_STREAM(
rclcpp::get_logger(
"platooning_control"),
"returning due to timeout.");
227 RCLCPP_DEBUG_STREAM(
rclcpp::get_logger(
"platooning_control"),
"returning due to first data input");
231 carma_planning_msgs::msg::TrajectoryPlanPoint second_trajectory_point =
current_trajectory_.get().trajectory_points[1];
255 carma_planning_msgs::msg::PlatooningInfo platooning_info_msg = *msg;
257 RCLCPP_DEBUG_STREAM(
rclcpp::get_logger(
"platooning_control"),
"platooning_info_msg.actual_gap: " << platooning_info_msg.actual_gap);
259 if (platooning_info_msg.actual_gap > 5.0)
261 platooning_info_msg.actual_gap -= 5.0;
264 RCLCPP_DEBUG_STREAM(
rclcpp::get_logger(
"platooning_control"),
"platooning_info_msg.actual_gap: " << platooning_info_msg.actual_gap);
274 autoware_msgs::msg::ControlCommandStamped
PlatooningControlPlugin::generate_control_signals(
const carma_planning_msgs::msg::TrajectoryPlanPoint& first_trajectory_point,
const geometry_msgs::msg::PoseStamped& current_pose,
const geometry_msgs::msg::TwistStamped& current_twist)
281 motion::control::controller_common::State state_tf =
convert_state(current_pose, current_twist);
288 pp_->set_trajectory(autoware_traj_plan);
289 const auto cmd{
pp_->compute_command(state_tf)};
291 auto steer_cmd = cmd.front_wheel_angle_rad;
300 motion::motion_common::State state;
301 state.header = pose.header;
302 state.state.x = pose.pose.position.x;
303 state.state.y = pose.pose.position.y;
304 state.state.z = pose.pose.position.z;
305 state.state.heading.real = pose.pose.orientation.w;
306 state.state.heading.imag = pose.pose.orientation.z;
308 state.state.longitudinal_velocity_mps = twist.twist.linear.x;
314 if (tp->trajectory_points.size() < 2) {
315 RCLCPP_WARN_STREAM(
rclcpp::get_logger(
"platooning_control"),
"PlatooningControlPlugin cannot execute trajectory as only 1 point was provided");
323 rclcpp::Time tp_time(tp->header.stamp);
324 RCLCPP_DEBUG_STREAM(
rclcpp::get_logger(
"platooning_control"),
"tp header time = " << tp_time.nanoseconds() / 1000000);
329 geometry_msgs::msg::TwistStamped cmd_twist;
330 cmd_twist.twist.linear.x = linear_vel;
331 cmd_twist.twist.angular.z = angular_vel;
332 cmd_twist.header.stamp = this->now();
338 autoware_msgs::msg::ControlCommandStamped cmd_ctrl;
339 cmd_ctrl.header.stamp = this->now();
340 cmd_ctrl.cmd.linear_velocity = linear_vel;
341 RCLCPP_DEBUG_STREAM(
rclcpp::get_logger(
"platooning_control"),
"ctrl command speed " << cmd_ctrl.cmd.linear_velocity);
342 cmd_ctrl.cmd.steering_angle = steering_angle;
343 RCLCPP_DEBUG_STREAM(
rclcpp::get_logger(
"platooning_control"),
"ctrl command steering " << cmd_ctrl.cmd.steering_angle);
359 double trajectory_speed = 0;
361 double dx1 = trajectory_points[trajectory_points.size()-1].x - trajectory_points[0].x;
362 double dy1 = trajectory_points[trajectory_points.size()-1].y - trajectory_points[0].y;
363 double d1 = sqrt(dx1*dx1 + dy1*dy1);
364 double t1 = (rclcpp::Time((trajectory_points[trajectory_points.size()-1].target_time)).nanoseconds() - rclcpp::Time(trajectory_points[0].target_time).nanoseconds())/1e9;
366 double avg_speed = d1/t1;
367 RCLCPP_DEBUG_STREAM(
rclcpp::get_logger(
"platooning_control"),
"trajectory_points size = " << trajectory_points.size() <<
", d1 = " << d1 <<
", t1 = " << t1 <<
", avg_speed = " << avg_speed);
369 for(
size_t i = 0;
i < trajectory_points.size() - 2;
i++ )
371 double dx = trajectory_points[
i + 1].x - trajectory_points[
i].x;
372 double dy = trajectory_points[
i + 1].y - trajectory_points[
i].y;
374 double t = rclcpp::Time((trajectory_points[
i + 1].target_time)).seconds() - rclcpp::Time(trajectory_points[
i].target_time).seconds();
376 if(v > trajectory_speed)
378 trajectory_speed = v;
382 RCLCPP_DEBUG_STREAM(
rclcpp::get_logger(
"platooning_control"),
"trajectory speed: " << trajectory_speed);
383 RCLCPP_DEBUG_STREAM(
rclcpp::get_logger(
"platooning_control"),
"avg trajectory speed: " << avg_speed);
392#include "rclcpp_components/register_node_macro.hpp"
boost::optional< geometry_msgs::msg::TwistStamped > current_twist_
The most recent velocity message received by this node.
boost::optional< carma_planning_msgs::msg::TrajectoryPlan > current_trajectory_
The most recent trajectory received by this plugin.
boost::optional< geometry_msgs::msg::PoseStamped > current_pose_
The most recent pose message received by this node.
This class includes node-level logic for Platooning Control such as its publishers,...
motion::motion_common::State convert_state(const geometry_msgs::msg::PoseStamped &pose, const geometry_msgs::msg::TwistStamped &twist) const
void platoon_info_cb(const carma_planning_msgs::msg::PlatooningInfo::SharedPtr msg)
callback function for platoon info
bool get_availability() override
Returns availability of plugin. Always true.
carma_ros2_utils::CallbackReturn on_configure_plugin() override
This method should be used to load parameters and will be called on the configure state transition.
void current_trajectory_callback(const carma_planning_msgs::msg::TrajectoryPlan::UniquePtr tp)
callback function for trajectory plan
double prev_input_time_ms_
double get_trajectory_speed(const std::vector< carma_planning_msgs::msg::TrajectoryPlanPoint > &trajectory_points)
calculate average speed of a set of trajectory points
geometry_msgs::msg::TwistStamped compose_twist_cmd(double linear_vel, double angular_vel)
Compose twist message from linear and angular velocity commands.
rcl_interfaces::msg::SetParametersResult parameter_update_callback(const std::vector< rclcpp::Parameter > ¶meters)
Callback for dynamic parameter updates.
std::string get_version_id() override
Returns version id of plugn.
PlatooningControlWorker pcw_
autoware_msgs::msg::ControlCommandStamped compose_ctrl_cmd(double linear_vel, double steering_angle)
Compose control message from speed and steering commands.
PlatoonLeaderInfo platoon_leader_
carma_ros2_utils::SubPtr< carma_planning_msgs::msg::PlatooningInfo > platoon_info_sub_
autoware_msgs::msg::ControlCommandStamped generate_control_signals(const carma_planning_msgs::msg::TrajectoryPlanPoint &first_trajectory_point, const geometry_msgs::msg::PoseStamped ¤t_pose, const geometry_msgs::msg::TwistStamped ¤t_twist)
generate control signal by calculating speed and steering commands.
autoware_msgs::msg::ControlCommandStamped generate_command() override
Extending class provided method which should generate a command message which will be published to th...
long consecutive_input_counter_
std::shared_ptr< pure_pursuit::PurePursuit > pp_
carma_ros2_utils::PubPtr< carma_planning_msgs::msg::PlatooningInfo > platoon_info_pub_
PlatooningControlPluginConfig config_
PlatooningControlPlugin(const rclcpp::NodeOptions &options)
PlatooningControlPlugin constructor.
carma_ros2_utils::SubPtr< carma_planning_msgs::msg::TrajectoryPlan > trajectory_plan_sub_
This is the worker class for platoon controller. It is responsible for generating and smoothing the s...
void set_leader(const PlatoonLeaderInfo &leader)
Sets the platoon leader object using info from msg.
void set_current_speed(double speed)
set current speed
std::shared_ptr< PlatooningControlPluginConfig > ctrl_config_
void generate_speed(const carma_planning_msgs::msg::TrajectoryPlanPoint &point)
Generates speed commands (in m/s) based on the trajectory point.
autoware_auto_msgs::msg::Trajectory process_trajectory_plan(const carma_planning_msgs::msg::TrajectoryPlan &tp, double vehicle_response_lag)
Given a carma type of trajectory_plan, generate autoware type of trajectory accounting for speed_lag ...
void set_logger(rclcpp::Logger logger)
Replace the module-level logger used by all basic_autonomy functions.
rclcpp::Logger get_logger()
Return the module-level logger used by all basic_autonomy functions.
int NumberOfVehicleInFront
Stuct containing the algorithm configuration values for the PlatooningControlPlugin.
double emergency_stop_distance
bool is_interpolate_lookahead_point
double speed_thres_traveling_direction
double min_delta_speed_per_timestep
double max_lookahead_dist
double stand_still_headway_m
double adjustment_cap_mps
double max_delta_speed_per_timestep
int ignore_initial_inputs
double dist_front_rear_wheels
bool is_integrator_enabled
double vehicle_response_lag
double min_lookahead_dist
bool is_delay_compensation
double speed_to_lookahead_ratio
bool enable_max_accel_filter
bool enable_max_adjustment_filter