Skip to content

Commit aa243da

Browse files
zusizusishmpwk
andauthored
feat(raw_vehicle_cmd_converter): use polling subscriber (#7319)
* replace subscription Signed-off-by: Sho Iwasawa <sho.iwasawa.2@tier4.jp> * fix document Signed-off-by: Sho Iwasawa <sho.iwasawa.2@tier4.jp> * sum up functions Signed-off-by: Sho Iwasawa <sho.iwasawa.2@tier4.jp> * add maintainer Signed-off-by: Sho Iwasawa <sho.iwasawa.2@tier4.jp> --------- Signed-off-by: Sho Iwasawa <sho.iwasawa.2@tier4.jp> Co-authored-by: Shumpei Wakabayashi <42209144+shmpwk@users.noreply.github.com>
1 parent 73969a1 commit aa243da

File tree

4 files changed

+22
-27
lines changed

4 files changed

+22
-27
lines changed

vehicle/autoware_raw_vehicle_cmd_converter/README.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,11 @@ For ease of calibration and adjustments to the lookup table, an auto-calibration
2626

2727
## Input topics
2828

29-
| Name | Type | Description |
30-
| --------------------- | ------------------------------------- | ------------------------------------------------------------------------------------------------------------------ |
31-
| `~/input/control_cmd` | autoware_control_msgs::msg::Control | target `velocity/acceleration/steering_angle/steering_angle_velocity` is necessary to calculate actuation command. |
32-
| `~/input/steering"` | autoware_vehicle_msgs::SteeringReport | current status of steering used for steering feed back control |
33-
| `~/input/twist` | navigation_msgs::Odometry | twist topic in odometry is used. |
29+
| Name | Type | Description |
30+
| --------------------- | ------------------------------------------ | ------------------------------------------------------------------------------------------------------------------ |
31+
| `~/input/control_cmd` | autoware_control_msgs::msg::Control | target `velocity/acceleration/steering_angle/steering_angle_velocity` is necessary to calculate actuation command. |
32+
| `~/input/steering"` | autoware_vehicle_msgs::msg::SteeringReport | current status of steering used for steering feed back control |
33+
| `~/input/odometry` | navigation_msgs::Odometry | twist topic in odometry is used. |
3434

3535
## Output topics
3636

vehicle/autoware_raw_vehicle_cmd_converter/include/autoware_raw_vehicle_cmd_converter/node.hpp

+6-6
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include "autoware_raw_vehicle_cmd_converter/pid.hpp"
2121
#include "autoware_raw_vehicle_cmd_converter/steer_map.hpp"
2222
#include "tier4_autoware_utils/ros/logger_level_configure.hpp"
23+
#include "tier4_autoware_utils/ros/polling_subscriber.hpp"
2324

2425
#include <rclcpp/rclcpp.hpp>
2526

@@ -74,12 +75,13 @@ class RawVehicleCommandConverterNode : public rclcpp::Node
7475

7576
//!< @brief topic publisher for low level vehicle command
7677
rclcpp::Publisher<ActuationCommandStamped>::SharedPtr pub_actuation_cmd_;
77-
//!< @brief subscriber for current velocity
78-
rclcpp::Subscription<Odometry>::SharedPtr sub_velocity_;
7978
//!< @brief subscriber for vehicle command
8079
rclcpp::Subscription<Control>::SharedPtr sub_control_cmd_;
81-
//!< @brief subscriber for steering
82-
rclcpp::Subscription<Steering>::SharedPtr sub_steering_;
80+
// polling subscribers
81+
tier4_autoware_utils::InterProcessPollingSubscriber<Odometry> sub_odometry_{
82+
this, "~/input/odometry"};
83+
tier4_autoware_utils::InterProcessPollingSubscriber<Steering> sub_steering_{
84+
this, "~/input/steering"};
8385

8486
rclcpp::TimerBase::SharedPtr timer_;
8587

@@ -109,9 +111,7 @@ class RawVehicleCommandConverterNode : public rclcpp::Node
109111
const double current_velocity, const double desired_acc, bool & accel_cmd_is_zero);
110112
double calculateBrakeMap(const double current_velocity, const double desired_acc);
111113
double calculateSteer(const double vel, const double steering, const double steer_rate);
112-
void onSteering(const Steering::ConstSharedPtr msg);
113114
void onControlCmd(const Control::ConstSharedPtr msg);
114-
void onVelocity(const Odometry::ConstSharedPtr msg);
115115
void publishActuationCmd();
116116
// for debugging
117117
rclcpp::Publisher<Float32MultiArrayStamped>::SharedPtr debug_pub_steer_pid_;

