CARLA
LibCarla/source/carla/rpc/VehiclePhysicsControl.h
Go to the documentation of this file.
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 
19 namespace carla {
20 namespace rpc {
22  public:
23 
24  VehiclePhysicsControl() = default;
25 
27  const std::vector<carla::geom::Vector2D> &in_torque_curve,
28  float in_max_rpm,
29  float in_moi,
30  float in_damping_rate_full_throttle,
31  float in_damping_rate_zero_throttle_clutch_engaged,
32  float in_damping_rate_zero_throttle_clutch_disengaged,
33 
34  bool in_use_gear_autobox,
35  float in_gear_switch_time,
36  float in_clutch_strength,
37  float in_final_ratio,
38  std::vector<GearPhysicsControl> &in_forward_gears,
39 
40  float in_mass,
41  float in_drag_coefficient,
42  geom::Location in_center_of_mass,
43  const std::vector<carla::geom::Vector2D> &in_steering_curve,
44  std::vector<WheelPhysicsControl> &in_wheels,
45  bool in_use_sweep_wheel_collision)
46  : torque_curve(in_torque_curve),
47  max_rpm(in_max_rpm),
48  moi(in_moi),
49  damping_rate_full_throttle(in_damping_rate_full_throttle),
50  damping_rate_zero_throttle_clutch_engaged(in_damping_rate_zero_throttle_clutch_engaged),
51  damping_rate_zero_throttle_clutch_disengaged(in_damping_rate_zero_throttle_clutch_disengaged),
52  use_gear_autobox(in_use_gear_autobox),
53  gear_switch_time(in_gear_switch_time),
54  clutch_strength(in_clutch_strength),
55  final_ratio(in_final_ratio),
56  forward_gears(in_forward_gears),
57  mass(in_mass),
58  drag_coefficient(in_drag_coefficient),
59  center_of_mass(in_center_of_mass),
60  steering_curve(in_steering_curve),
61  wheels(in_wheels),
62  use_sweep_wheel_collision(in_use_sweep_wheel_collision) {}
63 
64  const std::vector<GearPhysicsControl> &GetForwardGears() const {
65  return forward_gears;
66  }
67 
68  void SetForwardGears(std::vector<GearPhysicsControl> &in_forward_gears) {
69  forward_gears = in_forward_gears;
70  }
71 
72  const std::vector<WheelPhysicsControl> &GetWheels() const {
73  return wheels;
74  }
75 
76  void SetWheels(std::vector<WheelPhysicsControl> &in_wheels) {
77  wheels = in_wheels;
78  }
79 
80  const std::vector<geom::Vector2D> &GetTorqueCurve() const {
81  return torque_curve;
82  }
83 
84  void SetTorqueCurve(std::vector<geom::Vector2D> &in_torque_curve) {
85  torque_curve = in_torque_curve;
86  }
87 
88  const std::vector<geom::Vector2D> &GetSteeringCurve() const {
89  return steering_curve;
90  }
91 
92  void SetSteeringCurve(std::vector<geom::Vector2D> &in_steering_curve) {
93  steering_curve = in_steering_curve;
94  }
95 
96  void SetUseSweepWheelCollision(bool in_sweep) {
97  use_sweep_wheel_collision = in_sweep;
98  }
99 
102  }
103 
104  std::vector<geom::Vector2D> torque_curve = {geom::Vector2D(0.0f, 500.0f), geom::Vector2D(5000.0f, 500.0f)};
105  float max_rpm = 5000.0f;
106  float moi = 1.0f;
110 
111  bool use_gear_autobox = true;
112  float gear_switch_time = 0.5f;
113  float clutch_strength = 10.0f;
114  float final_ratio = 4.0f;
115  std::vector<GearPhysicsControl> forward_gears;
116 
117  float mass = 1000.0f;
118  float drag_coefficient = 0.3f;
120 
121  std::vector<geom::Vector2D> steering_curve = {geom::Vector2D(0.0f, 1.0f), geom::Vector2D(10.0f, 0.5f)};
122  std::vector<WheelPhysicsControl> wheels;
123 
125 
126  bool operator!=(const VehiclePhysicsControl &rhs) const {
127  return
128  max_rpm != rhs.max_rpm ||
129  moi != rhs.moi ||
130  damping_rate_full_throttle != rhs.damping_rate_full_throttle ||
131  damping_rate_zero_throttle_clutch_engaged != rhs.damping_rate_zero_throttle_clutch_engaged ||
132  damping_rate_zero_throttle_clutch_disengaged != rhs.damping_rate_zero_throttle_clutch_disengaged ||
133 
134  use_gear_autobox != rhs.use_gear_autobox ||
135  gear_switch_time != rhs.gear_switch_time ||
136  clutch_strength != rhs.clutch_strength ||
137  final_ratio != rhs.final_ratio ||
138  forward_gears != rhs.forward_gears ||
139 
140  mass != rhs.mass ||
141  drag_coefficient != rhs.drag_coefficient ||
142  steering_curve != rhs.steering_curve ||
143  center_of_mass != rhs.center_of_mass ||
144  wheels != rhs.wheels ||
145  use_sweep_wheel_collision != rhs.use_sweep_wheel_collision;
146  }
147 
148  bool operator==(const VehiclePhysicsControl &rhs) const {
149  return !(*this != rhs);
150  }
151 
152 #ifdef LIBCARLA_INCLUDED_FROM_UE4
153 
155  // Engine Setup
156  torque_curve = std::vector<carla::geom::Vector2D>();
157  TArray<FRichCurveKey> TorqueCurveKeys = Control.TorqueCurve.GetCopyOfKeys();
158  for (int32 KeyIdx = 0; KeyIdx < TorqueCurveKeys.Num(); KeyIdx++) {
159  geom::Vector2D point(TorqueCurveKeys[KeyIdx].Time, TorqueCurveKeys[KeyIdx].Value);
160  torque_curve.push_back(point);
161  }
162  max_rpm = Control.MaxRPM;
163  moi = Control.MOI;
164  damping_rate_full_throttle = Control.DampingRateFullThrottle;
165  damping_rate_zero_throttle_clutch_engaged = Control.DampingRateZeroThrottleClutchEngaged;
166  damping_rate_zero_throttle_clutch_disengaged = Control.DampingRateZeroThrottleClutchDisengaged;
167 
168  // Transmission Setup
169  use_gear_autobox = Control.bUseGearAutoBox;
170  gear_switch_time = Control.GearSwitchTime;
171  clutch_strength = Control.ClutchStrength;
172  final_ratio = Control.FinalRatio;
173  forward_gears = std::vector<GearPhysicsControl>();
174  for (const auto &Gear : Control.ForwardGears) {
175  forward_gears.push_back(GearPhysicsControl(Gear));
176  }
177 
178  // Vehicle Setup
179  mass = Control.Mass;
180  drag_coefficient = Control.DragCoefficient;
181 
182  steering_curve = std::vector<carla::geom::Vector2D>();
183  TArray<FRichCurveKey> SteeringCurveKeys = Control.SteeringCurve.GetCopyOfKeys();
184  for (int32 KeyIdx = 0; KeyIdx < SteeringCurveKeys.Num(); KeyIdx++) {
185  geom::Vector2D point(SteeringCurveKeys[KeyIdx].Time, SteeringCurveKeys[KeyIdx].Value);
186  steering_curve.push_back(point);
187  }
188 
189  center_of_mass = Control.CenterOfMass;
190 
191  // Wheels Setup
192  wheels = std::vector<WheelPhysicsControl>();
193  for (const auto &Wheel : Control.Wheels) {
194  wheels.push_back(WheelPhysicsControl(Wheel));
195  }
196 
197  use_sweep_wheel_collision = Control.UseSweepWheelCollision;
198  }
199 
200  operator FVehiclePhysicsControl() const {
201  FVehiclePhysicsControl Control;
202 
203  // Engine Setup
204  FRichCurve TorqueCurve;
205  for (const auto &point : torque_curve) {
206  TorqueCurve.AddKey(point.x, point.y);
207  }
208  Control.TorqueCurve = TorqueCurve;
209  Control.MaxRPM = max_rpm;
210  Control.MOI = moi;
214 
215  // Transmission Setup
219  Control.FinalRatio = final_ratio;
220  TArray<FGearPhysicsControl> ForwardGears;
221  for (const auto &gear : forward_gears) {
222  ForwardGears.Add(FGearPhysicsControl(gear));
223  }
224  Control.ForwardGears = ForwardGears;
225 
226 
227  // Vehicle Setup
228  Control.Mass = mass;
230 
231  // Transmission Setup
232  FRichCurve SteeringCurve;
233  for (const auto &point : steering_curve) {
234  SteeringCurve.AddKey(point.x, point.y);
235  }
236  Control.SteeringCurve = SteeringCurve;
237 
238  Control.CenterOfMass = center_of_mass;
239 
240  // Wheels Setup
241  TArray<FWheelPhysicsControl> Wheels;
242  for (const auto &wheel : wheels) {
243  Wheels.Add(FWheelPhysicsControl(wheel));
244  }
245  Control.Wheels = Wheels;
246 
248 
249  return Control;
250  }
251 
252 #endif
253 
254  MSGPACK_DEFINE_ARRAY(torque_curve,
255  max_rpm,
256  moi,
257  damping_rate_full_throttle,
258  damping_rate_zero_throttle_clutch_engaged,
259  damping_rate_zero_throttle_clutch_disengaged,
260  use_gear_autobox,
261  gear_switch_time,
262  clutch_strength,
263  final_ratio,
264  forward_gears,
265  mass,
266  drag_coefficient,
267  center_of_mass,
268  steering_curve,
269  wheels,
270  use_sweep_wheel_collision);
271  };
272 
273 } // namespace rpc
274 } // namespace carla
void SetSteeringCurve(std::vector< geom::Vector2D > &in_steering_curve)
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)
bool operator!=(const VehiclePhysicsControl &rhs) const
This file contains definitions of common data structures used in traffic manager. ...
Definition: Carla.cpp:133
void SetTorqueCurve(std::vector< geom::Vector2D > &in_torque_curve)
const std::vector< WheelPhysicsControl > & GetWheels() const
const std::vector< GearPhysicsControl > & GetForwardGears() const
void SetWheels(std::vector< WheelPhysicsControl > &in_wheels)
const std::vector< geom::Vector2D > & GetSteeringCurve() const
const std::vector< geom::Vector2D > & GetTorqueCurve() const
geom::Vector2D Vector2D
Definition: rpc/Vector2D.h:14
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)
bool operator==(const VehiclePhysicsControl &rhs) const
void SetForwardGears(std::vector< GearPhysicsControl > &in_forward_gears)