Skip to content

Commit

Permalink
feat(behavior_velocity_planner): subscribe acceleration from localiza…
Browse files Browse the repository at this point in the history
…tion module

Signed-off-by: satoshi-ota <satoshi.ota928@gmail.com>
  • Loading branch information
satoshi-ota committed Sep 14, 2022
1 parent ab2cb3c commit a4f99ea
Show file tree
Hide file tree
Showing 12 changed files with 28 additions and 66 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,7 @@ def launch_setup(context, *args, **kwargs):
("~/input/path_with_lane_id", "path_with_lane_id"),
("~/input/vector_map", "/map/vector_map"),
("~/input/vehicle_odometry", "/localization/kinematic_state"),
("~/input/accel", "/localization/acceleration"),
("~/input/dynamic_objects", "/perception/object_recognition/objects"),
(
"~/input/no_ground_pointcloud",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ class BehaviorVelocityPlannerNode : public rclcpp::Node
sub_predicted_objects_;
rclcpp::Subscription<sensor_msgs::msg::PointCloud2>::SharedPtr sub_no_ground_pointcloud_;
rclcpp::Subscription<nav_msgs::msg::Odometry>::SharedPtr sub_vehicle_odometry_;
rclcpp::Subscription<geometry_msgs::msg::AccelWithCovarianceStamped>::SharedPtr sub_acceleration_;
rclcpp::Subscription<autoware_auto_mapping_msgs::msg::HADMapBin>::SharedPtr sub_lanelet_map_;
rclcpp::Subscription<autoware_auto_perception_msgs::msg::TrafficSignalArray>::SharedPtr
sub_traffic_signals_;
Expand All @@ -78,6 +79,7 @@ class BehaviorVelocityPlannerNode : public rclcpp::Node
const autoware_auto_perception_msgs::msg::PredictedObjects::ConstSharedPtr msg);
void onNoGroundPointCloud(const sensor_msgs::msg::PointCloud2::ConstSharedPtr msg);
void onVehicleVelocity(const nav_msgs::msg::Odometry::ConstSharedPtr msg);
void onAcceleration(const geometry_msgs::msg::AccelWithCovarianceStamped::ConstSharedPtr msg);
void onLaneletMap(const autoware_auto_mapping_msgs::msg::HADMapBin::ConstSharedPtr msg);
void onTrafficSignals(
const autoware_auto_perception_msgs::msg::TrafficSignalArray::ConstSharedPtr msg);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include <autoware_auto_perception_msgs/msg/predicted_objects.hpp>
#include <autoware_auto_perception_msgs/msg/traffic_signal_array.hpp>
#include <autoware_auto_perception_msgs/msg/traffic_signal_stamped.hpp>
#include <geometry_msgs/msg/accel_with_covariance_stamped.hpp>
#include <geometry_msgs/msg/pose_stamped.hpp>
#include <geometry_msgs/msg/twist_stamped.hpp>
#include <nav_msgs/msg/occupancy_grid.hpp>
Expand Down Expand Up @@ -70,7 +71,7 @@ struct PlannerData

// msgs from callbacks that are used for data-ready
geometry_msgs::msg::TwistStamped::ConstSharedPtr current_velocity;
boost::optional<double> current_accel;
geometry_msgs::msg::AccelWithCovarianceStamped::ConstSharedPtr current_acceleration;
static constexpr double velocity_buffer_time_sec = 10.0;
std::deque<geometry_msgs::msg::TwistStamped> velocity_buffer;
autoware_auto_perception_msgs::msg::PredictedObjects::ConstSharedPtr predicted_objects;
Expand Down Expand Up @@ -156,44 +157,6 @@ struct PlannerData
return std::make_shared<autoware_auto_perception_msgs::msg::TrafficSignalStamped>(
external_traffic_light_id_map.at(id));
}

private:
boost::optional<double> prev_accel_;
geometry_msgs::msg::TwistStamped::ConstSharedPtr prev_velocity_;
double accel_lowpass_gain_;

