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 // QoS per tier4's AutowareController: RELIABLE / TRANSIENT_LOCAL /
54 // KEEP_LAST 1 so the latest latched command survives a late join.
56 bool ok = true;
57 ok &= _impl->control.Init("rt/control/command/control_cmd", qos);
58 ok &= _impl->gear.Init("rt/control/command/gear_cmd", qos);
59 ok &= _impl->turn_indicators.Init("rt/control/command/turn_indicators_cmd", qos);
60 ok &= _impl->hazard_lights.Init("rt/control/command/hazard_lights_cmd", qos);
61 ok &= _impl->emergency.Init("rt/control/command/emergency_cmd", qos);
62 ok &= _impl->engage.Init("rt/vehicle/engage", qos);
63 if (!ok) {
64 log_error("AutowareControlSubscriber: failed to initialize one or more command readers");
65 }
66}
67
69
71 // Drain every subscriber (clearing its new-message flag) even though only
72 // control_cmd feeds the vehicle today — tier4 AutowareController::GetControl
73 // does the same; gear/turn/hazard/emergency/engage application is a tier4
74 // TODO deferred to the Unreal phase.
75 const auto control_in = _impl->control.GetMessage();
76 (void)_impl->gear.GetMessage();
77 (void)_impl->turn_indicators.GetMessage();
78 (void)_impl->hazard_lights.GetMessage();
79 (void)_impl->emergency.GetMessage();
80 (void)_impl->engage.GetMessage();
81
82 VehicleAccelerationControl control_out{};
83
84 // Longitudinal: use ONLY acceleration from /control/command/control_cmd to
85 // drive the vehicle. Velocity and jerk from the message are intentionally
86 // ignored to keep pure acceleration control.
87 control_out.acceleration = control_in.longitudinal.acceleration;
88
89 // Set lateral negative, because CARLA treats positive as right and Autoware
90 // expects positive to represent left (all when moving forward).
91 const float raw_steering = -control_in.lateral.steering_tire_angle;
92
93 // Apply steering compensation lookup table (measured on Lincoln MKZ). This
94 // reduces understeer / outward drift by mapping Autoware's target tire angle
95 // to a vehicle input that better matches the requested actual tire angle.
96 control_out.steer = autoware_steering_compensation::GetSteeringInput(raw_steering);
97 control_out.steer_speed = 0.0f;
98 if (control_in.lateral.is_defined_steering_tire_rotation_rate) {
99 control_out.steer_speed = -control_in.lateral.steering_tire_rotation_rate;
100 }
101
102 return ROS2CallbackData(control_out);
103}
104
106 if (_impl->HasNewMessage()) {
107 auto control = this->GetMessage();
108 callback(this->GetActor(), control);
109 }
110}
111
112} // namespace ros2
113} // 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::function< void(void *actor, ROS2CallbackData data)> ActorCallback
std::variant< VehicleControl, AckermannControl, VehicleAccelerationControl > ROS2CallbackData
This file contains definitions of common data structures used in traffic manager.
static void log_error(Args &&... args)
Definition Logging.h:110
Middleware-neutral QoS profile passed to IPublisherMiddleware::Init / ISubscriberMiddleware::Init whe...
Definition QosProfile.h:27
static QosProfile ReliableTransientLocal()
RELIABLE / TRANSIENT_LOCAL / KEEP_LAST depth 1 — the profile tier4 uses for the Autoware command subs...
Definition QosProfile.h:40
Control decoded from Autoware's /control/command/control_cmd: longitudinal acceleration [m/s^2] + ste...
autoware_control_msgs/msg/Control
Definition Control.h:15