Skip to content

Commit b107ac7

Browse files
authored
feat(raw_vehicle_cmd_converter): add vehicle adaptor (#8782)
* feat(raw_vehicle_cmd_converter): add vehicle adaptor Signed-off-by: kosuke55 <kosuke.tnp@gmail.com> sub operation status Signed-off-by: kosuke55 <kosuke.tnp@gmail.com> * feat(raw_vehicle_cmd_converter): publish vehicle adaptor output Signed-off-by: kosuke55 <kosuke.tnp@gmail.com> * use control horizon Signed-off-by: kosuke55 <kosuke.tnp@gmail.com> * revert carla Signed-off-by: kosuke55 <kosuke.tnp@gmail.com> * update docs Signed-off-by: kosuke55 <kosuke.tnp@gmail.com> --------- Signed-off-by: kosuke55 <kosuke.tnp@gmail.com>
1 parent 4d529ba commit b107ac7

File tree

9 files changed

+169
-22
lines changed

9 files changed

+169
-22
lines changed

vehicle/autoware_raw_vehicle_cmd_converter/CMakeLists.txt

+6-2
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,15 @@ ament_auto_add_library(actuation_map_converter SHARED
1313
src/vgr.cpp
1414
)
1515

16+
ament_auto_add_library(vehicle_adaptor SHARED
17+
src/vehicle_adaptor/vehicle_adaptor.cpp
18+
)
19+
1620
ament_auto_add_library(autoware_raw_vehicle_cmd_converter_node_component SHARED
1721
src/node.cpp
1822
)
1923

20-
target_link_libraries(autoware_raw_vehicle_cmd_converter_node_component actuation_map_converter)
24+
target_link_libraries(autoware_raw_vehicle_cmd_converter_node_component actuation_map_converter vehicle_adaptor)
2125

2226
rclcpp_components_register_node(autoware_raw_vehicle_cmd_converter_node_component
2327
PLUGIN "autoware::raw_vehicle_cmd_converter::RawVehicleCommandConverterNode"
@@ -30,7 +34,7 @@ if(BUILD_TESTING)
3034
)
3135
set(TEST_RAW_VEHICLE_CMD_CONVERTER_EXE test_autoware_raw_vehicle_cmd_converter)
3236
ament_add_ros_isolated_gtest(${TEST_RAW_VEHICLE_CMD_CONVERTER_EXE} ${TEST_SOURCES})
33-
target_link_libraries(${TEST_RAW_VEHICLE_CMD_CONVERTER_EXE} actuation_map_converter autoware_raw_vehicle_cmd_converter_node_component)
37+
target_link_libraries(${TEST_RAW_VEHICLE_CMD_CONVERTER_EXE} actuation_map_converter vehicle_adaptor autoware_raw_vehicle_cmd_converter_node_component)
3438
endif()
3539

3640
ament_auto_package(INSTALL_TO_SHARE

vehicle/autoware_raw_vehicle_cmd_converter/README.md

+14
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,12 @@ vgr_coef_c: 0.042
4545
When `convert_steer_cmd_method: "vgr"` is selected, the node receives the control command from the controller as the desired tire angle and calculates the desired steering angle to output.
4646
Also, when `convert_actuation_to_steering_status: true`, this node receives the `actuation_status` topic and calculates the steer tire angle from the `steer_wheel_angle` and publishes it.
4747

48+
### Vehicle Adaptor
49+
50+
**Under development**
51+
A feature that compensates for control commands according to the dynamic characteristics of the vehicle.
52+
This feature works when `use_vehicle_adaptor: true` is set and requires `control_horizon` to be enabled, so you need to set `enable_control_cmd_horizon_pub: true` in the trajectory_follower node.
53+
4854
## Input topics
4955

5056
| Name | Type | Description |
@@ -54,6 +60,14 @@ Also, when `convert_actuation_to_steering_status: true`, this node receives the
5460
| `~/input/odometry` | navigation_msgs::Odometry | twist topic in odometry is used. |
5561
| `~/input/actuation_status` | tier4_vehicle_msgs::msg::ActuationStatus | actuation status is assumed to receive the same type of status as sent to the vehicle side. For example, if throttle/brake pedal/steer_wheel_angle is sent, the same type of status is received. In the case of steer_wheel_angle, it is used to calculate steer_tire_angle and VGR in this node. |
5662

63+
Input topics when vehicle_adaptor is enabled
64+
65+
| Name | Type | Description |
66+
| ------------------------------ | ----------------------------------------------- | ----------------------- |
67+
| `~/input/accel` | geometry_msgs::msg::AccelWithCovarianceStamped; | acceleration status |
68+
| `~/input/operation_mode_state` | autoware_adapi_v1_msgs::msg::OperationModeState | operation mode status |
69+
| `~/input/control_horizon` | autoware_control_msgs::msg::ControlHorizon | control horizon command |
70+
5771
## Output topics
5872

5973
| Name | Type | Description |

vehicle/autoware_raw_vehicle_cmd_converter/include/autoware_raw_vehicle_cmd_converter/node.hpp

+16-1
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,12 @@
2121
#include "autoware_raw_vehicle_cmd_converter/brake_map.hpp"
2222
#include "autoware_raw_vehicle_cmd_converter/pid.hpp"
2323
#include "autoware_raw_vehicle_cmd_converter/steer_map.hpp"
24+
#include "autoware_raw_vehicle_cmd_converter/vehicle_adaptor/vehicle_adaptor.hpp"
2425
#include "autoware_raw_vehicle_cmd_converter/vgr.hpp"
2526

2627
#include <rclcpp/rclcpp.hpp>
2728

29+
#include <autoware_adapi_v1_msgs/msg/operation_mode_state.hpp>
2830
#include <autoware_control_msgs/msg/control.hpp>
2931
#include <autoware_vehicle_msgs/msg/steering_report.hpp>
3032
#include <geometry_msgs/msg/twist_stamped.hpp>
@@ -46,7 +48,8 @@ using tier4_vehicle_msgs::msg::ActuationStatusStamped;
4648
using TwistStamped = geometry_msgs::msg::TwistStamped;
4749
using Odometry = nav_msgs::msg::Odometry;
4850
using Steering = autoware_vehicle_msgs::msg::SteeringReport;
49-
51+
using autoware_adapi_v1_msgs::msg::OperationModeState;
52+
using geometry_msgs::msg::AccelWithCovarianceStamped;
5053
class DebugValues
5154
{
5255
public:
@@ -79,24 +82,35 @@ class RawVehicleCommandConverterNode : public rclcpp::Node
7982
//!< @brief topic publisher for low level vehicle command
8083
rclcpp::Publisher<ActuationCommandStamped>::SharedPtr pub_actuation_cmd_;
8184
rclcpp::Publisher<Steering>::SharedPtr pub_steering_status_;
85+
rclcpp::Publisher<Control>::SharedPtr pub_compensated_control_cmd_;
8286
//!< @brief subscriber for vehicle command
8387
rclcpp::Subscription<Control>::SharedPtr sub_control_cmd_;
8488
rclcpp::Subscription<ActuationStatusStamped>::SharedPtr sub_actuation_status_;
8589
rclcpp::Subscription<Steering>::SharedPtr sub_steering_;
8690
// polling subscribers
8791
autoware::universe_utils::InterProcessPollingSubscriber<Odometry> sub_odometry_{
8892
this, "~/input/odometry"};
93+
// polling subscribers for vehicle_adaptor
94+
autoware::universe_utils::InterProcessPollingSubscriber<AccelWithCovarianceStamped> sub_accel_{
95+
this, "~/input/accel"};
96+
autoware::universe_utils::InterProcessPollingSubscriber<OperationModeState> sub_operation_mode_{
97+
this, "~/input/operation_mode_state"};
98+
// control_horizon is an experimental topic, but vehicle_adaptor uses it to improve performance,
99+
autoware::universe_utils::InterProcessPollingSubscriber<ControlHorizon> sub_control_horizon_{
100+
this, "~/input/control_horizon"};
89101

90102
rclcpp::TimerBase::SharedPtr timer_;
91103

92104
std::unique_ptr<TwistStamped> current_twist_ptr_; // [m/s]
93105
std::unique_ptr<double> current_steer_ptr_;
94106
ActuationStatusStamped::ConstSharedPtr actuation_status_ptr_;
107+
Odometry::ConstSharedPtr current_odometry_;
95108
Control::ConstSharedPtr control_cmd_ptr_;
96109
AccelMap accel_map_;
97110
BrakeMap brake_map_;
98111
SteerMap steer_map_;
99112
VGR vgr_;
113+
VehicleAdaptor vehicle_adaptor_;
100114
// TODO(tanaka): consider accel/brake pid too
101115
PIDController steer_pid_;
102116
bool ff_map_initialized_;
@@ -112,6 +126,7 @@ class RawVehicleCommandConverterNode : public rclcpp::Node
112126
bool convert_brake_cmd_; //!< @brief use brake or not
113127
std::optional<std::string> convert_steer_cmd_method_{std::nullopt}; //!< @brief method to convert
114128
bool need_to_subscribe_actuation_status_{false};
129+
bool use_vehicle_adaptor_{false};
115130
rclcpp::Time prev_time_steer_calculation_{0, 0, RCL_ROS_TIME};
116131

117132
// Whether to subscribe to actuation_status and calculate and publish steering_status
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
// Copyright 2024 Tier IV, Inc. All rights reserved.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
#ifndef AUTOWARE_RAW_VEHICLE_CMD_CONVERTER__VEHICLE_ADAPTOR__VEHICLE_ADAPTOR_HPP_
16+
#define AUTOWARE_RAW_VEHICLE_CMD_CONVERTER__VEHICLE_ADAPTOR__VEHICLE_ADAPTOR_HPP_
17+
18+
#include <autoware_adapi_v1_msgs/msg/operation_mode_state.hpp>
19+
#include <autoware_control_msgs/msg/control.hpp>
20+
#include <autoware_control_msgs/msg/control_horizon.hpp>
21+
#include <autoware_vehicle_msgs/msg/steering_report.hpp>
22+
#include <geometry_msgs/msg/accel_with_covariance_stamped.hpp>
23+
#include <nav_msgs/msg/odometry.hpp>
24+
25+
namespace autoware::raw_vehicle_cmd_converter
26+
{
27+
28+
using autoware_adapi_v1_msgs::msg::OperationModeState;
29+
using autoware_control_msgs::msg::Control;
30+
using autoware_control_msgs::msg::ControlHorizon;
31+
using autoware_vehicle_msgs::msg::SteeringReport;
32+
using geometry_msgs::msg::AccelWithCovarianceStamped;
33+
using nav_msgs::msg::Odometry;
34+
35+
class VehicleAdaptor
36+
{
37+
public:
38+
VehicleAdaptor() = default;
39+
Control compensate(
40+
const Control & input_control_cmd, [[maybe_unused]] const Odometry & odometry,
41+
[[maybe_unused]] const AccelWithCovarianceStamped & accel,
42+
[[maybe_unused]] const double steering,
43+
[[maybe_unused]] const OperationModeState & operation_mode,
44+
[[maybe_unused]] const ControlHorizon & control_horizon);
45+
46+
private:
47+
};
48+
} // namespace autoware::raw_vehicle_cmd_converter
49+
50+
#endif // AUTOWARE_RAW_VEHICLE_CMD_CONVERTER__VEHICLE_ADAPTOR__VEHICLE_ADAPTOR_HPP_

vehicle/autoware_raw_vehicle_cmd_converter/launch/raw_vehicle_converter.launch.xml

+6
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,11 @@
22
<launch>
33
<arg name="input_control_cmd" default="/control/command/control_cmd"/>
44
<arg name="input_odometry" default="/localization/kinematic_state"/>
5+
<arg name="input_accel" default="/localization/acceleration"/>
56
<arg name="input_steering" default="/vehicle/status/steering_status"/>
67
<arg name="input_actuation_status" default="/vehicle/status/actuation_status"/>
8+
<arg name="input_operation_mode_state" default="/system/operation_mode/state"/>
9+
<arg name="input_control_horizon" default="/control/trajectory_follower/controller_node_exe/debug/control_cmd_horizon"/>
710
<arg name="output_actuation_cmd" default="/control/command/actuation_cmd"/>
811
<arg name="output_steering_status" default="/vehicle/status/steering_status"/>
912
<!-- Parameter -->
@@ -13,8 +16,11 @@
1316
<param from="$(var config_file)" allow_substs="true"/>
1417
<remap from="~/input/control_cmd" to="$(var input_control_cmd)"/>
1518
<remap from="~/input/odometry" to="$(var input_odometry)"/>
19+
<remap from="~/input/accel" to="$(var input_accel)"/>
1620
<remap from="~/input/steering" to="$(var input_steering)"/>
1721
<remap from="~/input/actuation_status" to="$(var input_actuation_status)"/>
22+
<remap from="~/input/operation_mode_state" to="$(var input_operation_mode_state)"/>
23+
<remap from="~/input/control_horizon" to="$(var input_control_horizon)"/>
1824
<remap from="~/output/actuation_cmd" to="$(var output_actuation_cmd)"/>
1925
<remap from="~/output/steering_status" to="$(var output_steering_status)"/>
2026
</node>

vehicle/autoware_raw_vehicle_cmd_converter/package.xml

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
<buildtool_depend>ament_cmake_auto</buildtool_depend>
2222
<buildtool_depend>autoware_cmake</buildtool_depend>
2323

24+
<depend>autoware_adapi_v1_msgs</depend>
2425
<depend>autoware_control_msgs</depend>
2526
<depend>autoware_interpolation</depend>
2627
<depend>autoware_vehicle_msgs</depend>

vehicle/autoware_raw_vehicle_cmd_converter/schema/raw_vehicle_cmd_converter.schema.json

+5
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,11 @@
180180
"type": "boolean",
181181
"default": "true",
182182
"description": "convert actuation to steering status or not. Whether to subscribe to actuation_status and calculate and publish steering_status For example, receive the steering wheel angle and calculate the steering wheel angle based on the gear ratio. If false, the vehicle interface must publish steering_status."
183+
},
184+
"use_vehicle_adaptor": {
185+
"type": "boolean",
186+
"default": "false",
187+
"description": "flag to enable feature that compensates control commands according to vehicle dynamics."
183188
}
184189
},
185190
"required": [

vehicle/autoware_raw_vehicle_cmd_converter/src/node.cpp

+39-19
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ RawVehicleCommandConverterNode::RawVehicleCommandConverterNode(
4040
// for steering steer controller
4141
use_steer_ff_ = declare_parameter<bool>("use_steer_ff");
4242
use_steer_fb_ = declare_parameter<bool>("use_steer_fb");
43+
use_vehicle_adaptor_ = declare_parameter<bool>("use_vehicle_adaptor", false);
44+
4345
if (convert_accel_cmd_) {
4446
if (!accel_map_.readAccelMapFromCSV(csv_path_accel_map, true)) {
4547
throw std::invalid_argument("Accel map is invalid.");
@@ -116,15 +118,21 @@ RawVehicleCommandConverterNode::RawVehicleCommandConverterNode(
116118
debug_pub_steer_pid_ = create_publisher<Float32MultiArrayStamped>(
117119
"/vehicle/raw_vehicle_cmd_converter/debug/steer_pid", 1);
118120

121+
if (use_vehicle_adaptor_) {
122+
pub_compensated_control_cmd_ = create_publisher<Control>(
123+
"/vehicle/raw_vehicle_cmd_converter/debug/compensated_control_cmd", 1);
124+
}
125+
119126
logger_configure_ = std::make_unique<autoware::universe_utils::LoggerLevelConfigure>(this);
120127
}
121128

122129
void RawVehicleCommandConverterNode::publishActuationCmd()
123130
{
124-
if (!current_twist_ptr_ || !control_cmd_ptr_ || !current_steer_ptr_) {
131+
/* check if all necessary data is available */
132+
if (!current_odometry_ || !control_cmd_ptr_ || !current_steer_ptr_) {
125133
RCLCPP_WARN_EXPRESSION(
126134
get_logger(), is_debugging_, "some pointers are null: %s, %s, %s",
127-
!current_twist_ptr_ ? "twist" : "", !control_cmd_ptr_ ? "cmd" : "",
135+
!current_odometry_ ? "odometry" : "", !control_cmd_ptr_ ? "cmd" : "",
128136
!current_steer_ptr_ ? "steer" : "");
129137
return;
130138
}
@@ -136,14 +144,34 @@ void RawVehicleCommandConverterNode::publishActuationCmd()
136144
}
137145
}
138146

147+
/* compensate control command if vehicle adaptor is enabled */
148+
Control control_cmd = *control_cmd_ptr_;
149+
if (use_vehicle_adaptor_) {
150+
const auto current_accel = sub_accel_.takeData();
151+
const auto current_operation_mode = sub_operation_mode_.takeData();
152+
const auto control_horizon = sub_control_horizon_.takeData();
153+
if (!current_accel || !current_operation_mode || !control_horizon) {
154+
RCLCPP_WARN_EXPRESSION(
155+
get_logger(), is_debugging_, "some pointers are null: %s, %s %s",
156+
!current_accel ? "accel" : "", !current_operation_mode ? "operation_mode" : "",
157+
!control_horizon ? "control_horizon" : "");
158+
return;
159+
}
160+
control_cmd = vehicle_adaptor_.compensate(
161+
*control_cmd_ptr_, *current_odometry_, *current_accel, *current_steer_ptr_,
162+
*current_operation_mode, *control_horizon);
163+
pub_compensated_control_cmd_->publish(control_cmd);
164+
}
165+
166+
/* calculate actuation command */
139167
double desired_accel_cmd = 0.0;
140168
double desired_brake_cmd = 0.0;
141169
double desired_steer_cmd = 0.0;
142170
ActuationCommandStamped actuation_cmd;
143-
const double acc = control_cmd_ptr_->longitudinal.acceleration;
144-
const double vel = current_twist_ptr_->twist.linear.x;
145-
const double steer = control_cmd_ptr_->lateral.steering_tire_angle;
146-
const double steer_rate = control_cmd_ptr_->lateral.steering_tire_rotation_rate;
171+
const double acc = control_cmd.longitudinal.acceleration;
172+
const double vel = current_odometry_->twist.twist.linear.x;
173+
const double steer = control_cmd.lateral.steering_tire_angle;
174+
const double steer_rate = control_cmd.lateral.steering_tire_rotation_rate;
147175
bool accel_cmd_is_zero = true;
148176
if (convert_accel_cmd_) {
149177
desired_accel_cmd = calculateAccelMap(vel, acc, accel_cmd_is_zero);
@@ -173,7 +201,7 @@ void RawVehicleCommandConverterNode::publishActuationCmd()
173201
desired_steer_cmd = calculateSteerFromMap(vel, steer, steer_rate);
174202
}
175203
actuation_cmd.header.frame_id = "base_link";
176-
actuation_cmd.header.stamp = control_cmd_ptr_->stamp;
204+
actuation_cmd.header.stamp = control_cmd.stamp;
177205
actuation_cmd.actuation.accel_cmd = desired_accel_cmd;
178206
actuation_cmd.actuation.brake_cmd = desired_brake_cmd;
179207
actuation_cmd.actuation.steer_cmd = desired_steer_cmd;
@@ -252,12 +280,7 @@ double RawVehicleCommandConverterNode::calculateBrakeMap(
252280

253281
void RawVehicleCommandConverterNode::onControlCmd(const Control::ConstSharedPtr msg)
254282
{
255-
const auto odometry_msg = sub_odometry_.takeData();
256-
if (odometry_msg) {
257-
current_twist_ptr_ = std::make_unique<TwistStamped>();
258-
current_twist_ptr_->header = odometry_msg->header;
259-
current_twist_ptr_->twist = odometry_msg->twist.twist;
260-
}
283+
current_odometry_ = sub_odometry_.takeData();
261284
control_cmd_ptr_ = msg;
262285
publishActuationCmd();
263286
}
@@ -277,14 +300,11 @@ void RawVehicleCommandConverterNode::onActuationStatus(
277300
}
278301

279302
// calculate steering status from actuation status
280-
const auto odometry_msg = sub_odometry_.takeData();
281-
if (odometry_msg) {
303+
current_odometry_ = sub_odometry_.takeData();
304+
if (current_odometry_) {
282305
if (convert_steer_cmd_method_.value() == "vgr") {
283-
current_twist_ptr_ = std::make_unique<TwistStamped>();
284-
current_twist_ptr_->header = odometry_msg->header;
285-
current_twist_ptr_->twist = odometry_msg->twist.twist;
286306
current_steer_ptr_ = std::make_unique<double>(vgr_.calculateSteeringTireState(
287-
current_twist_ptr_->twist.linear.x, actuation_status_ptr_->status.steer_status));
307+
current_odometry_->twist.twist.linear.x, actuation_status_ptr_->status.steer_status));
288308
Steering steering_msg{};
289309
steering_msg.steering_tire_angle = *current_steer_ptr_;
290310
pub_steering_status_->publish(steering_msg);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// Copyright 2024 Tier IV, Inc. All rights reserved.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
#include "autoware_raw_vehicle_cmd_converter/vehicle_adaptor/vehicle_adaptor.hpp"
16+
17+
#include <iostream>
18+
19+
namespace autoware::raw_vehicle_cmd_converter
20+
{
21+
Control VehicleAdaptor::compensate(
22+
const Control & input_control_cmd, [[maybe_unused]] const Odometry & odometry,
23+
[[maybe_unused]] const AccelWithCovarianceStamped & accel, [[maybe_unused]] const double steering,
24+
[[maybe_unused]] const OperationModeState & operation_mode,
25+
[[maybe_unused]] const ControlHorizon & control_horizon)
26+
{
27+
// TODO(someone): implement the control command compensation
28+
Control output_control_cmd = input_control_cmd;
29+
std::cerr << "vehicle adaptor: compensate control command" << std::endl;
30+
return output_control_cmd;
31+
}
32+
} // namespace autoware::raw_vehicle_cmd_converter

0 commit comments

Comments
 (0)