CARLA
Loading...
Searching...
No Matches
VehicleStatusSerializer.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 "carla/Buffer.h"
10#include "carla/Memory.h"
11#include "carla/MsgPack.h"
13
14#include <cstdint>
15#include <cstring>
16#include <stdexcept>
17
18namespace carla {
19namespace sensor {
20
21 class SensorData;
22
23namespace s11n {
24
25#pragma pack(push, 1)
26 /// Snapshot of a vehicle's kinematic + control state, streamed each tick by
27 /// the Autoware VehicleStatusSensor (UE side, next phase) and decoded by
28 /// ROS2::ProcessDataFromStatusSensor into the six /vehicle/status/* report
29 /// publishers. Ported from tier4/autoware-support.
30 ///
31 /// Bit masks:
32 /// control_flags: b0 = reverse, b1 = manual gear shift
33 /// turn_mask: b0 = left blinker, b1 = right blinker, b2 = hazards
35 double timestamp;
36 float speed_mps;
37 float vel_x_mps, vel_y_mps, vel_z_mps; // local
39 float rot_pitch, rot_yaw, rot_roll; // relative
40 float steer;
41 int32_t gear;
42 uint8_t turn_mask;
44
45 MSGPACK_DEFINE_ARRAY(timestamp,
50 steer,
51 gear,
54 };
55#pragma pack(pop)
56
58 public:
59
60 constexpr static auto header_offset = 0u;
61
63 return MsgPack::UnPack<VehicleStatusData>(message.begin(), message.size());
64 }
65
66 /// Direct field-wise serialization (server side).
67 template <typename SensorT>
69 const SensorT &,
70 double timestamp,
71 float speed_mps,
72 float vel_x_mps,
73 float vel_y_mps,
74 float vel_z_mps,
75 float angVel_x_mps,
76 float angVel_y_mps,
77 float angVel_z_mps,
78 float rot_pitch,
79 float rot_yaw,
80 float rot_roll,
81 float steer,
82 int32_t gear,
83 uint8_t turn_mask,
84 uint8_t control_flags) {
86 timestamp,
87 speed_mps,
88 vel_x_mps, vel_y_mps, vel_z_mps,
89 angVel_x_mps, angVel_y_mps, angVel_z_mps,
90 rot_pitch, rot_yaw, rot_roll,
91 steer,
92 gear,
93 turn_mask,
94 control_flags});
95 }
96
97 /// Overload for the Unreal sensor streaming a packed struct. The UE-side
98 /// packed layout carries two trailing pad bytes (4-byte struct alignment);
99 /// everything before them matches VehicleStatusData byte-for-byte.
100 template <typename SensorT>
101 static Buffer Serialize(const SensorT &, const Buffer &buffer) {
102 constexpr size_t packed_size = sizeof(VehicleStatusData) + 2u; // + _pad0/_pad1
103 if (buffer.size() != packed_size && buffer.size() != sizeof(VehicleStatusData)) {
104 throw std::runtime_error("Invalid buffer size for VehicleStatusSensor");
105 }
107 std::memcpy(&msg, buffer.data(), sizeof(VehicleStatusData));
108 return MsgPack::Pack(msg);
109 }
110
112 };
113
114} // namespace s11n
115} // namespace sensor
116} // namespace carla
A piece of raw data.
const value_type * data() const noexcept
Direct access to the allocated memory or nullptr if no memory is allocated.
size_type size() const noexcept
static Buffer Pack(const T &obj)
Definition MsgPack.h:19
Wrapper around the raw data generated by a sensor plus some useful meta-information.
Definition RawData.h:21
auto begin() noexcept
Begin iterator to the data generated by the sensor.
Definition RawData.h:52
size_t size() const
Size in bytes of the data generated by the sensor.
Definition RawData.h:83
static VehicleStatusData DeserializeRawData(const RawData &message)
static SharedPtr< SensorData > Deserialize(RawData &&data)
static Buffer Serialize(const SensorT &, const Buffer &buffer)
Overload for the Unreal sensor streaming a packed struct.
static Buffer Serialize(const SensorT &, double timestamp, float speed_mps, float vel_x_mps, float vel_y_mps, float vel_z_mps, float angVel_x_mps, float angVel_y_mps, float angVel_z_mps, float rot_pitch, float rot_yaw, float rot_roll, float steer, int32_t gear, uint8_t turn_mask, uint8_t control_flags)
Direct field-wise serialization (server side).
This file contains definitions of common data structures used in traffic manager.
std::shared_ptr< T > SharedPtr
Definition Memory.h:15
Snapshot of a vehicle's kinematic + control state, streamed each tick by the Autoware VehicleStatusSe...