CARLA
Loading...
Searching...
No Matches
AutowareGNSSPublisher.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"
15
16namespace carla {
17namespace ros2 {
18
23
29
31 std::string base_topic_name, std::string frame_id)
32 : BasePublisher(std::move(base_topic_name), std::move(frame_id)),
33 _impl(std::make_shared<Impl>()) {
34 // QoS per tier4's AutowareGNSSPublisher: RELIABLE / VOLATILE / KEEP_LAST 1.
36 bool ok = true;
37 ok &= _impl->pose.Init(GetBaseTopicName() + "/pose", qos);
38 ok &= _impl->pose_with_covariance.Init(
39 GetBaseTopicName() + "/pose_with_covariance", qos);
40 if (!ok) {
41 log_error("AutowareGNSSPublisher: failed to initialise writers for",
43 }
44}
45
47
49 std::int32_t seconds,
50 std::uint32_t nanoseconds,
51 float tx, float ty, float tz,
52 float pitch_deg, float yaw_deg, float roll_deg,
53 double mgrs_offset_x, double mgrs_offset_y, double mgrs_offset_z) {
54 // Same CARLA-to-ROS handedness conversion as CarlaTransformPublisher
55 // (tier4 copied that math into AutowareGNSSPublisher::SetData).
56 const TransformQuaternion tq =
57 TransformFromCarlaRotation(tx, ty, tz, pitch_deg, yaw_deg, roll_deg);
58
59 auto *pose = _impl->pose.GetMessage();
60 pose->position.x = static_cast<double>(tq.translation[0]) + mgrs_offset_x;
61 pose->position.y = static_cast<double>(tq.translation[1]) + mgrs_offset_y;
62 pose->position.z = static_cast<double>(tq.translation[2]) + mgrs_offset_z;
63 pose->orientation.w = tq.rotation[0];
64 pose->orientation.x = tq.rotation[1];
65 pose->orientation.y = tq.rotation[2];
66 pose->orientation.z = tq.rotation[3];
67
68 auto *pwcs = _impl->pose_with_covariance.GetMessage();
69 pwcs->header.stamp.sec = seconds;
70 pwcs->header.stamp.nanosec = nanoseconds;
71 pwcs->header.frame_id = GetFrameId();
72 pwcs->pose.pose = *pose;
73 pwcs->pose.covariance = {}; // TODO(tier4 parity): meaningful covariance.
74 return true;
75}
76
78 bool ok = true;
79 ok &= _impl->pose.Publish();
80 ok &= _impl->pose_with_covariance.Publish();
81 return ok;
82}
83
84} // namespace ros2
85} // namespace carla
PublisherImpl< AutowareGnssPoseTraits > pose
PublisherImpl< AutowareGnssPoseWithCovarianceTraits > pose_with_covariance
AutowareGNSSPublisher(std::string base_topic_name, std::string frame_id)
bool Publish() override
Publishes both topics.
bool Write(std::int32_t seconds, std::uint32_t nanoseconds, float tx, float ty, float tz, float pitch_deg, float yaw_deg, float roll_deg, double mgrs_offset_x, double mgrs_offset_y, double mgrs_offset_z)
Fill both pose messages from the sensor's CARLA world transform (translation in meters,...
const std::string & GetBaseTopicName() const noexcept
const std::string & GetFrameId() const noexcept
TransformQuaternion TransformFromCarlaRotation(float tx, float ty, float tz, float pitch_deg, float yaw_deg, float roll_deg) noexcept
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