void updateCurrentAcc()
{
current_accel = {};

if (!current_velocity) {
return;
}

if (!prev_velocity_) {
prev_velocity_ = current_velocity;
return;
}

const double dv = current_velocity->twist.linear.x - prev_velocity_->twist.linear.x;
const double dt = std::max(
(rclcpp::Time(current_velocity->header.stamp) - rclcpp::Time(prev_velocity_->header.stamp))
.seconds(),
1e-03);

const double accel = dv / dt;
prev_velocity_ = current_velocity;

if (!prev_accel_) {
prev_accel_ = accel;
return;
}
// apply lowpass filter
current_accel = accel_lowpass_gain_ * accel + (1.0 - accel_lowpass_gain_) * prev_accel_.get();

prev_accel_ = current_accel;
}
friend BehaviorVelocityPlannerNode;
};
} // namespace behavior_velocity_planner

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ inline bool smoothPath(
{
const geometry_msgs::msg::Pose current_pose = planner_data->current_pose.pose;
const double v0 = planner_data->current_velocity->twist.linear.x;
const double a0 = planner_data->current_accel.get();
const double a0 = planner_data->current_acceleration->accel.accel.linear.x;
const auto & external_v_limit = planner_data->external_velocity_limit;
const auto & smoother = planner_data->velocity_smoother_;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
<remap from="~/input/path_with_lane_id" to="path_with_lane_id"/>
<remap from="~/input/vector_map" to="$(var map_topic_name)"/>
<remap from="~/input/vehicle_odometry" to="/localization/kinematic_state"/>
<remap from="~/input/accel" to="/localization/acceleration"/>
<remap from="~/input/dynamic_objects" to="/perception/object_recognition/objects"/>
<remap from="~/input/no_ground_pointcloud" to="/perception/obstacle_segmentation/pointcloud"/>
<remap from="~/input/traffic_signals" to="$(var input_traffic_light_topic_name)"/>
Expand Down
16 changes: 11 additions & 5 deletions planning/behavior_velocity_planner/src/node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,9 @@ BehaviorVelocityPlannerNode::BehaviorVelocityPlannerNode(const rclcpp::NodeOptio
"~/input/vehicle_odometry", 1,
std::bind(&BehaviorVelocityPlannerNode::onVehicleVelocity, this, _1),
createSubscriptionOptions(this));
sub_acceleration_ = this->create_subscription<geometry_msgs::msg::AccelWithCovarianceStamped>(
"~/input/accel", 1, std::bind(&BehaviorVelocityPlannerNode::onAcceleration, this, _1),
createSubscriptionOptions(this));
sub_lanelet_map_ = this->create_subscription<autoware_auto_mapping_msgs::msg::HADMapBin>(
"~/input/vector_map", rclcpp::QoS(10).transient_local(),
std::bind(&BehaviorVelocityPlannerNode::onLaneletMap, this, _1),
Expand Down Expand Up @@ -159,8 +162,6 @@ BehaviorVelocityPlannerNode::BehaviorVelocityPlannerNode(const rclcpp::NodeOptio
// Parameters
forward_path_length_ = this->declare_parameter("forward_path_length", 1000.0);
backward_path_length_ = this->declare_parameter("backward_path_length", 5.0);
// TODO(yukkysaito): This will become unnecessary when acc output from localization is available.
planner_data_.accel_lowpass_gain_ = this->declare_parameter("lowpass_gain", 0.5);
planner_data_.stop_line_extend_length = this->declare_parameter("stop_line_extend_length", 5.0);

// nearest search
Expand Down Expand Up @@ -225,7 +226,7 @@ bool BehaviorVelocityPlannerNode::isDataReady(
RCLCPP_INFO_THROTTLE(get_logger(), clock, 3000, "Waiting for current velocity");
return false;
}
if (!d.current_accel) {
if (!d.current_acceleration) {
RCLCPP_INFO_THROTTLE(get_logger(), clock, 3000, "Waiting for current acceleration");
return false;
}
Expand Down Expand Up @@ -305,8 +306,6 @@ void BehaviorVelocityPlannerNode::onVehicleVelocity(
current_velocity->twist = msg->twist.twist;
planner_data_.current_velocity = current_velocity;

planner_data_.updateCurrentAcc();

// Add velocity to buffer
planner_data_.velocity_buffer.push_front(*current_velocity);
const rclcpp::Time now = this->now();
Expand All @@ -329,6 +328,13 @@ void BehaviorVelocityPlannerNode::onVehicleVelocity(
}
}

void BehaviorVelocityPlannerNode::onAcceleration(
const geometry_msgs::msg::AccelWithCovarianceStamped::ConstSharedPtr msg)
{
std::lock_guard<std::mutex> lock(mutex_);
planner_data_.current_acceleration = msg;
}

void BehaviorVelocityPlannerNode::onParam()
{
planner_data_.velocity_smoother_ =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,7 @@ float CrosswalkModule::calcTargetVelocity(
return 0.0;
}

const auto ego_acc = planner_data_->current_accel.get();
const auto ego_acc = planner_data_->current_acceleration->accel.accel.linear.x;
const auto dist_deceleration = calcSignedArcLength(ego_path.points, ego_pos, stop_point);
const auto feasible_velocity = planning_utils::calcDecelerationVelocityFromDistanceToTarget(
max_jerk, max_accel, ego_acc, ego_vel, dist_deceleration);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ bool generateStopLine(
{
/* set judge line dist */
const double current_vel = planner_data->current_velocity->twist.linear.x;
const double current_acc = planner_data->current_accel.get();
const double current_acc = planner_data->current_acceleration->accel.accel.linear.x;
const double max_acc = planner_data->max_stop_acceleration_threshold;
const double max_jerk = planner_data->max_stop_jerk_threshold;
const double delay_response_time = planner_data->delay_response_time;
Expand Down Expand Up @@ -499,7 +499,7 @@ bool generateStopLineBeforeIntersection(
{
/* set judge line dist */
const double current_vel = planner_data->current_velocity->twist.linear.x;
const double current_acc = planner_data->current_accel.get();
const double current_acc = planner_data->current_acceleration->accel.accel.linear.x;
const double max_acc = planner_data->max_stop_acceleration_threshold;
const double max_jerk = planner_data->max_stop_jerk_threshold;
const double delay_response_time = planner_data->delay_response_time;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -368,16 +368,10 @@ bool NoStoppingAreaModule::isStoppable(
{
// get vehicle info and compute pass_judge_line_distance
const auto current_velocity = planner_data_->current_velocity->twist.linear.x;
const auto current_acceleration = planner_data_->current_accel.get();
const auto current_acceleration = planner_data_->current_acceleration->accel.accel.linear.x;
const double max_acc = planner_data_->max_stop_acceleration_threshold;
const double max_jerk = planner_data_->max_stop_jerk_threshold;
const double delay_response_time = planner_data_->delay_response_time;
if (!planner_data_->current_accel) {
RCLCPP_WARN_THROTTLE(
logger_, *clock_, 1000,
"[no stopping area] empty current acc! check current vel has been received.");
return false;
}
const double stoppable_distance = planning_utils::calcJudgeLineDistWithJerkLimit(
current_velocity, current_acceleration, max_acc, max_jerk, delay_response_time);
const double signed_arc_length =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ bool OcclusionSpotModule::modifyPathVelocity(
param_.v.max_stop_jerk = planner_data_->max_stop_jerk_threshold;
param_.v.max_stop_accel = planner_data_->max_stop_acceleration_threshold;
param_.v.v_ego = planner_data_->current_velocity->twist.linear.x;
param_.v.a_ego = planner_data_->current_accel.get();
param_.v.a_ego = planner_data_->current_acceleration->accel.accel.linear.x;
param_.v.delay_time = planner_data_->system_delay;
param_.detection_area_max_length =
planning_utils::calcJudgeLineDistWithJerkLimit(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ bool RunOutModule::modifyPathVelocity(

// set planner data
const auto current_vel = planner_data_->current_velocity->twist.linear.x;
const auto current_acc = planner_data_->current_accel.get();
const auto current_acc = planner_data_->current_acceleration->accel.accel.linear.x;
const auto & current_pose = planner_data_->current_pose.pose;

// set height of debug data
Expand Down Expand Up @@ -129,7 +129,7 @@ Polygons2d RunOutModule::createDetectionAreaPolygon(const PathWithLaneId & smoot
{
// calculate distance needed to stop with jerk and acc constraints
const float initial_vel = planner_data_->current_velocity->twist.linear.x;
const float initial_acc = planner_data_->current_accel.get();
const float initial_acc = planner_data_->current_acceleration->accel.accel.linear.x;
const float target_vel = 0.0;
const float jerk_dec_max = planner_param_.smoother.start_jerk;
const float jerk_dec = planner_param_.run_out.specify_decel_jerk
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -332,17 +332,12 @@ bool TrafficLightModule::isPassthrough(const double & signed_arc_length) const
const double reachable_distance =
planner_data_->current_velocity->twist.linear.x * planner_param_.yellow_lamp_period;

if (!planner_data_->current_accel) {
RCLCPP_WARN_THROTTLE(
logger_, *clock_, 1000,
"[traffic_light] empty current acc! check current vel has been received.");
return false;
}
// Calculate distance until ego vehicle decide not to stop,
// taking into account the jerk and acceleration.
const double pass_judge_line_distance = planning_utils::calcJudgeLineDistWithJerkLimit(
planner_data_->current_velocity->twist.linear.x, planner_data_->current_accel.get(), max_acc,
max_jerk, delay_response_time);
planner_data_->current_velocity->twist.linear.x,
planner_data_->current_acceleration->accel.accel.linear.x, max_acc, max_jerk,
delay_response_time);

const bool distance_stoppable = pass_judge_line_distance < signed_arc_length;
const bool slow_velocity = planner_data_->current_velocity->twist.linear.x < 2.0;
Expand Down

0 comments on commit a4f99ea

Please sign in to comment.