Skip to content

Commit a2356f3

Browse files
committed
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>
1 parent a7314b6 commit a2356f3

File tree

8 files changed

+135
-22
lines changed

8 files changed

+135
-22
lines changed

Diff for: simulator/autoware_carla_interface/launch/autoware_carla_interface.launch.xml

+2
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131

3232
<arg name="input_control_cmd" default="/control/command/control_cmd"/>
3333
<arg name="input_odometry" default="/localization/kinematic_state"/>
34+
<arg name="input_accel" default="/localization/acceleration"/>
3435
<arg name="input_steering" default="/vehicle/status/steering_status"/>
3536
<arg name="output_actuation_cmd" default="/control/command/actuation_cmd"/>
3637
<arg name="config_file" default="$(find-pkg-share autoware_carla_interface)/raw_vehicle_cmd_converter.param.yaml"/>
@@ -39,6 +40,7 @@
3940
<param from="$(var config_file)" allow_substs="true"/>
4041
<remap from="~/input/control_cmd" to="$(var input_control_cmd)"/>
4142
<remap from="~/input/odometry" to="$(var input_odometry)"/>
43+
<remap from="~/input/accel" to="$(var input_accel)"/>
4244
<remap from="~/input/steering" to="$(var input_steering)"/>
4345
<remap from="~/output/actuation_cmd" to="$(var output_actuation_cmd)"/>
4446
</node>

Diff for: 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

Diff for: vehicle/autoware_raw_vehicle_cmd_converter/include/autoware_raw_vehicle_cmd_converter/node.hpp

+11-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:
@@ -86,17 +89,23 @@ class RawVehicleCommandConverterNode : public rclcpp::Node
8689
// polling subscribers
8790
autoware::universe_utils::InterProcessPollingSubscriber<Odometry> sub_odometry_{
8891
this, "~/input/odometry"};
92+
autoware::universe_utils::InterProcessPollingSubscriber<AccelWithCovarianceStamped> sub_accel_{
93+
this, "~/input/accel"};
94+
autoware::universe_utils::InterProcessPollingSubscriber<OperationModeState> sub_operation_mode_{
95+
this, "~/input/operation_mode_state"};
8996

9097
rclcpp::TimerBase::SharedPtr timer_;
9198

9299
std::unique_ptr<TwistStamped> current_twist_ptr_; // [m/s]
93100
std::unique_ptr<double> current_steer_ptr_;
94101
ActuationStatusStamped::ConstSharedPtr actuation_status_ptr_;
102+
Odometry::ConstSharedPtr current_odometry_;
95103
Control::ConstSharedPtr control_cmd_ptr_;
96104
AccelMap accel_map_;
97105
BrakeMap brake_map_;
98106
SteerMap steer_map_;
99107
VGR vgr_;
108+
VehicleAdaptor vehicle_adaptor_;
100109
// TODO(tanaka): consider accel/brake pid too
101110
PIDController steer_pid_;
102111
bool ff_map_initialized_;
@@ -112,6 +121,7 @@ class RawVehicleCommandConverterNode : public rclcpp::Node
112121
bool convert_brake_cmd_; //!< @brief use brake or not
113122
std::optional<std::string> convert_steer_cmd_method_{std::nullopt}; //!< @brief method to convert
114123
bool need_to_subscribe_actuation_status_{false};
124+
bool use_vehicle_adaptor_{false};
115125
rclcpp::Time prev_time_steer_calculation_{0, 0, RCL_ROS_TIME};
116126

117127
// Whether to subscribe to actuation_status and calculate and publish steering_status
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
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_vehicle_msgs/msg/steering_report.hpp>
21+
#include <geometry_msgs/msg/accel_with_covariance_stamped.hpp>
22+
#include <nav_msgs/msg/odometry.hpp>
23+
24+
namespace autoware::raw_vehicle_cmd_converter
25+
{
26+
27+
using autoware_adapi_v1_msgs::msg::OperationModeState;
28+
using autoware_control_msgs::msg::Control;
29+
using autoware_vehicle_msgs::msg::SteeringReport;
30+
using geometry_msgs::msg::AccelWithCovarianceStamped;
31+
using nav_msgs::msg::Odometry;
32+
33+
class VehicleAdaptor
34+
{
35+
public:
36+
VehicleAdaptor() = default;
37+
Control compensate(
38+
const Control & input_control_cmd, [[maybe_unused]] const Odometry & odometry,
39+
[[maybe_unused]] const AccelWithCovarianceStamped & accel,
40+
[[maybe_unused]] const double steering,
41+
[[maybe_unused]] const OperationModeState & operation_mode);
42+
43+
private:
44+
};
45+
} // namespace autoware::raw_vehicle_cmd_converter
46+
47+
#endif // AUTOWARE_RAW_VEHICLE_CMD_CONVERTER__VEHICLE_ADAPTOR__VEHICLE_ADAPTOR_HPP_

Diff for: vehicle/autoware_raw_vehicle_cmd_converter/launch/raw_vehicle_converter.launch.xml

+4
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@
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"/>
79
<arg name="output_actuation_cmd" default="/control/command/actuation_cmd"/>
810
<arg name="output_steering_status" default="/vehicle/status/steering_status"/>
911
<!-- Parameter -->
@@ -13,8 +15,10 @@
1315
<param from="$(var config_file)" allow_substs="true"/>
1416
<remap from="~/input/control_cmd" to="$(var input_control_cmd)"/>
1517
<remap from="~/input/odometry" to="$(var input_odometry)"/>
18+
<remap from="~/input/accel" to="$(var input_accel)"/>
1619
<remap from="~/input/steering" to="$(var input_steering)"/>
1720
<remap from="~/input/actuation_status" to="$(var input_actuation_status)"/>
21+
<remap from="~/input/operation_mode_state" to="$(var input_operation_mode_state)"/>
1822
<remap from="~/output/actuation_cmd" to="$(var output_actuation_cmd)"/>
1923
<remap from="~/output/steering_status" to="$(var output_steering_status)"/>
2024
</node>

