CARLA
 
载入中...
搜索中...
未找到
LibCarla/source/carla/rpc/VehiclePhysicsControl.h
浏览该文件的文档.
1// Copyright (c) 2019 Computer Vision Center (CVC) at the Universitat Autonoma
2// de Barcelona (UAB).
3// Copyright (c) 2019 Intel Corporation
4//
5// This work is licensed under the terms of the MIT license.
6// For a copy, see <https://opensource.org/licenses/MIT>.
7
8#pragma once
9
10#include "carla/MsgPack.h"
11#include "carla/geom/Location.h"
12#include "carla/geom/Vector2D.h"
15
16#include <string>
17#include <vector>
18
19namespace carla {
20namespace rpc {
21// 用于控制车辆的物理属性
23 public:
24
26 // 带参数的构造函数,初始化所有车辆物理属性
28 const std::vector<carla::geom::Vector2D> &in_torque_curve,
29 float in_max_rpm,
30 float in_moi,
31 float in_damping_rate_full_throttle,
32 float in_damping_rate_zero_throttle_clutch_engaged,
33 float in_damping_rate_zero_throttle_clutch_disengaged,
34
35 bool in_use_gear_autobox,
36 float in_gear_switch_time,
37 float in_clutch_strength,
38 float in_final_ratio,
39 std::vector<GearPhysicsControl> &in_forward_gears,
40
41 float in_mass,
42 float in_drag_coefficient,
43 geom::Location in_center_of_mass,
44 const std::vector<carla::geom::Vector2D> &in_steering_curve,
45 std::vector<WheelPhysicsControl> &in_wheels,
46 bool in_use_sweep_wheel_collision)
47 : torque_curve(in_torque_curve),
48 max_rpm(in_max_rpm),
49 moi(in_moi),
50 damping_rate_full_throttle(in_damping_rate_full_throttle),
51 damping_rate_zero_throttle_clutch_engaged(in_damping_rate_zero_throttle_clutch_engaged),
52 damping_rate_zero_throttle_clutch_disengaged(in_damping_rate_zero_throttle_clutch_disengaged),
53 use_gear_autobox(in_use_gear_autobox),
54 gear_switch_time(in_gear_switch_time),
55 clutch_strength(in_clutch_strength),
56 final_ratio(in_final_ratio),
57 forward_gears(in_forward_gears),
58 mass(in_mass),
59 drag_coefficient(in_drag_coefficient),
60 center_of_mass(in_center_of_mass),
61 steering_curve(in_steering_curve),
62 wheels(in_wheels),
63 use_sweep_wheel_collision(in_use_sweep_wheel_collision) {}
64// 获取前进档位的控制参数
65 const std::vector<GearPhysicsControl> &GetForwardGears() const {
66 return forward_gears;
67 }
68// 设置前进档位的控制参数
69 void SetForwardGears(std::vector<GearPhysicsControl> &in_forward_gears) {
70 forward_gears = in_forward_gears;
71 }
72 // 获取车轮的物理控制参数
73 const std::vector<WheelPhysicsControl> &GetWheels() const {
74 return wheels;
75 }
76
77 void SetWheels(std::vector<WheelPhysicsControl> &in_wheels) {
78 wheels = in_wheels;
79 }
80// 获取扭矩曲线
81 const std::vector<geom::Vector2D> &GetTorqueCurve() const {
82 return torque_curve;
83 }
84 // 设置扭矩曲线
85 void SetTorqueCurve(std::vector<geom::Vector2D> &in_torque_curve) {
86 torque_curve = in_torque_curve;
87 }
88 // 获取转向曲线
89 const std::vector<geom::Vector2D> &GetSteeringCurve() const {
90 return steering_curve;
91 }
92// 设置转向曲线
93 void SetSteeringCurve(std::vector<geom::Vector2D> &in_steering_curve) {
94 steering_curve = in_steering_curve;
95 }
96// 设置是否使用车轮碰撞检测
97 void SetUseSweepWheelCollision(bool in_sweep) {
99 }
100 // 获取是否使用车轮碰撞检测
104 // 默认的扭矩曲线,表示转速与扭矩的关系
105 std::vector<geom::Vector2D> torque_curve = {geom::Vector2D(0.0f, 500.0f), geom::Vector2D(5000.0f, 500.0f)};// 最大转速
106 float max_rpm = 5000.0f; // 动能矩
107 float moi = 1.0f; // 全油门时的阻尼系数
108 float damping_rate_full_throttle = 0.15f; // 零油门且离合器接合时的阻尼系数
109 float damping_rate_zero_throttle_clutch_engaged = 2.0f;// 零油门且离合器分离时的阻尼系数
111// 是否使用自动变速箱
112 bool use_gear_autobox = true; // 换挡时间
113 float gear_switch_time = 0.5f; // 离合器
114 float clutch_strength = 10.0f; // 最终传动比
115 float final_ratio = 4.0f; // 前进档位的控制参数
116 std::vector<GearPhysicsControl> forward_gears;
117
118 float mass = 1000.0f;
119 float drag_coefficient = 0.3f;
121 // 转向曲线,表示转速与转向角度的关系
122 std::vector<geom::Vector2D> steering_curve = {geom::Vector2D(0.0f, 1.0f), geom::Vector2D(10.0f, 0.5f)};// 车轮物理控制
123 std::vector<WheelPhysicsControl> wheels;
124 // 是否使用车轮碰撞检测
126 // 重载不等号运算符,比较两个VehiclePhysicsControl对象是否不同
127 bool operator!=(const VehiclePhysicsControl &rhs) const {
128 return
129 max_rpm != rhs.max_rpm || // 比较最大转速
130 moi != rhs.moi || // 比较转动惯量
131
132 damping_rate_full_throttle ! =rhs.damping_rate_full_throttle || // 比较全油门下的阻尼率
135//比较不同油门下的阻尼率
136 use_gear_autobox != rhs.use_gear_autobox || // 比较是否使用自动变速箱
137 gear_switch_time != rhs.gear_switch_time || // 比较换挡时间
138 clutch_strength != rhs.clutch_strength || // 比较离合器强度
139 final_ratio != rhs.final_ratio || // 比较最终传动比
140 forward_gears != rhs.forward_gears || // 比较前进挡列表
141
142 mass != rhs.mass || // 比较车辆质量
143 drag_coefficient != rhs.drag_coefficient || // 比较空气阻力系数
144 steering_curve != rhs.steering_curve || // 比较转向曲线
145 center_of_mass != rhs.center_of_mass || // 比较质心位置
146 wheels != rhs.wheels || // 比较车轮列表
147 use_sweep_wheel_collision != rhs.use_sweep_wheel_collision; // 比较是否使用车轮扫掠碰撞
148 }
149
150 bool operator==(const VehiclePhysicsControl &rhs) const {
151 return !(*this != rhs);
152 }
153
154#ifdef LIBCARLA_INCLUDED_FROM_UE4
155// 构造函数:将一个 FVehiclePhysicsControl 对象转换为 VehiclePhysicsControl 对象
157// 初始化引擎设置
158 // Engine Setup
159 torque_curve = std::vector<carla::geom::Vector2D>();
160 TArray<FRichCurveKey> TorqueCurveKeys = Control.TorqueCurve.GetCopyOfKeys();
161 for (int32 KeyIdx = 0; KeyIdx < TorqueCurveKeys.Num(); KeyIdx++) {
162 geom::Vector2D point(TorqueCurveKeys[KeyIdx].Time, TorqueCurveKeys[KeyIdx].Value);
163 torque_curve.push_back(point);
164 }
165 max_rpm = Control.MaxRPM;
166 moi = Control.MOI;
167 damping_rate_full_throttle = Control.DampingRateFullThrottle;
168 damping_rate_zero_throttle_clutch_engaged = Control.DampingRateZeroThrottleClutchEngaged;
169 damping_rate_zero_throttle_clutch_disengaged = Control.DampingRateZeroThrottleClutchDisengaged;
170
171 // Transmission Setup
172 use_gear_autobox = Control.bUseGearAutoBox;
173 gear_switch_time = Control.GearSwitchTime;
174 clutch_strength = Control.ClutchStrength;
175 final_ratio = Control.FinalRatio;
176 forward_gears = std::vector<GearPhysicsControl>();
177 for (const auto &Gear : Control.ForwardGears) {
178 forward_gears.push_back(GearPhysicsControl(Gear));
179 }
180
181 // Vehicle Setup
182 mass = Control.Mass;
183 drag_coefficient = Control.DragCoefficient;
184
185 steering_curve = std::vector<carla::geom::Vector2D>();
186 TArray<FRichCurveKey> SteeringCurveKeys = Control.SteeringCurve.GetCopyOfKeys();
187 for (int32 KeyIdx = 0; KeyIdx < SteeringCurveKeys.Num(); KeyIdx++) {
188 geom::Vector2D point(SteeringCurveKeys[KeyIdx].Time, SteeringCurveKeys[KeyIdx].Value);
189 steering_curve.push_back(point);
190 }
191
192 center_of_mass = Control.CenterOfMass;
193
194 // Wheels Setup
195 wheels = std::vector<WheelPhysicsControl>();
196 for (const auto &Wheel : Control.Wheels) {
197 wheels.push_back(WheelPhysicsControl(Wheel));
198 }
199
200 use_sweep_wheel_collision = Control.UseSweepWheelCollision;
201 }
202
203 operator FVehiclePhysicsControl() const {
205
206 // Engine Setup
207 FRichCurve TorqueCurve;
208 for (const auto &point : torque_curve) {
209 TorqueCurve.AddKey(point.x, point.y);
210 }
211 Control.TorqueCurve = TorqueCurve;
212 Control.MaxRPM = max_rpm;
213 Control.MOI = moi;
214 Control.DampingRateFullThrottle = damping_rate_full_throttle;
215 Control.DampingRateZeroThrottleClutchEngaged = damping_rate_zero_throttle_clutch_engaged;
216 Control.DampingRateZeroThrottleClutchDisengaged = damping_rate_zero_throttle_clutch_disengaged;
217
218 // Transmission Setup
219 Control.bUseGearAutoBox = use_gear_autobox;
220 Control.GearSwitchTime = gear_switch_time;
221 Control.ClutchStrength = clutch_strength;
222 Control.FinalRatio = final_ratio;
223 TArray<FGearPhysicsControl> ForwardGears;
224 for (const auto &gear : forward_gears) {
225 ForwardGears.Add(FGearPhysicsControl(gear));
226 }
227 Control.ForwardGears = ForwardGears;
228
229
230 // Vehicle Setup
231 Control.Mass = mass;
232 Control.DragCoefficient = drag_coefficient;
233
234 // Transmission Setup
235 FRichCurve SteeringCurve;
236 for (const auto &point : steering_curve) {
237 SteeringCurve.AddKey(point.x, point.y);
238 }
239 Control.SteeringCurve = SteeringCurve;
240
241 Control.CenterOfMass = center_of_mass;
242
243 // Wheels Setup
244 TArray<FWheelPhysicsControl> Wheels;
245 for (const auto &wheel : wheels) {
246 Wheels.Add(FWheelPhysicsControl(wheel));
247 }
248 Control.Wheels = Wheels;
249
250 Control.UseSweepWheelCollision = use_sweep_wheel_collision;
251
252 return Control;
253 }
254
255#endif
256
258 max_rpm,
259 moi,
268 mass,
272 wheels,
274 };
275
276} // namespace rpc
277} // namespace carla
FVehicleControl Control
Definition ActorData.h:119
定义两个嵌套的命名空间:carla和geom。
bool operator==(const VehiclePhysicsControl &rhs) const
MSGPACK_DEFINE_ARRAY(torque_curve, max_rpm, moi, damping_rate_full_throttle, damping_rate_zero_throttle_clutch_engaged, damping_rate_zero_throttle_clutch_disengaged, use_gear_autobox, gear_switch_time, clutch_strength, final_ratio, forward_gears, mass, drag_coefficient, center_of_mass, steering_curve, wheels, use_sweep_wheel_collision)
const std::vector< geom::Vector2D > & GetSteeringCurve() const
void SetTorqueCurve(std::vector< geom::Vector2D > &in_torque_curve)
const std::vector< WheelPhysicsControl > & GetWheels() const
bool operator!=(const VehiclePhysicsControl &rhs) const
VehiclePhysicsControl(const std::vector< carla::geom::Vector2D > &in_torque_curve, float in_max_rpm, float in_moi, float in_damping_rate_full_throttle, float in_damping_rate_zero_throttle_clutch_engaged, float in_damping_rate_zero_throttle_clutch_disengaged, bool in_use_gear_autobox, float in_gear_switch_time, float in_clutch_strength, float in_final_ratio, std::vector< GearPhysicsControl > &in_forward_gears, float in_mass, float in_drag_coefficient, geom::Location in_center_of_mass, const std::vector< carla::geom::Vector2D > &in_steering_curve, std::vector< WheelPhysicsControl > &in_wheels, bool in_use_sweep_wheel_collision)
void SetSteeringCurve(std::vector< geom::Vector2D > &in_steering_curve)
const std::vector< GearPhysicsControl > & GetForwardGears() const
const std::vector< geom::Vector2D > & GetTorqueCurve() const
void SetForwardGears(std::vector< GearPhysicsControl > &in_forward_gears)
void SetWheels(std::vector< WheelPhysicsControl > &in_wheels)
CARLA模拟器的主命名空间。
Definition Carla.cpp:139