CARLA
 
载入中...
搜索中...
未找到
Vehicle.cpp
浏览该文件的文档.
1// Copyright (c) 2019 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
8
12#include "carla/Memory.h"
14
16
17namespace carla {
18
20
21namespace client {
22
23
24 template <typename AttributesT>
25 static bool GetControlIsSticky(const AttributesT &attributes) {
26 for (auto &&attribute : attributes) {
27 if (attribute.GetId() == "sticky_control") {
28 return attribute.template As<bool>();
29 }
30 }
31 return true;
32 }
33
35 : Actor(std::move(init)),
36 _is_control_sticky(GetControlIsSticky(GetAttributes())) {}
37
38 void Vehicle::SetAutopilot(bool enabled, uint16_t tm_port) {
39 TM tm(GetEpisode(), tm_port);
40 if (enabled) {
41 tm.RegisterVehicles({shared_from_this()});
42 } else {
43 tm.UnregisterVehicles({shared_from_this()});
44 }
45 }
46
48 return GetEpisode().Lock()->GetVehicleTelemetryData(*this);
49 }
50
51 void Vehicle::ShowDebugTelemetry(bool enabled) {
52 GetEpisode().Lock()->ShowVehicleDebugTelemetry(*this, enabled);
53 }
54
55 void Vehicle::ApplyControl(const Control &control) {
56 if (!_is_control_sticky || (control != _control)) {
57 GetEpisode().Lock()->ApplyControlToVehicle(*this, control);
58 _control = control;
59 }
60 }
61
63 GetEpisode().Lock()->ApplyAckermannControlToVehicle(*this, control);
64 }
65
67 return GetEpisode().Lock()->GetAckermannControllerSettings(*this);
68 }
69
71 GetEpisode().Lock()->ApplyAckermannControllerSettings(*this, settings);
72 }
73
74 void Vehicle::ApplyPhysicsControl(const PhysicsControl &physics_control) {
75 GetEpisode().Lock()->ApplyPhysicsControlToVehicle(*this, physics_control);
76 }
77
78 void Vehicle::OpenDoor(const VehicleDoor door_idx) {
79 GetEpisode().Lock()->OpenVehicleDoor(*this, rpc::VehicleDoor(door_idx));
80 }
81
82 void Vehicle::CloseDoor(const VehicleDoor door_idx) {
83 GetEpisode().Lock()->CloseVehicleDoor(*this, rpc::VehicleDoor(door_idx));
84 }
85
86 void Vehicle::SetLightState(const LightState &light_state) {
87 GetEpisode().Lock()->SetLightStateToVehicle(*this, rpc::VehicleLightState(light_state));
88 }
89
90 void Vehicle::SetWheelSteerDirection(WheelLocation wheel_location, float angle_in_deg) {
91 GetEpisode().Lock()->SetWheelSteerDirection(*this, wheel_location, angle_in_deg);
92 }
93
95 return GetEpisode().Lock()->GetWheelSteerAngle(*this, wheel_location);
96 }
97
99 return GetEpisode().Lock()->GetActorSnapshot(*this).state.vehicle_data.control;
100 }
101
103 return GetEpisode().Lock()->GetVehiclePhysicsControl(*this);
104 }
105
107 return GetEpisode().Lock()->GetVehicleLightState(*this).GetLightStateEnum();
108 }
109
111 return GetEpisode().Lock()->GetActorSnapshot(*this).state.vehicle_data.speed_limit;
112 }
113
115 return GetEpisode().Lock()->GetActorSnapshot(*this).state.vehicle_data.traffic_light_state;
116 }
117
119 return GetEpisode().Lock()->GetActorSnapshot(*this).state.vehicle_data.has_traffic_light;
120 }
121
123 auto id = GetEpisode().Lock()->GetActorSnapshot(*this).state.vehicle_data.traffic_light_id;
124 return boost::static_pointer_cast<TrafficLight>(GetWorld().GetActor(id));
125 }
126
127 void Vehicle::EnableCarSim(std::string simfile_path) {
128 GetEpisode().Lock()->EnableCarSim(*this, simfile_path);
129 }
130
131 void Vehicle::UseCarSimRoad(bool enabled) {
132 GetEpisode().Lock()->UseCarSimRoad(*this, enabled);
133 }
134
136 uint64_t MaxSubsteps,
137 float MaxSubstepDeltaTime,
138 std::string VehicleJSON,
139 std::string PowertrainJSON,
140 std::string TireJSON,
141 std::string BaseJSONPath) {
142 GetEpisode().Lock()->EnableChronoPhysics(*this,
143 MaxSubsteps,
144 MaxSubstepDeltaTime,
145 VehicleJSON,
146 PowertrainJSON,
147 TireJSON,
148 BaseJSONPath);
149 }
150
152 GetEpisode().Lock()->RestorePhysXPhysics(*this);
153 }
154
156 return GetEpisode().Lock()->GetActorSnapshot(*this).state.vehicle_data.failure_state;
157 }
158
159} // namespace client
160} // 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:90
TelemetryData GetTelemetryData() const
Return the telemetry data for this vehicle.
Definition Vehicle.cpp:47
void ApplyControl(const Control &control)
Apply control to this vehicle.
Definition Vehicle.cpp:55
PhysicsControl GetPhysicsControl() const
Return the physics control last applied to this vehicle.
Definition Vehicle.cpp:102
float GetWheelSteerAngle(WheelLocation wheel_location)
Return a Rotation from a wheel of the vehicle
Definition Vehicle.cpp:94
void CloseDoor(const VehicleDoor door_idx)
Close a door in this vehicle
Definition Vehicle.cpp:82
Vehicle(ActorInitializer init)
Definition Vehicle.cpp:34
LightState GetLightState() const
Return the current open lights (LightState) of this vehicle.
Definition Vehicle.cpp:106
bool IsAtTrafficLight()
Return whether a traffic light is affecting this vehicle.
Definition Vehicle.cpp:118
void EnableCarSim(std::string simfile_path)
Enables CarSim simulation if it is availiable
Definition Vehicle.cpp:127
rpc::TrafficLightState GetTrafficLightState() const
Return the state of the traffic light currently affecting this vehicle.
Definition Vehicle.cpp:114
void ApplyAckermannControl(const AckermannControl &control)
Apply control to this vehicle.
Definition Vehicle.cpp:62
void ApplyPhysicsControl(const PhysicsControl &physics_control)
Apply physics control to this vehicle.
Definition Vehicle.cpp:74
rpc::AckermannControllerSettings GetAckermannControllerSettings() const
Return the last Ackermann controller settings applied to this vehicle.
Definition Vehicle.cpp:66
float GetSpeedLimit() const
Return the speed limit currently affecting this vehicle.
Definition Vehicle.cpp:110
SharedPtr< TrafficLight > GetTrafficLight() const
Retrieve the traffic light actor currently affecting this vehicle.
Definition Vehicle.cpp:122
Control GetControl() const
Return the control last applied to this vehicle.
Definition Vehicle.cpp:98
void UseCarSimRoad(bool enabled)
Enables the use of CarSim internal road definition instead of unreal's
Definition Vehicle.cpp:131
void ApplyAckermannControllerSettings(const rpc::AckermannControllerSettings &settings)
Apply Ackermann control settings to this vehicle
Definition Vehicle.cpp:70
void OpenDoor(const VehicleDoor door_idx)
Open a door in this vehicle
Definition Vehicle.cpp:78
void EnableChronoPhysics(uint64_t MaxSubsteps, float MaxSubstepDeltaTime, std::string VehicleJSON="", std::string PowertrainJSON="", std::string TireJSON="", std::string BaseJSONPath="")
Definition Vehicle.cpp:135
void SetLightState(const LightState &light_state)
Sets a LightState to this vehicle.
Definition Vehicle.cpp:86
rpc::VehicleFailureState GetFailureState() const
Returns the failure state of the vehicle
Definition Vehicle.cpp:155
const bool _is_control_sticky
Definition Vehicle.h:154
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:51
SharedPtrType Lock() const
Same as TryLock but never return nullptr.
Defines the physical appearance of a vehicle whitch is obtained by the sensors.
This class integrates all the various stages of the traffic manager appropriately using messengers.
void UnregisterVehicles(const std::vector< ActorPtr > &actor_list)
This method unregisters a vehicle from traffic manager.
void RegisterVehicles(const std::vector< ActorPtr > &actor_list)
This method registers a vehicle with the traffic manager.
static bool GetControlIsSticky(const AttributesT &attributes)
Definition Vehicle.cpp:25
This file contains definitions of common data structures used in traffic manager.
Definition Carla.cpp:133
boost::shared_ptr< T > SharedPtr
Use this SharedPtr (boost::shared_ptr) to keep compatibility with boost::python, but it would be nice...
Definition Memory.h:20