CARLA
Loading...
Searching...
No Matches
CarlaTransformPublisher.h
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#pragma once
8
10
11#include <array>
12#include <cstdint>
13#include <memory>
14#include <string>
15#include <unordered_map>
16
17namespace carla {
18namespace ros2 {
19
20template <typename Traits> class PublisherImpl;
21struct CarlaTransformMsgTraits;
22
23// Publishes tf2_msgs::msg::TFMessage to the global "rt/tf" topic. Each
24// sensor owns its own instance and contributes one TransformStamped per
25// tick; subscribers see the full set fanned out across the topic. Callers
26// hand in raw float translation + Euler degrees so the header does not
27// include carla::geom::Transform (pulls MsgPack + Boost via
28// carla/MsgPack.h — neither is on the include path of the
29// carla-ros2-native ExternalProject).
31public:
34
38 CarlaTransformPublisher &operator=(CarlaTransformPublisher &&) noexcept = default;
39
40 bool Publish() override;
41
42 // Builds a TransformStamped(parent_frame_id -> child_frame_id) from the
43 // given CARLA-handed translation + Euler-degree rotation and stages it
44 // for the next Publish().
45 bool Write(
46 std::int32_t seconds,
47 std::uint32_t nanoseconds,
48 const std::string &parent_frame_id,
49 const std::string &child_frame_id,
50 float tx, float ty, float tz,
51 float pitch_deg, float yaw_deg, float roll_deg);
52
53 // Cache the last (input, output) pair per child_frame_id so a static
54 // sensor doesn't pay the quaternion conversion on every tick. Public so
55 // the equality helper in the .cpp can pattern-match.
57 float tx;
58 float ty;
59 float tz;
60 float pitch;
61 float yaw;
62 float roll;
63 std::array<float, 3> translation;
64 std::array<float, 4> rotation;
65 };
66
67private:
68 std::shared_ptr<PublisherImpl<CarlaTransformMsgTraits>> _impl;
69 std::unordered_map<std::string, CachedTransform> _last_transforms;
70};
71
72} // namespace ros2
73} // namespace carla
std::unordered_map< std::string, CachedTransform > _last_transforms
CarlaTransformPublisher & operator=(const CarlaTransformPublisher &)=delete
std::shared_ptr< PublisherImpl< CarlaTransformMsgTraits > > _impl
bool Write(std::int32_t seconds, std::uint32_t nanoseconds, const std::string &parent_frame_id, const std::string &child_frame_id, float tx, float ty, float tz, float pitch_deg, float yaw_deg, float roll_deg)
CarlaTransformPublisher(const CarlaTransformPublisher &)=delete
CarlaTransformPublisher(CarlaTransformPublisher &&) noexcept=default
This file contains definitions of common data structures used in traffic manager.