CARLA
 
载入中...
搜索中...
未找到
LibCarla/source/carla/rpc/VehicleControl.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#include "carla/MsgPack.h" // 引入 MsgPack 库头文件,用于序列化
9
10#ifdef LIBCARLA_INCLUDED_FROM_UE4 //
12#include "Carla/Vehicle/VehicleControl.h" // 引入与车辆控制相关的头文件
14#endif // LIBCARLA_INCLUDED_FROM_UE4 // 结束条件编译判断
15
16namespace carla { // carla 命名空间
17namespace rpc { // rpc 命名空间
18
19 // 定义一个车辆控制类 VehicleControl
21 public:
22
23 VehicleControl() = default; // 默认构造函数,使用默认成员初始化
24
25 // 带参数的构造函数,初始化所有成员变量
27 float in_throttle, // 油门
28 float in_steer, // 转向
29 float in_brake, // 刹车
30 bool in_hand_brake, // 手刹
31 bool in_reverse, // 倒车
32 bool in_manual_gear_shift, // 是否手动换挡
33 int32_t in_gear) // 当前挡位
34 : throttle(in_throttle), // 初始化油门
35 steer(in_steer), // 初始化转向
36 brake(in_brake), // 初始化刹车
37 hand_brake(in_hand_brake), // 初始化手刹
38 reverse(in_reverse), // 初始化倒车
39 manual_gear_shift(in_manual_gear_shift), // 初始化手动换挡
40 gear(in_gear) {} // 初始化挡位
41
42 // 定义所有成员变量
43 float throttle = 0.0f; // 油门,默认值为 0.0
44 float steer = 0.0f; // 转向,默认值为 0.0
45 float brake = 0.0f; // 刹车,默认值为 0.0
46 bool hand_brake = false; // 手刹,默认值为 false
47 bool reverse = false; // 倒车,默认值为 false
48 bool manual_gear_shift = false; // 是否手动换挡,默认值为 false
49 int32_t gear = 0; // 当前挡位,默认值为 0
50
51#ifdef LIBCARLA_INCLUDED_FROM_UE4 // 如果是从 UE4 环境中包含此代码
52 // 从 FVehicleControl 转换为 VehicleControl 的构造函数
54 : throttle(Control.Throttle), // 初始化油门
55 steer(Control.Steer), // 初始化转向
56 brake(Control.Brake), // 初始化刹车
57 hand_brake(Control.bHandBrake), // 初始化手刹
58 reverse(Control.bReverse), // 初始化倒车
59 manual_gear_shift(Control.bManualGearShift), // 初始化手动换挡
60 gear(Control.Gear) {} // 初始化挡位
61
62 // 将 VehicleControl 转换为 FVehicleControl 的操作符
63 operator FVehicleControl() const {
64 FVehicleControl Control; // 创建一个 FVehicleControl 对象
65 Control.Throttle = throttle; // 设置油门
66 Control.Steer = steer; // 设置转向
67 Control.Brake = brake; // 设置刹车
68 Control.bHandBrake = hand_brake; // 设置手刹
69 Control.bReverse = reverse; // 设置倒车
70 Control.bManualGearShift = manual_gear_shift; // 设置手动换挡
71 Control.Gear = gear; // 设置挡位
72 return Control; // 返回转换后的 FVehicleControl 对象
73 }
74
75#endif // LIBCARLA_INCLUDED_FROM_UE4 // 结束 UE4 环境的条件编译
76
77 // 定义不等于操作符,用于比较两个 VehicleControl 对象是否不同
78 bool operator!=(const VehicleControl &rhs) const {
79 return
80 throttle != rhs.throttle || // 油门不相等
81 steer != rhs.steer || // 转向不相等
82 brake != rhs.brake || // 刹车不相等
83 hand_brake != rhs.hand_brake || // 手刹不相等
84 reverse != rhs.reverse || // 倒车不相等
85 manual_gear_shift != rhs.manual_gear_shift || // 是否手动换挡不相等
86 gear != rhs.gear; // 挡位不相等
87 }
88
89 // 定义等于操作符,用于比较两个 VehicleControl 对象是否相等
90 bool operator==(const VehicleControl &rhs) const {
91 return !(*this != rhs); // 如果不等于返回 false,则相等
92 }
93
94 // 定义序列化方式,使用 MsgPack 库
96 throttle, // 序列化油门
97 steer, // 序列化转向
98 brake, // 序列化刹车
99 hand_brake, // 序列化手刹
100 reverse, // 序列化倒车
101 manual_gear_shift, // 序列化手动换挡
102 gear); // 序列化挡位
103 };
104
105} // namespace rpc // 结束 rpc 命名空间
106} // namespace carla // 结束 carla 命名空间
FVehicleControl Control
Definition ActorData.h:119
bool operator!=(const VehicleControl &rhs) const
MSGPACK_DEFINE_ARRAY(throttle, steer, brake, hand_brake, reverse, manual_gear_shift, gear)
bool operator==(const VehicleControl &rhs) const
VehicleControl(float in_throttle, float in_steer, float in_brake, bool in_hand_brake, bool in_reverse, bool in_manual_gear_shift, int32_t in_gear)
CARLA模拟器的主命名空间。
Definition Carla.cpp:139