CARLA
Loading...
Searching...
No Matches
AutowareVehicleStatusPublisher.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
23namespace {
24constexpr const char *kFrameId = "base_link";
25} // namespace
26
33
43
45 : BasePublisher("rt/vehicle/status", kFrameId),
46 _impl(std::make_shared<Impl>()) {
47 // QoS per tier4's AutowarePublisher: RELIABLE / VOLATILE / KEEP_LAST 1.
49 bool ok = true;
50 ok &= _impl->velocity.Init("rt/vehicle/status/velocity_status", qos);
51 ok &= _impl->steering.Init("rt/vehicle/status/steering_status", qos);
52 ok &= _impl->control_mode.Init("rt/vehicle/status/control_mode", qos);
53 ok &= _impl->gear.Init("rt/vehicle/status/gear_status", qos);
54 ok &= _impl->turn_indicators.Init("rt/vehicle/status/turn_indicators_status", qos);
55 ok &= _impl->hazard_lights.Init("rt/vehicle/status/hazard_lights_status", qos);
56 if (!ok) {
57 log_error("AutowareVehicleStatusPublisher: failed to initialise one or more report writers");
58 }
59}
60
62
64 float longitudinal_velocity, float lateral_velocity, float heading_rate) {
65 auto *report = _impl->velocity.GetMessage();
66 // Leave header.stamp empty; Publish() populates the stamp.
67 report->header.frame_id = kFrameId;
68 report->longitudinal_velocity = longitudinal_velocity;
69 report->lateral_velocity = lateral_velocity;
70 report->heading_rate = heading_rate;
71}
72
73void AutowareVehicleStatusPublisher::SetSteering(float steering_tire_angle) {
74 auto *report = _impl->steering.GetMessage();
75 // Report the *actual* tire angle: apply the inverse compensation LUT so the
76 // published state matches what the command-side GetSteeringInput mapping
77 // asked the vehicle to do (tier4 AutowarePublisher::SetSteering).
78 report->steering_tire_angle =
80}
81
83 auto *report = _impl->control_mode.GetMessage();
84 switch (mode) {
85#define CASE(DATUM) \
86 case ControlMode::DATUM: \
87 report->mode = msg::ControlModeReport::DATUM; \
88 break; \
89 static_assert(true, "")
90
95 CASE(MANUAL);
98
99#undef CASE
100 }
101}
102
104 auto *report = _impl->gear.GetMessage();
105 switch (gear) {
106#define CASE(DATUM) \
107 case Gear::DATUM: \
108 report->report = msg::GearReport::DATUM; \
109 break; \
110 static_assert(true, "")
111
112 CASE(NONE);
113 CASE(NEUTRAL);
114 CASE(DRIVE);
115 CASE(DRIVE_2);
116 CASE(DRIVE_3);
117 CASE(DRIVE_4);
118 CASE(DRIVE_5);
119 CASE(DRIVE_6);
120 CASE(DRIVE_7);
121 CASE(DRIVE_8);
122 CASE(DRIVE_9);
123 CASE(DRIVE_10);
124 CASE(DRIVE_11);
125 CASE(DRIVE_12);
126 CASE(DRIVE_13);
127 CASE(DRIVE_14);
128 CASE(DRIVE_15);
129 CASE(DRIVE_16);
130 CASE(DRIVE_17);
131 CASE(DRIVE_18);
132 CASE(REVERSE);
134 CASE(PARK);
135 CASE(LOW);
136 CASE(LOW_2);
137
138#undef CASE
139 }
140}
141
143 auto *report = _impl->turn_indicators.GetMessage();
144 switch (status) {
146 report->report = msg::TurnIndicatorsReport::DISABLE;
147 break;
150 break;
153 break;
154 }
155}
156
157void AutowareVehicleStatusPublisher::SetHazardLights(const bool hazard_lights_enabled) {
158 auto *report = _impl->hazard_lights.GetMessage();
159 report->report = hazard_lights_enabled ? msg::HazardLightsReport::ENABLE
161}
162
164 std::int32_t seconds, std::uint32_t nanoseconds) {
165 _seconds = seconds;
166 _nanoseconds = nanoseconds;
167 return Publish();
168}
169
171 // All reports are published at once with the same stamp based on the
172 // assumption that they share one frequency.
173 // https://github.com/tier4/AWSIM/blob/v1.3.1/docs/Components/ROS2/ROS2TopicAndServiceList/index.md
174 _impl->velocity.GetMessage()->header.stamp.sec = _seconds;
175 _impl->velocity.GetMessage()->header.stamp.nanosec = _nanoseconds;
176 _impl->steering.GetMessage()->stamp.sec = _seconds;
177 _impl->steering.GetMessage()->stamp.nanosec = _nanoseconds;
178 _impl->control_mode.GetMessage()->stamp.sec = _seconds;
179 _impl->control_mode.GetMessage()->stamp.nanosec = _nanoseconds;
180 _impl->gear.GetMessage()->stamp.sec = _seconds;
181 _impl->gear.GetMessage()->stamp.nanosec = _nanoseconds;
182 _impl->turn_indicators.GetMessage()->stamp.sec = _seconds;
183 _impl->turn_indicators.GetMessage()->stamp.nanosec = _nanoseconds;
184 _impl->hazard_lights.GetMessage()->stamp.sec = _seconds;
185 _impl->hazard_lights.GetMessage()->stamp.nanosec = _nanoseconds;
186
187 bool ok = true;
188 ok &= _impl->velocity.Publish();
189 ok &= _impl->steering.Publish();
190 ok &= _impl->control_mode.Publish();
191 ok &= _impl->gear.Publish();
192 ok &= _impl->turn_indicators.Publish();
193 ok &= _impl->hazard_lights.Publish();
194 return ok;
195}
196
197} // namespace ros2
198} // namespace carla
#define CASE(DATUM)
PublisherImpl< AutowareTurnIndicatorsReportTraits > turn_indicators
PublisherImpl< AutowareSteeringReportTraits > steering
PublisherImpl< AutowareHazardLightsReportTraits > hazard_lights
PublisherImpl< AutowareVelocityReportTraits > velocity
PublisherImpl< AutowareControlModeReportTraits > control_mode
bool Publish() override
BasePublisher interface; publishes with the last stamp given to the two-argument overload (0,...
void SetVelocity(float longitudinal_velocity, float lateral_velocity, float heading_rate)
float GetSteeringOutput(const float input_angle)
Desired vehicle-input angle -> observed (actual) tire angle.
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 ReliableVolatile()
RELIABLE / VOLATILE / KEEP_LAST depth 1 — the profile tier4 uses for the Autoware report publishers.
Definition QosProfile.h:51