CARLA
Loading...
Searching...
No Matches
LibCarla/source/carla/rpc/WheelPhysicsControl.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//
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/geom/Location.h"
12#include "carla/MsgPack.h"
13
14
15namespace carla {
16 namespace rpc {
17
19
20 uint8_t axle_type = 0; // @TODO INTRODUCE ENUM
22 float wheel_radius = 30.0f;
23 float wheel_width = 30.0f;
24 float wheel_mass = 30.0f;
25 float cornering_stiffness = 1000.0f;
27 float side_slip_modifier = 1.0f;
28 float slip_threshold = 20.0f;
29 float skid_threshold = 20.0f;
30 float max_steer_angle = 70.0f;
32 bool affected_by_brake = true;
34 bool affected_by_engine = true;
35 bool abs_enabled = false;
38 uint8_t external_torque_combine_method = 0; // @TODO INTRODUCE ENUM
39 std::vector<geom::Vector2D> lateral_slip_graph = {};
42 float suspension_max_raise = 10.0f;
43 float suspension_max_drop = 10.0f;
45 float wheel_load_ratio = 0.5f;
46 float spring_rate = 250.0f;
47 float spring_preload = 50.0f;
49 float rollbar_scaling = 0.15f;
50 uint8_t sweep_shape = 0; // @TODO INTRODUCE ENUM
51 uint8_t sweep_type = 0; // @TODO INTRODUCE ENUM
52 float max_brake_torque = 1500.0f;
53 float max_hand_brake_torque = 3000.0f;
54 int32_t wheel_index = -1;
58
59 inline bool operator==(const WheelPhysicsControl& rhs) const {
60 const bool cmp[] =
61 {
62 axle_type == rhs.axle_type,
63 offset == rhs.offset,
97 location == rhs.location,
99 velocity == rhs.velocity
100 };
101 return std::all_of(std::begin(cmp), std::end(cmp), [](bool b) noexcept { return b; });
102 }
103
104 inline bool operator!=(const WheelPhysicsControl& rhs) const {
105 return !(*this == rhs);
106 }
107
108#ifdef LIBCARLA_INCLUDED_FROM_UE4
109
111 const FWheelPhysicsControl& Wheel)
112 {
113 WheelPhysicsControl Out = { };
114 Out.axle_type = (uint8_t)Wheel.AxleType;
116 Wheel.Offset.X,
117 Wheel.Offset.Y,
118 Wheel.Offset.Z);
119 Out.wheel_radius = Wheel.WheelRadius;
120 Out.wheel_width = Wheel.WheelWidth;
121 Out.wheel_mass = Wheel.WheelMass;
125 Out.slip_threshold = Wheel.SlipThreshold;
126 Out.skid_threshold = Wheel.SkidThreshold;
127 Out.max_steer_angle = Wheel.MaxSteerAngle;
132 Out.abs_enabled = Wheel.bABSEnabled;
136 Out.lateral_slip_graph.reserve(Wheel.LateralSlipGraph.GetNumKeys());
137 for (auto& e : Wheel.LateralSlipGraph.GetConstRefOfKeys())
138 Out.lateral_slip_graph.push_back({ e.Time, e.Value });
139 Out.suspension_axis = geom::Vector3D(
140 Wheel.SuspensionAxis.X,
141 Wheel.SuspensionAxis.Y,
142 Wheel.SuspensionAxis.Z);
143 Out.suspension_force_offset = geom::Vector3D(
144 Wheel.SuspensionForceOffset.X,
145 Wheel.SuspensionForceOffset.Y,
146 Wheel.SuspensionForceOffset.Z);
147 Out.suspension_max_raise = Wheel.SuspensionMaxRaise;
148 Out.suspension_max_drop = Wheel.SuspensionMaxDrop;
149 Out.suspension_damping_ratio = Wheel.SuspensionDampingRatio;
150 Out.wheel_load_ratio = Wheel.WheelLoadRatio;
151 Out.spring_rate = Wheel.SpringRate;
152 Out.spring_preload = Wheel.SpringPreload;
153 Out.suspension_smoothing = Wheel.SuspensionSmoothing;
154 Out.rollbar_scaling = Wheel.RollbarScaling;
155 Out.sweep_shape = (uint8_t)Wheel.SweepShape;
156 Out.sweep_type = (uint8_t)Wheel.SweepType;
157 Out.max_brake_torque = Wheel.MaxBrakeTorque;
158 Out.max_hand_brake_torque = Wheel.MaxHandBrakeTorque;
159 Out.wheel_index = Wheel.WheelIndex;
160 Out.location = Wheel.Location;
161 Out.old_location = Wheel.OldLocation;
162 Out.velocity = Wheel.Velocity;
163 return Out;
164 }
165
166 operator FWheelPhysicsControl() const {
168 Wheel.AxleType = (EAxleType)axle_type;
169 Wheel.Offset = FVector(offset.x, offset.y, offset.z);
170 Wheel.WheelRadius = wheel_radius;
171 Wheel.WheelWidth = wheel_width;
172 Wheel.WheelMass = wheel_mass;
173 Wheel.CorneringStiffness = cornering_stiffness;
174 Wheel.FrictionForceMultiplier = friction_force_multiplier;
175 Wheel.SideSlipModifier = side_slip_modifier;
176 Wheel.SlipThreshold = slip_threshold;
177 Wheel.SkidThreshold = skid_threshold;
178 Wheel.MaxSteerAngle = max_steer_angle;
179 Wheel.bAffectedBySteering = affected_by_steering;
180 Wheel.bAffectedByBrake = affected_by_brake;
181 Wheel.bAffectedByHandbrake = affected_by_handbrake;
182 Wheel.bAffectedByEngine = affected_by_engine;
183 Wheel.bABSEnabled = abs_enabled;
184 Wheel.bTractionControlEnabled = traction_control_enabled;
185 Wheel.MaxWheelspinRotation = max_wheelspin_rotation;
186 Wheel.ExternalTorqueCombineMethod = (ETorqueCombineMethod)external_torque_combine_method;
187 for (auto [x, y] : lateral_slip_graph)
188 Wheel.LateralSlipGraph.AddKey(x, y);
189 Wheel.SuspensionAxis = FVector(
190 suspension_axis.x,
191 suspension_axis.y,
192 suspension_axis.z);
193 Wheel.SuspensionForceOffset = FVector(
194 suspension_force_offset.x,
195 suspension_force_offset.y,
196 suspension_force_offset.z);
197 Wheel.SuspensionMaxRaise = suspension_max_raise;
198 Wheel.SuspensionMaxDrop = suspension_max_drop;
199 Wheel.SuspensionDampingRatio = suspension_damping_ratio;
200 Wheel.WheelLoadRatio = wheel_load_ratio;
201 Wheel.SpringRate = spring_rate;
202 Wheel.SpringPreload = spring_preload;
203 Wheel.SuspensionSmoothing = suspension_smoothing;
204 Wheel.RollbarScaling = rollbar_scaling;
205 Wheel.SweepShape = (ESweepShape)sweep_shape;
206 Wheel.SweepType = (ESweepType)sweep_type;
207 Wheel.MaxBrakeTorque = max_brake_torque;
208 Wheel.MaxHandBrakeTorque = max_hand_brake_torque;
209 Wheel.WheelIndex = wheel_index;
210 Wheel.Location = location;
211 Wheel.OldLocation = old_location;
212 Wheel.Velocity = velocity;
213 return Wheel;
214 }
215#endif
216
217 MSGPACK_DEFINE_ARRAY(
218 axle_type,
219 offset,
220 wheel_radius,
221 wheel_width,
222 wheel_mass,
223 cornering_stiffness,
224 friction_force_multiplier,
225 side_slip_modifier,
226 slip_threshold,
227 skid_threshold,
228 max_steer_angle,
229 affected_by_steering,
230 affected_by_brake,
231 affected_by_handbrake,
232 affected_by_engine,
233 abs_enabled,
234 traction_control_enabled,
235 max_wheelspin_rotation,
236 external_torque_combine_method,
237 lateral_slip_graph,
238 suspension_axis,
239 suspension_force_offset,
240 suspension_max_raise,
241 suspension_max_drop,
242 suspension_damping_ratio,
243 wheel_load_ratio,
244 spring_rate,
245 spring_preload,
246 suspension_smoothing,
247 rollbar_scaling,
248 sweep_shape,
249 sweep_type,
250 max_brake_torque,
251 max_hand_brake_torque,
252 wheel_index,
253 location,
254 old_location,
255 velocity)
256 };
257
258 }
259}
float y
float x
This file contains definitions of common data structures used in traffic manager.
ETorqueCombineMethod ExternalTorqueCombineMethod
Determines how the SetDriveTorque/SetBrakeTorque inputs are combined with the internal torques.
float SuspensionMaxRaise
How far the wheel can go above the resting position.
int SuspensionSmoothing
Smooth suspension [0-off, 10-max] - Warning might cause momentary visual inter-penetration of the whe...
ESweepShape SweepShape
Wheel suspension trace type, defaults to ray trace.
FVector SuspensionForceOffset
Vertical offset from where suspension forces are applied (along Z-axis)
float MaxHandBrakeTorque
Max handbrake brake torque for this wheel (Nm).
FVector Offset
If BoneName is specified, offset the wheel from the bone's location.
float SideSlipModifier
Wheel Lateral Skid Grip Loss, lower number less grip on skid.
float SuspensionMaxDrop
How far the wheel can drop below the resting position.
FVector SuspensionAxis
Local body direction in which where suspension forces are applied (typically along -Z-axis)
EAxleType AxleType
If left undefined then the bAffectedByEngine value is used, if defined then bAffectedByEngine is igno...
float SuspensionDampingRatio
Suspension damping, larger value causes the suspension to come to rest faster [range 0 to 1].
ESweepType SweepType
Whether wheel suspension considers simple, complex.
static WheelPhysicsControl FromFWheelPhysicsControl(const FWheelPhysicsControl &Wheel)
bool operator!=(const WheelPhysicsControl &rhs) const
bool operator==(const WheelPhysicsControl &rhs) const