CARLA
Toggle main menu visibility
Loading...
Searching...
No Matches
LibCarla
source
carla
ros2
publishers
CarlaIMUPublisher.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/CarlaIMUPublisher.h
"
8
9
#include "
carla/Logging.h
"
10
#include "
carla/ros2/publishers/ImuMath.h
"
11
#include "
carla/ros2/publishers/PublisherImpl.h
"
12
#include "
carla/ros2/types/msg/Imu.h
"
13
14
namespace
carla
{
15
namespace
ros2
{
16
17
struct
CarlaImuMsgTraits
{
18
using
msg_type
=
msg::Imu
;
19
};
20
21
CarlaIMUPublisher::CarlaIMUPublisher
(
22
std::string base_topic_name, std::string frame_id)
23
:
BasePublisher
(
std
::move(base_topic_name),
std
::move(frame_id)),
24
_impl
(
std
::make_shared<
PublisherImpl
<
CarlaImuMsgTraits
>>()) {
25
if
(!
_impl
->Init(
GetBaseTopicName
())) {
26
log_error(
"CarlaIMUPublisher: failed to initialise writer for"
,
GetBaseTopicName
());
27
}
28
}
29
30
CarlaIMUPublisher::~CarlaIMUPublisher
() =
default
;
31
32
bool
CarlaIMUPublisher::Publish
() {
33
return
_impl
->Publish();
34
}
35
36
bool
CarlaIMUPublisher::Write
(
37
std::int32_t seconds,
38
std::uint32_t nanoseconds,
39
float
accel_x,
float
accel_y,
float
accel_z,
40
float
gyro_x,
float
gyro_y,
float
gyro_z,
41
float
compass) {
42
auto
*message =
_impl
->GetMessage();
43
message->header.stamp.sec = seconds;
44
message->header.stamp.nanosec = nanoseconds;
45
message->header.frame_id =
GetFrameId
();
46
47
// Input samples arrive in CARLA's left-handed sensor frame; convert to the
48
// REP-103 right-handed frame before publishing (see ImuMath.h for the
49
// pseudovector rationale on the gyro axes).
50
const
auto
accel =
AccelToRos
(accel_x, accel_y, accel_z);
51
message->linear_acceleration.x = accel[0];
52
message->linear_acceleration.y = accel[1];
53
message->linear_acceleration.z = accel[2];
54
55
const
auto
gyro =
GyroToRos
(gyro_x, gyro_y, gyro_z);
56
message->angular_velocity.x = gyro[0];
57
message->angular_velocity.y = gyro[1];
58
message->angular_velocity.z = gyro[2];
59
60
// Yaw-only quaternion from compass heading; math lives in ImuMath.h.
61
const
auto
q =
OrientationFromCompass
(compass);
62
message->orientation.w = q[0];
63
message->orientation.x = q[1];
64
message->orientation.y = q[2];
65
message->orientation.z = q[3];
66
67
return
true
;
68
}
69
70
}
// namespace ros2
71
}
// namespace carla
CarlaIMUPublisher.h
ImuMath.h
Imu.h
Logging.h
PublisherImpl.h
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::CarlaIMUPublisher::Publish
bool Publish() override
Definition
CarlaIMUPublisher.cpp:32
carla::ros2::CarlaIMUPublisher::_impl
std::shared_ptr< PublisherImpl< CarlaImuMsgTraits > > _impl
Definition
CarlaIMUPublisher.h:46
carla::ros2::CarlaIMUPublisher::~CarlaIMUPublisher
~CarlaIMUPublisher() override
carla::ros2::CarlaIMUPublisher::Write
bool Write(std::int32_t seconds, std::uint32_t nanoseconds, float accel_x, float accel_y, float accel_z, float gyro_x, float gyro_y, float gyro_z, float compass)
Definition
CarlaIMUPublisher.cpp:36
carla::ros2::CarlaIMUPublisher::CarlaIMUPublisher
CarlaIMUPublisher(std::string base_topic_name, std::string frame_id)
Definition
CarlaIMUPublisher.cpp:21
carla::ros2::PublisherImpl
Definition
PublisherImpl.h:28
carla::ros2
Definition
AutowareSteeringCompensation.h:15
carla::ros2::AccelToRos
std::array< float, 3 > AccelToRos(float ax, float ay, float az)
Definition
ImuMath.h:34
carla::ros2::GyroToRos
std::array< float, 3 > GyroToRos(float gx, float gy, float gz)
Definition
ImuMath.h:51
carla::ros2::OrientationFromCompass
std::array< float, 4 > OrientationFromCompass(float compass)
Definition
ImuMath.h:23
carla
This file contains definitions of common data structures used in traffic manager.
Definition
SignComponent.h:21
std
Definition
CarlaRecorderCollision.h:31
carla::ros2::CarlaImuMsgTraits
Definition
CarlaIMUPublisher.cpp:17
carla::ros2::CarlaImuMsgTraits::msg_type
msg::Imu msg_type
Definition
CarlaIMUPublisher.cpp:18
carla::ros2::msg::Imu
Definition
Imu.h:15
Generated by
1.18.0