CARLA
Loading...
Searching...
No Matches
AutowareControlSubscriber.cpp
Go to the documentation of this file.
1// Copyright (c) 2026 Computer Vision Center (CVC) at the Universitat Autonoma
2// de Barcelona (UAB).
3//
4// This work is licensed under the terms of the MIT license.
5// For a copy, see <https://opensource.org/licenses/MIT>.
6
8
9#include "carla/Logging.h"
19
20namespace carla {
21namespace ros2 {
22
29
48
50 void *vehicle, std::string frame_id)
51 : BaseSubscriber(vehicle, "rt/control/command", std::move(frame_id)),
52 _impl(std::make_shared<Impl>()) {
53 // RELIABLE / VOLATILE / KEEP_LAST 1. A volatile reader matches both kinds of
54 // Autoware command writer: vehicle_cmd_gate's (TRANSIENT_LOCAL) and
55 // control_command_gate's (VOLATILE), which replaces it in autoware_launch
56 // (#1897). A TRANSIENT_LOCAL reader matches only the former; DDS does not
57 // pair a TRANSIENT_LOCAL reader with a VOLATILE writer, so nothing arrived.
58 // The commands stream at the control rate, so nothing depends on a latched
59 // sample.
61 bool ok = true;
62 ok &= _impl->control.Init("rt/control/command/control_cmd", qos);
63 ok &= _impl->gear.Init("rt/control/command/gear_cmd", qos);
64 ok &= _impl->turn_indicators.Init("rt/control/command/turn_indicators_cmd", qos);
65 ok &= _impl->hazard_lights.Init("rt/control/command/hazard_lights_cmd", qos);
66 ok &= _impl->emergency.Init("rt/control/command/emergency_cmd", qos);
67 ok &= _impl->engage.Init("rt/vehicle/engage", qos);
68 if (!ok) {
69 log_error("AutowareControlSubscriber: failed to initialize one or more command readers");
70 }
71}
72
74
76 // Drain every subscriber (clearing its new-message flag) even though only
77 // control_cmd feeds the vehicle today — tier4 AutowareController::GetControl
78 // does the same; gear/turn/hazard/emergency/engage application is a tier4
79 // TODO deferred to the Unreal phase.
80 const auto control_in = _impl->control.GetMessage();
81 (void)_impl->gear.GetMessage();
82 (void)_impl->turn_indicators.GetMessage();
83 (void)_impl->hazard_lights.GetMessage();
84 (void)_impl->emergency.GetMessage();
85 (void)_impl->engage.GetMessage();
86
87 VehicleAccelerationControl control_out{};
88
89 // Longitudinal: use ONLY acceleration from /control/command/control_cmd to
90 // drive the vehicle. Velocity and jerk from the message are intentionally
91 // ignored to keep pure acceleration control.
92 control_out.acceleration = control_in.longitudinal.acceleration;
93
94 // Set lateral negative, because CARLA treats positive as right and Autoware
95 // expects positive to represent left (all when moving forward).
96 const float raw_steering = -control_in.lateral.steering_tire_angle;
97
98 // Apply steering compensation lookup table (measured on Lincoln MKZ). This
99 // reduces understeer / outward drift by mapping Autoware's target tire angle
100 // to a vehicle input that better matches the requested actual tire angle.
102 control_out.steer_speed = 0.0f;
103 if (control_in.lateral.is_defined_steering_tire_rotation_rate) {
104 control_out.steer_speed = -control_in.lateral.steering_tire_rotation_rate;
105 }
106
107 return ROS2CallbackData(control_out);
108}
109
111 if (_impl->HasNewMessage()) {
112 auto control = this->GetMessage();
113 callback(this->GetActor(), control);
114 }
115}
116
117} // namespace ros2
118} // namespace carla
SubscriberImpl< AutowareEmergencyCmdTraits > emergency
SubscriberImpl< AutowareHazardLightsCmdTraits > hazard_lights
SubscriberImpl< AutowareGearCmdTraits > gear
SubscriberImpl< AutowareEngageTraits > engage
SubscriberImpl< AutowareTurnIndicatorsCmdTraits > turn_indicators
SubscriberImpl< AutowareControlCmdTraits > control
AutowareControlSubscriber(void *vehicle, std::string frame_id)
void ProcessMessages(ActorCallback callback) override
Drains the six command topics once per frame (called from ROS2::SetFrame like every BaseSubscriber).
void * GetActor() const noexcept
float GetSteeringInput(const float output_angle)
Target (actual) tire angle -> vehicle input that produces it.
std::variant< VehicleControl, AckermannControl, VehicleAccelerationControl > ROS2CallbackData
std::function< void(void *actor, ROS2CallbackData data)> ActorCallback
This file contains definitions of common data structures used in traffic manager.
Middleware-neutral QoS profile passed to IPublisherMiddleware::Init / ISubscriberMiddleware::Init whe...
Definition QosProfile.h:27
static QosProfile ReliableVolatile()
RELIABLE / VOLATILE / KEEP_LAST depth 1 — the Autoware report publishers and command subscribers (a v...
Definition QosProfile.h:52
Control decoded from Autoware's /control/command/control_cmd: longitudinal acceleration [m/s^2] + ste...
autoware_control_msgs/msg/Control
Definition Control.h:15