vehicle/autoware_raw_vehicle_cmd_converter/package.xml

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
<maintainer email="takamasa.horibe@tier4.jp">Takamasa Horibe</maintainer>
88
<maintainer email="taiki.tanaka@tier4.jp">Tanaka Taiki</maintainer>
99
<maintainer email="makoto.kurihara@tier4.jp">Makoto Kurihara</maintainer>
10+
<maintainer email="sho.iwasawa.2@tier4.jp">Sho Iwasawa</maintainer>
1011

1112
<license>Apache License 2.0</license>
1213

vehicle/autoware_raw_vehicle_cmd_converter/src/node.cpp

+10-16
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,6 @@ RawVehicleCommandConverterNode::RawVehicleCommandConverterNode(
7878
pub_actuation_cmd_ = create_publisher<ActuationCommandStamped>("~/output/actuation_cmd", 1);
7979
sub_control_cmd_ = create_subscription<Control>(
8080
"~/input/control_cmd", 1, std::bind(&RawVehicleCommandConverterNode::onControlCmd, this, _1));
81-
sub_velocity_ = create_subscription<Odometry>(
82-
"~/input/odometry", 1, std::bind(&RawVehicleCommandConverterNode::onVelocity, this, _1));
83-
sub_steering_ = create_subscription<Steering>(
84-
"~/input/steering", 1, std::bind(&RawVehicleCommandConverterNode::onSteering, this, _1));
8581
debug_pub_steer_pid_ = create_publisher<Float32MultiArrayStamped>(
8682
"/vehicle/raw_vehicle_cmd_converter/debug/steer_pid", 1);
8783

@@ -204,20 +200,18 @@ double RawVehicleCommandConverterNode::calculateBrakeMap(
204200
return desired_brake_cmd;
205201
}
206202

207-
void RawVehicleCommandConverterNode::onSteering(const Steering::ConstSharedPtr msg)
208-
{
209-
current_steer_ptr_ = std::make_unique<double>(msg->steering_tire_angle);
210-
}
211-
212-
void RawVehicleCommandConverterNode::onVelocity(const Odometry::ConstSharedPtr msg)
213-
{
214-
current_twist_ptr_ = std::make_unique<TwistStamped>();
215-
current_twist_ptr_->header = msg->header;
216-
current_twist_ptr_->twist = msg->twist.twist;
217-
}
218-
219203
void RawVehicleCommandConverterNode::onControlCmd(const Control::ConstSharedPtr msg)
220204
{
205+
const auto odometry_msg = sub_odometry_.takeData();
206+
const auto steering_msg = sub_steering_.takeData();
207+
if (steering_msg) {
208+
current_steer_ptr_ = std::make_unique<double>(steering_msg->steering_tire_angle);
209+
}
210+
if (odometry_msg) {
211+
current_twist_ptr_ = std::make_unique<TwistStamped>();
212+
current_twist_ptr_->header = odometry_msg->header;
213+
current_twist_ptr_->twist = odometry_msg->twist.twist;
214+
}
221215
control_cmd_ptr_ = msg;
222216
publishActuationCmd();
223217
}

0 commit comments

Comments
 (0)