CARLA
Loading...
Searching...
No Matches
Vehicle.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
20
22
23namespace carla {
24
25namespace traffic_manager {
26 class TrafficManager;
27}
28
29namespace client {
30
31 class TrafficLight;
32
33 class Vehicle : public Actor {
34 public:
35
44
45
46 explicit Vehicle(ActorInitializer init);
47
48 /// Switch on/off this vehicle's autopilot.
49 void SetAutopilot(bool enabled = true, uint16_t tm_port = TM_DEFAULT_PORT);
50
51 /// Switch on/off this vehicle's autopilot.
52 void ShowDebugTelemetry(bool enabled = true);
53
54 /// Apply @a control to this vehicle.
55 void ApplyControl(const Control &control);
56
57 /// Apply @a control to this vehicle.
58 void ApplyAckermannControl(const AckermannControl &control);
59
60 /// Return the last Ackermann controller settings applied to this vehicle.
61 ///
62 /// @warning This function does call the simulator.
64
65 /// Apply Ackermann control settings to this vehicle
67
68 /// Apply physics control to this vehicle.
69 void ApplyPhysicsControl(const PhysicsControl &physics_control);
70
71 /// Open a door in this vehicle
72 void OpenDoor(const VehicleDoor door_idx);
73
74 /// Close a door in this vehicle
75 void CloseDoor(const VehicleDoor door_idx);
76
77 /// Sets a @a LightState to this vehicle.
78 void SetLightState(const LightState &light_state);
79
80 /// Sets a @a Rotation to a wheel of the vehicle (affects the bone of the car skeleton, not the physics)
81 void SetWheelSteerDirection(WheelLocation wheel_location, float angle_in_deg);
82
83 /// Return a @a Rotation from a wheel of the vehicle
84 ///
85 /// @note The function returns the rotation of the vehicle based on the it's physics
86 float GetWheelSteerAngle(WheelLocation wheel_location);
87
88 /// Sets the spin angle of a wheel, in degrees (affects the bone of the car skeleton, not the physics)
89 void SetWheelPitchAngle(WheelLocation wheel_location, float angle_in_deg);
90
91 /// Return the spin angle of a wheel, in degrees
92 float GetWheelPitchAngle(WheelLocation wheel_location);
93
94 /// Sets the suspension compression of a wheel, in meters (affects the bone of the car skeleton, not the physics)
95 void SetWheelSuspensionOffset(WheelLocation wheel_location, float offset);
96
97 /// Return the suspension compression of a wheel, in meters
98 float GetWheelSuspensionOffset(WheelLocation wheel_location);
99
100 /// Enables or disables the wheel animation override, in which the wheels
101 /// show only the values set through the wheel setters (affects the bones
102 /// of the car skeleton, not the physics)
103 void SetWheelAnimationOverride(bool enabled);
104
105 /// Return the control last applied to this vehicle.
106 ///
107 /// @note This function does not call the simulator, it returns the data
108 /// received in the last tick.
109 Control GetControl() const;
110
111 /// Return the physics control last applied to this vehicle.
112 ///
113 /// @warning This function does call the simulator.
115
116 /// Return the runtime telemetry of this vehicle: forward speed, last
117 /// applied control inputs, engine RPM, current gear, and per-wheel
118 /// lateral slip, longitudinal slip, and angular velocity sourced from
119 /// the Chaos vehicle physics state.
120 ///
121 /// @warning This function does call the simulator.
123
124 /// Return the current open lights (LightState) of this vehicle.
125 ///
126 /// @note This function does not call the simulator, it returns the data
127 /// received in the last tick.
129
130 /// Return the speed limit currently affecting this vehicle.
131 ///
132 /// @note This function does not call the simulator, it returns the data
133 /// received in the last tick.
134 float GetSpeedLimit() const;
135
136 std::vector<geom::Transform> GetVehicleBoneWorldTransforms() const;
137
138 /// Return the state of the traffic light currently affecting this vehicle.
139 ///
140 /// @return Green If no traffic light is affecting the vehicle.
141 ///
142 /// @note This function does not call the simulator, it returns the data
143 /// received in the last tick.
145
146 /// Return whether a traffic light is affecting this vehicle.
147 ///
148 /// @note This function does not call the simulator, it returns the data
149 /// received in the last tick.
150 bool IsAtTrafficLight();
151
152 /// Retrieve the traffic light actor currently affecting this vehicle.
154
155 /// Enables CarSim simulation if it is availiable
156 void EnableCarSim(std::string simfile_path);
157
158 /// Enables the use of CarSim internal road definition instead of unreal's
159 void UseCarSimRoad(bool enabled);
160
162 uint64_t MaxSubsteps,
163 float MaxSubstepDeltaTime,
164 std::string VehicleJSON = "",
165 std::string PowertrainJSON = "",
166 std::string TireJSON = "",
167 std::string BaseJSONPath = "");
168
169 /// Returns the failure state of the vehicle
171
172 private:
173
175
177 };
178
179} // namespace client
180} // namespace carla
Used to initialize Actor classes.
Represents an actor in the simulation.
void SetWheelSteerDirection(WheelLocation wheel_location, float angle_in_deg)
Sets a Rotation to a wheel of the vehicle (affects the bone of the car skeleton, not the physics)
Definition Vehicle.cpp:86
TelemetryData GetTelemetryData() const
Return the runtime telemetry of this vehicle: forward speed, last applied control inputs,...
Definition Vehicle.cpp:122
void ApplyControl(const Control &control)
Apply control to this vehicle.
Definition Vehicle.cpp:51
void SetWheelAnimationOverride(bool enabled)
Enables or disables the wheel animation override, in which the wheels show only the values set throug...
Definition Vehicle.cpp:110
PhysicsControl GetPhysicsControl() const
Return the physics control last applied to this vehicle.
Definition Vehicle.cpp:118
float GetWheelSteerAngle(WheelLocation wheel_location)
Return a Rotation from a wheel of the vehicle.
Definition Vehicle.cpp:90
void CloseDoor(const VehicleDoor door_idx)
Close a door in this vehicle.
Definition Vehicle.cpp:78
LightState GetLightState() const
Return the current open lights (LightState) of this vehicle.
Definition Vehicle.cpp:126
bool IsAtTrafficLight()
Return whether a traffic light is affecting this vehicle.
Definition Vehicle.cpp:142
void EnableCarSim(std::string simfile_path)
Enables CarSim simulation if it is availiable.
Definition Vehicle.cpp:151
rpc::TrafficLightState GetTrafficLightState() const
Return the state of the traffic light currently affecting this vehicle.
Definition Vehicle.cpp:138
void ApplyAckermannControl(const AckermannControl &control)
Apply control to this vehicle.
Definition Vehicle.cpp:58
float GetWheelSuspensionOffset(WheelLocation wheel_location)
Return the suspension compression of a wheel, in meters.
Definition Vehicle.cpp:106
void ApplyPhysicsControl(const PhysicsControl &physics_control)
Apply physics control to this vehicle.
Definition Vehicle.cpp:70
rpc::AckermannControllerSettings GetAckermannControllerSettings() const
Return the last Ackermann controller settings applied to this vehicle.
Definition Vehicle.cpp:62
float GetSpeedLimit() const
Return the speed limit currently affecting this vehicle.
Definition Vehicle.cpp:134
void SetWheelPitchAngle(WheelLocation wheel_location, float angle_in_deg)
Sets the spin angle of a wheel, in degrees (affects the bone of the car skeleton, not the physics)
Definition Vehicle.cpp:94
SharedPtr< TrafficLight > GetTrafficLight() const
Retrieve the traffic light actor currently affecting this vehicle.
Definition Vehicle.cpp:146
void SetWheelSuspensionOffset(WheelLocation wheel_location, float offset)
Sets the suspension compression of a wheel, in meters (affects the bone of the car skeleton,...
Definition Vehicle.cpp:102
Control GetControl() const
Return the control last applied to this vehicle.
Definition Vehicle.cpp:114
std::vector< geom::Transform > GetVehicleBoneWorldTransforms() const
Definition Vehicle.cpp:130
void UseCarSimRoad(bool enabled)
Enables the use of CarSim internal road definition instead of unreal's.
Definition Vehicle.cpp:155
void ApplyAckermannControllerSettings(const rpc::AckermannControllerSettings &settings)
Apply Ackermann control settings to this vehicle.
Definition Vehicle.cpp:66
void OpenDoor(const VehicleDoor door_idx)
Open a door in this vehicle.
Definition Vehicle.cpp:74
void EnableChronoPhysics(uint64_t MaxSubsteps, float MaxSubstepDeltaTime, std::string VehicleJSON="", std::string PowertrainJSON="", std::string TireJSON="", std::string BaseJSONPath="")
Definition Vehicle.cpp:159
float GetWheelPitchAngle(WheelLocation wheel_location)
Return the spin angle of a wheel, in degrees.
Definition Vehicle.cpp:98
void SetLightState(const LightState &light_state)
Sets a LightState to this vehicle.
Definition Vehicle.cpp:82
rpc::VehicleFailureState GetFailureState() const
Returns the failure state of the vehicle.
Definition Vehicle.cpp:175
const bool _is_control_sticky
Definition Vehicle.h:174
void SetAutopilot(bool enabled=true, uint16_t tm_port=TM_DEFAULT_PORT)
Switch on/off this vehicle's autopilot.
Definition Vehicle.cpp:38
void ShowDebugTelemetry(bool enabled=true)
Switch on/off this vehicle's autopilot.
Definition Vehicle.cpp:47
This class integrates all the various stages of the traffic manager appropriately using messengers.
static const unsigned short TM_DEFAULT_PORT
Definition Constants.h:23
This file contains definitions of common data structures used in traffic manager.
std::shared_ptr< T > SharedPtr
Definition Memory.h:15