CARLA
Toggle main menu visibility
Loading...
Searching...
No Matches
LibCarla
source
carla
ros2
publishers
ImuMath.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
9
#include <array>
10
#include <cmath>
11
12
namespace
carla
{
13
namespace
ros2
{
14
15
// Returns a yaw-only quaternion (w, x, y, z) corresponding to converting a
16
// magnetic compass heading (radians, clockwise from North) into ROS REP-103
17
// yaw (radians, counter-clockwise from East): yaw = pi/2 - compass.
18
//
19
// M_PI is used here, not std::numbers::pi_v, because this header is consumed
20
// by the carla-ros2-native ExternalProject in Ros2Native/, which does not
21
// configure CMAKE_CXX_STANDARD and therefore defaults to C++17 where
22
// <numbers> is unavailable.
23
inline
std::array<float, 4>
OrientationFromCompass
(
float
compass) {
24
const
float
yaw =
static_cast<
float
>
(M_PI) / 2.0f - compass;
25
const
float
c = std::cos(yaw * 0.5f);
26
const
float
s = std::sin(yaw * 0.5f);
27
return
{c, 0.0f, 0.0f, s};
28
}
29
30
// Converts a linear acceleration sampled in CARLA's left-handed sensor frame
31
// (x forward, y right, z up) into the ROS REP-103 right-handed sensor frame
32
// (x forward, y left, z up). Ordinary (polar) vectors only need the y axis
33
// mirrored — the same y-negation our TF, lidar and odometry publishers apply.
34
inline
std::array<float, 3>
AccelToRos
(
float
ax,
float
ay,
float
az) {
35
return
{ax, -ay, az};
36
}
37
38
// Converts an angular velocity sampled in CARLA's left-handed sensor frame
39
// into the REP-103 right-handed sensor frame.
40
//
41
// Angular velocity is a pseudovector, so mirroring the y axis flips the sign
42
// of the components PARALLEL to the mirror plane (x and z), not the mirrored
43
// one. Concretely, with UE's component cross product v = w x r evaluated in
44
// left-handed coordinates:
45
// - turning left (CCW from above) -> UE wz < 0, ROS wz > 0 => negate z
46
// - rolling right (right side down) -> UE wx < 0, ROS wx > 0 => negate x
47
// - pitching nose-down -> UE wy > 0, ROS wy > 0 => keep y
48
// This matches the carla-ros-bridge ImuSensor conversion (-x, +y, -z). Note
49
// tier4's autoware-support layer negated (y, z) instead, which mis-handles
50
// the pseudovector reflection; we deliberately diverge.
51
inline
std::array<float, 3>
GyroToRos
(
float
gx,
float
gy,
float
gz) {
52
return
{-gx, gy, -gz};
53
}
54
55
}
// namespace ros2
56
}
// namespace carla
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
Generated by
1.18.0