CARLA
Loading...
Searching...
No Matches
LibCarla/source/carla/rpc/VehiclePhysicsControl.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// 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"
14
15#include <string>
16#include <vector>
17
18namespace carla {
19 namespace rpc {
21 {
22 // Engine Setup:
23 std::vector<geom::Vector2D> torque_curve = {
24 geom::Vector2D(0.0f, 500.0f),
25 geom::Vector2D(5000.0f, 500.0f)
26 };
27
28 float max_torque = 300.0f;
29 float max_rpm = 5000.0f;
30 float idle_rpm = 1.0f;
31 float brake_effect = 1.0f;
32 float rev_up_moi = 1.0f;
33 float rev_down_rate = 600.0f;
34
35 // ToDo: Convert to an enum, see EVehicleDifferential.
36 uint8_t differential_type = 0;
37 float front_rear_split = 0.5f;
38
40 float gear_change_time = 0.5f;
41 float final_ratio = 4.0f;
42 std::vector<float> forward_gear_ratios = { 2.85, 2.02, 1.35, 1.0, 2.85, 2.02, 1.35, 1.0 };
43 std::vector<float> reverse_gear_ratios = { 2.86, 2.86 };
44 float change_up_rpm = 4500.0f;
45 float change_down_rpm = 2000.0f;
47
48 float mass = 1000.0f;
49 float drag_coefficient = 0.3f;
51 float chassis_width = 180.f;
52 float chassis_height = 140.f;
54 float drag_area = 0.0f;
56 float sleep_threshold = 10.0f;
57 float sleep_slope_limit = 0.866f;
58
59 std::vector<geom::Vector2D> steering_curve = {
60 geom::Vector2D(0.0f, 1.0f),
61 geom::Vector2D(10.0f, 0.5f)
62 };
63 std::vector<WheelPhysicsControl> wheels;
64
66
106
107 inline bool operator!=(const VehiclePhysicsControl& rhs) const {
108 return !(*this == rhs);
109 }
110
111#ifdef LIBCARLA_INCLUDED_FROM_UE4
112
114 const FVehiclePhysicsControl& Control) {
115 VehiclePhysicsControl Out = { };
116 // torque_curve and steering_curve carry non-empty defaults (see the
117 // member initializers above); clear them or the real keys get
118 // appended after the default ones, producing an unsorted curve.
119 Out.torque_curve.clear();
120 Out.torque_curve.reserve(Control.TorqueCurve.GetNumKeys());
121 for (auto& Key : Control.TorqueCurve.GetConstRefOfKeys())
122 Out.torque_curve.push_back(geom::Vector2D(Key.Time, Key.Value));
123 Out.max_torque = Control.MaxTorque;
124 Out.max_rpm = Control.MaxRPM;
125 Out.idle_rpm = Control.IdleRPM;
126 Out.brake_effect = Control.BrakeEffect;
127 Out.rev_up_moi = Control.RevUpMOI;
128 Out.rev_down_rate = Control.RevDownRate;
130 Out.front_rear_split = Control.FrontRearSplit;
132 Out.gear_change_time = Control.GearChangeTime;
133 Out.final_ratio = Control.FinalRatio;
134 Out.forward_gear_ratios.resize(Control.ForwardGearRatios.Num());
135 for (size_t i = 0; i != Out.forward_gear_ratios.size(); ++i)
136 Out.forward_gear_ratios[i] = Control.ForwardGearRatios[i];
137 Out.reverse_gear_ratios.resize(Control.ReverseGearRatios.Num());
138 for (size_t i = 0; i != Out.reverse_gear_ratios.size(); ++i)
139 Out.reverse_gear_ratios[i] = Control.ReverseGearRatios[i];
140 Out.change_up_rpm = Control.ChangeUpRPM;
141 Out.change_down_rpm = Control.ChangeDownRPM;
143 Out.mass = Control.Mass;
144 Out.drag_coefficient = Control.DragCoefficient;
145 Out.center_of_mass = Control.CenterOfMass;
146 Out.chassis_width = Control.ChassisWidth;
147 Out.chassis_height = Control.ChassisHeight;
149 Out.drag_area = Control.DragArea;
151 Control.InertiaTensorScale.X,
152 Control.InertiaTensorScale.Y,
153 Control.InertiaTensorScale.Z);
154 Out.sleep_threshold = Control.SleepThreshold;
156 Out.steering_curve.clear();
157 Out.steering_curve.reserve(Control.SteeringCurve.GetNumKeys());
158 for (auto& Key : Control.SteeringCurve.GetConstRefOfKeys())
159 Out.steering_curve.push_back(geom::Vector2D(Key.Time, Key.Value));
160 Out.wheels.resize(Control.Wheels.Num());
161 for (size_t i = 0; i != Out.wheels.size(); ++i)
164 return Out;
165 }
166
167 operator FVehiclePhysicsControl() const {
168 FVehiclePhysicsControl Control = { };
169 for (auto [x, y] : torque_curve)
170 Control.TorqueCurve.AddKey(x, y);
171 Control.MaxTorque = max_torque;
172 Control.MaxRPM = max_rpm;
173 Control.IdleRPM = idle_rpm;
174 Control.BrakeEffect = brake_effect;
175 Control.RevUpMOI = rev_up_moi;
176 Control.RevDownRate = rev_down_rate;
181 Control.FinalRatio = final_ratio;
182 Control.ForwardGearRatios.SetNum(forward_gear_ratios.size());
183 for (size_t i = 0; i != Control.ForwardGearRatios.Num(); ++i)
185 Control.ReverseGearRatios.SetNum(reverse_gear_ratios.size());
186 for (size_t i = 0; i != Control.ReverseGearRatios.Num(); ++i)
188 Control.ChangeUpRPM = change_up_rpm;
191 Control.Mass = mass;
194 Control.ChassisWidth = chassis_width;
197 Control.DragArea = drag_area;
198 Control.InertiaTensorScale = FVector(
204 for (auto [x, y] : steering_curve)
205 Control.SteeringCurve.AddKey(x, y);
206 Control.Wheels.SetNum(wheels.size());
207 for (size_t i = 0; i != Control.Wheels.Num(); ++i)
208 Control.Wheels[i] = wheels[i];
210 return Control;
211 }
212
213#endif
214
218 max_rpm,
219 idle_rpm,
233 mass,
239 drag_area,
244 wheels,
246 );
247 };
248
249 } // namespace rpc
250} // namespace carla
float y
float x
This file contains definitions of common data structures used in traffic manager.
bool operator==(const VehiclePhysicsControl &rhs) const
bool operator!=(const VehiclePhysicsControl &rhs) const
static VehiclePhysicsControl FromFVehiclePhysicsControl(const FVehiclePhysicsControl &Control)
MSGPACK_DEFINE_ARRAY(torque_curve, max_torque, max_rpm, idle_rpm, brake_effect, rev_up_moi, rev_down_rate, differential_type, front_rear_split, use_automatic_gears, gear_change_time, final_ratio, forward_gear_ratios, reverse_gear_ratios, change_up_rpm, change_down_rpm, transmission_efficiency, mass, drag_coefficient, center_of_mass, chassis_width, chassis_height, downforce_coefficient, drag_area, inertia_tensor_scale, sleep_threshold, sleep_slope_limit, steering_curve, wheels, use_sweep_wheel_collision)
static WheelPhysicsControl FromFWheelPhysicsControl(const FWheelPhysicsControl &Wheel)