CARLA
Toggle main menu visibility
Loading...
Searching...
No Matches
LibCarla
source
carla
ros2
publishers
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
7
#include "
carla/ros2/publishers/AutowareGNSSPublisher.h
"
8
9
#include "
carla/Logging.h
"
10
#include "
carla/ros2/middleware/QosProfile.h
"
11
#include "
carla/ros2/publishers/PublisherImpl.h
"
12
#include "
carla/ros2/publishers/TransformQuaternion.h
"
13
#include "
carla/ros2/types/msg/Pose.h
"
14
#include "
carla/ros2/types/msg/PoseWithCovarianceStamped.h
"
15
16
namespace
carla
{
17
namespace
ros2
{
18
19
struct
AutowareGnssPoseTraits
{
using
msg_type
=
msg::Pose
; };
20
struct
AutowareGnssPoseWithCovarianceTraits
{
21
using
msg_type
=
msg::PoseWithCovarianceStamped
;
22
};
23
24
class
AutowareGNSSPublisher::Impl
{
25
public
:
26
PublisherImpl<AutowareGnssPoseTraits>
pose
;
27
PublisherImpl<AutowareGnssPoseWithCovarianceTraits>
pose_with_covariance
;
28
};
29
30
AutowareGNSSPublisher::AutowareGNSSPublisher
(
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.
35
const
QosProfile
qos =
QosProfile::ReliableVolatile
();
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"
,
42
GetBaseTopicName
());
43
}
44
}
45
46
AutowareGNSSPublisher::~AutowareGNSSPublisher
() =
default
;
47
48
bool
AutowareGNSSPublisher::Write
(
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
77
bool
AutowareGNSSPublisher::Publish
() {
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
AutowareGNSSPublisher.h
Logging.h
PoseWithCovarianceStamped.h
Pose.h
PublisherImpl.h
QosProfile.h
TransformQuaternion.h
carla::ros2::AutowareGNSSPublisher::Impl
Definition
AutowareGNSSPublisher.cpp:24
carla::ros2::AutowareGNSSPublisher::Impl::pose
PublisherImpl< AutowareGnssPoseTraits > pose
Definition
AutowareGNSSPublisher.cpp:26
carla::ros2::AutowareGNSSPublisher::Impl::pose_with_covariance
PublisherImpl< AutowareGnssPoseWithCovarianceTraits > pose_with_covariance
Definition
AutowareGNSSPublisher.cpp:27
carla::ros2::AutowareGNSSPublisher::AutowareGNSSPublisher
AutowareGNSSPublisher(std::string base_topic_name, std::string frame_id)
Definition
AutowareGNSSPublisher.cpp:30
carla::ros2::AutowareGNSSPublisher::_impl
std::shared_ptr< Impl > _impl
Definition
AutowareGNSSPublisher.h:49
carla::ros2::AutowareGNSSPublisher::Publish
bool Publish() override
Publishes both topics.
Definition
AutowareGNSSPublisher.cpp:77
carla::ros2::AutowareGNSSPublisher::~AutowareGNSSPublisher
~AutowareGNSSPublisher() override
carla::ros2::AutowareGNSSPublisher::Write
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,...
Definition
AutowareGNSSPublisher.cpp:48
carla::ros2::BasePublisher::BasePublisher
BasePublisher()=default
carla::ros2::BasePublisher::GetBaseTopicName
const std::string & GetBaseTopicName() const noexcept
Definition
BasePublisher.h:42
carla::ros2::BasePublisher::GetFrameId
const std::string & GetFrameId() const noexcept
Definition
BasePublisher.h:43
carla::ros2::PublisherImpl
Definition
PublisherImpl.h:28
carla::ros2
Definition
AutowareSteeringCompensation.h:15
carla::ros2::TransformFromCarlaRotation
TransformQuaternion TransformFromCarlaRotation(float tx, float ty, float tz, float pitch_deg, float yaw_deg, float roll_deg) noexcept
Definition
TransformQuaternion.h:43
carla
This file contains definitions of common data structures used in traffic manager.
Definition
SignComponent.h:21
std
Definition
CarlaRecorderCollision.h:31
carla::ros2::AutowareGnssPoseTraits
Definition
AutowareGNSSPublisher.cpp:19
carla::ros2::AutowareGnssPoseTraits::msg_type
msg::Pose msg_type
Definition
AutowareGNSSPublisher.cpp:19
carla::ros2::AutowareGnssPoseWithCovarianceTraits
Definition
AutowareGNSSPublisher.cpp:20
carla::ros2::AutowareGnssPoseWithCovarianceTraits::msg_type
msg::PoseWithCovarianceStamped msg_type
Definition
AutowareGNSSPublisher.cpp:21
carla::ros2::QosProfile
Middleware-neutral QoS profile passed to IPublisherMiddleware::Init / ISubscriberMiddleware::Init whe...
Definition
QosProfile.h:27
carla::ros2::QosProfile::ReliableVolatile
static QosProfile ReliableVolatile()
RELIABLE / VOLATILE / KEEP_LAST depth 1 — the Autoware report publishers and command subscribers (a v...
Definition
QosProfile.h:52
carla::ros2::TransformQuaternion
Definition
TransformQuaternion.h:18
carla::ros2::TransformQuaternion::translation
std::array< float, 3 > translation
Definition
TransformQuaternion.h:19
carla::ros2::TransformQuaternion::rotation
std::array< float, 4 > rotation
Definition
TransformQuaternion.h:20
carla::ros2::msg::PoseWithCovarianceStamped
Definition
PoseWithCovarianceStamped.h:13
carla::ros2::msg::Pose
Definition
Pose.h:13
Generated by
1.18.0