Diff for: 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>

Diff for: vehicle/autoware_raw_vehicle_cmd_converter/src/node.cpp

+33-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.");
@@ -121,10 +123,11 @@ RawVehicleCommandConverterNode::RawVehicleCommandConverterNode(
121123

122124
void RawVehicleCommandConverterNode::publishActuationCmd()
123125
{
124-
if (!current_twist_ptr_ || !control_cmd_ptr_ || !current_steer_ptr_) {
126+
/* check if all necessary data is available */
127+
if (!current_odometry_ || !control_cmd_ptr_ || !current_steer_ptr_) {
125128
RCLCPP_WARN_EXPRESSION(
126129
get_logger(), is_debugging_, "some pointers are null: %s, %s, %s",
127-
!current_twist_ptr_ ? "twist" : "", !control_cmd_ptr_ ? "cmd" : "",
130+
!current_odometry_ ? "odometry" : "", !control_cmd_ptr_ ? "cmd" : "",
128131
!current_steer_ptr_ ? "steer" : "");
129132
return;
130133
}
@@ -136,14 +139,33 @@ void RawVehicleCommandConverterNode::publishActuationCmd()
136139
}
137140
}
138141

142+
const auto current_accel = sub_accel_.takeData();
143+
const auto current_operation_mode = sub_operation_mode_.takeData();
144+
if (use_vehicle_adaptor_) {
145+
if (!current_accel || !current_operation_mode) {
146+
RCLCPP_WARN_EXPRESSION(
147+
get_logger(), is_debugging_, "some pointers are null: %s, %s",
148+
!current_accel ? "accel" : "", !current_operation_mode ? "operation_mode" : "");
149+
return;
150+
}
151+
}
152+
153+
/* compensate control command if vehicle adaptor is enabled */
154+
const Control control_cmd = use_vehicle_adaptor_
155+
? vehicle_adaptor_.compensate(
156+
*control_cmd_ptr_, *current_odometry_, *current_accel,
157+
*current_steer_ptr_, *current_operation_mode)
158+
: *control_cmd_ptr_;
159+
160+
/* calculate actuation command */
139161
double desired_accel_cmd = 0.0;
140162
double desired_brake_cmd = 0.0;
141163
double desired_steer_cmd = 0.0;
142164
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;
165+
const double acc = control_cmd.longitudinal.acceleration;
166+
const double vel = current_odometry_->twist.twist.linear.x;
167+
const double steer = control_cmd.lateral.steering_tire_angle;
168+
const double steer_rate = control_cmd.lateral.steering_tire_rotation_rate;
147169
bool accel_cmd_is_zero = true;
148170
if (convert_accel_cmd_) {
149171
desired_accel_cmd = calculateAccelMap(vel, acc, accel_cmd_is_zero);
@@ -173,7 +195,7 @@ void RawVehicleCommandConverterNode::publishActuationCmd()
173195
desired_steer_cmd = calculateSteerFromMap(vel, steer, steer_rate);
174196
}
175197
actuation_cmd.header.frame_id = "base_link";
176-
actuation_cmd.header.stamp = control_cmd_ptr_->stamp;
198+
actuation_cmd.header.stamp = control_cmd.stamp;
177199
actuation_cmd.actuation.accel_cmd = desired_accel_cmd;
178200
actuation_cmd.actuation.brake_cmd = desired_brake_cmd;
179201
actuation_cmd.actuation.steer_cmd = desired_steer_cmd;
@@ -252,12 +274,7 @@ double RawVehicleCommandConverterNode::calculateBrakeMap(
252274

253275
void RawVehicleCommandConverterNode::onControlCmd(const Control::ConstSharedPtr msg)
254276
{
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-
}
277+
current_odometry_ = sub_odometry_.takeData();
261278
control_cmd_ptr_ = msg;
262279
publishActuationCmd();
263280
}
@@ -277,14 +294,11 @@ void RawVehicleCommandConverterNode::onActuationStatus(
277294
}
278295

279296
// calculate steering status from actuation status
280-
const auto odometry_msg = sub_odometry_.takeData();
281-
if (odometry_msg) {
297+
current_odometry_ = sub_odometry_.takeData();
298+
if (current_odometry_) {
282299
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;
286300
current_steer_ptr_ = std::make_unique<double>(vgr_.calculateSteeringTireState(
287-
current_twist_ptr_->twist.linear.x, actuation_status_ptr_->status.steer_status));
301+
current_odometry_->twist.twist.linear.x, actuation_status_ptr_->status.steer_status));
288302
Steering steering_msg{};
289303
steering_msg.steering_tire_angle = *current_steer_ptr_;
290304
pub_steering_status_->publish(steering_msg);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
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+
{
26+
// TODO(someone): implement the control command compensation
27+
Control output_control_cmd = input_control_cmd;
28+
std::cerr << "vehicle adaptor: compensate control command" << std::endl;
29+
return output_control_cmd;
30+
}
31+
} // namespace autoware::raw_vehicle_cmd_converter

0 commit comments

Comments
 (0)