CARLA
 
载入中...
搜索中...
未找到
ActorDynamicState.h
浏览该文件的文档.
1// Copyright (c) 2017 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#include "carla/geom/Vector3D.h"
11#include "carla/rpc/ActorId.h"
17
18#include <cstdint>
19
20namespace carla { // 定义命名空间 carla
21namespace sensor { // 定义命名空间 sensor
22namespace data { // 定义命名空间 data
23
24namespace detail { // 定义命名空间 detail
25
26#pragma pack(push, 1) // 开始 1 字节对齐
27 class PackedVehicleControl { // 定义 PackedVehicleControl 类
28 public:
29
30 PackedVehicleControl() = default; // 默认构造函数
31
32 PackedVehicleControl(const rpc::VehicleControl &control) // 带参数的构造函数
33 : throttle(control.throttle), // 初始化油门
34 steer(control.steer), // 初始化转向
35 brake(control.brake), // 初始化刹车
36 hand_brake(control.hand_brake), // 初始化手刹
37 reverse(control.reverse), // 初始化倒车
38 manual_gear_shift(control.manual_gear_shift), // 初始化手动换档
39 gear(control.gear) {} // 初始化档位
40
41 operator rpc::VehicleControl() const { // 转换操作符,将其转换为 rpc::VehicleControl
42 return {throttle, steer, brake, hand_brake, reverse, manual_gear_shift, gear}; // 返回对应的 rpc::VehicleControl 对象
43 }
44
45 private:
46
47 float throttle; // 油门
48 float steer; // 转向
49 float brake; // 刹车
50 bool hand_brake; // 手刹
51 bool reverse; // 倒车
52 bool manual_gear_shift; // 手动换档
53 int32_t gear; // 档位
54 };
55
56#pragma pack(pop) // 恢复对齐方式
57
58#pragma pack(push, 1) // 开始 1 字节对齐
59 struct VehicleData { // 定义 VehicleData 结构体
60 VehicleData() = default; // 默认构造函数
61
63 float speed_limit; // 速度限制
65 bool has_traffic_light; // 是否有交通灯
68 };
69#pragma pack(pop) // 恢复对齐方式
70
71#pragma pack(push, 1) // 开始 1 字节对齐
72 class PackedWalkerControl { // 定义 PackedWalkerControl 类
73 public:
74
75 PackedWalkerControl() = default; // 默认构造函数
76
77 PackedWalkerControl(const rpc::WalkerControl &control) // 带参数的构造函数
78 : direction{control.direction.x, control.direction.y, control.direction.z}, // 初始化方向
79 speed(control.speed), // 初始化速度
80 jump(control.jump) {} // 初始化跳跃状态
81
82 operator rpc::WalkerControl() const { // 转换操作符,将其转换为 rpc::WalkerControl
83 return {geom::Vector3D{direction[0u], direction[1u], direction[2u]}, speed, jump}; // 返回对应的 rpc::WalkerControl 对象
84 }
85
86 private:
87
88 float direction[3u]; // 方向向量
89 float speed; // 速度
90 bool jump; // 跳跃状态
91 };
92
93#pragma pack(pop) // 恢复对齐方式
94
95#pragma pack(push, 1) // 开始 1 字节对齐
96 struct TrafficLightData { // 定义 TrafficLightData 结构体
97 TrafficLightData() = default; // 默认构造函数
98
99 char sign_id[32u]; // 标志 ID
100 float green_time; // 绿灯时间
101 float yellow_time; // 黄灯时间
102 float red_time; // 红灯时间
103 float elapsed_time; // 已经过的时间
104 uint32_t pole_index; // 标志杆索引
105 bool time_is_frozen; // 时间是否被冻结
106 rpc::TrafficLightState state; // 交通灯状态
107 };
108#pragma pack(pop) // 恢复对齐方式
109
110#pragma pack(push, 1) // 开始 1 字节对齐
111 struct TrafficSignData { // 定义 TrafficSignData 结构体
112 TrafficSignData() = default; // 默认构造函数
113
114 char sign_id[32u]; // 标志 ID
115 };
116#pragma pack(pop) // 恢复对齐方式
117} // namespace detail
118
119#pragma pack(push, 1) // 开始 1 字节对齐
120
121 /// 动态状态的参与者在某一帧的状态
123
124 ActorId id; // 参与者 ID
125
126 rpc::ActorState actor_state; // 参与者状态
127
128 geom::Transform transform; // 转换信息
129
131
133
135
136 union TypeDependentState { // 定义一个联合体,根据类型存储不同状态
141 } state; // 状态
142 };
143
144#pragma pack(pop) // 恢复对齐方式
145
146 static_assert(
147 sizeof(ParticipantDynamicState) == 119u, // 确保 ParticipantDynamicState 的大小为 119 字节
148 "Invalid ParticipantDynamicState size! "
149 "If you modified this class please update the size here, else you may "
150 "comment this assert, but your platform may have compatibility issues "
151 "connecting to other platforms."); // 如果大小不匹配,给出提示信息
152
153} // namespace data
154} // namespace sensor
155} // namespace carla
PackedVehicleControl(const rpc::VehicleControl &control)
PackedWalkerControl(const rpc::WalkerControl &control)
uint32_t ActorId
Definition ActorId.h:20
CARLA模拟器的主命名空间。
Definition Carla.cpp:139
rpc::ActorId ActorId
Definition ActorId.h:26
动态状态的参与者在某一帧的状态
union carla::sensor::data::ParticipantDynamicState::TypeDependentState state