-
-
Notifications
You must be signed in to change notification settings - Fork 3.5k
/
Vehicle.cpp
136 lines (107 loc) · 4.18 KB
/
Vehicle.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
// Copyright (c) 2019 Computer Vision Center (CVC) at the Universitat Autonoma
// de Barcelona (UAB).
//
// This work is licensed under the terms of the MIT license.
// For a copy, see <https://opensource.org/licenses/MIT>.
#include "carla/client/Vehicle.h"
#include "carla/client/ActorList.h"
#include "carla/client/detail/Simulator.h"
#include "carla/client/TrafficLight.h"
#include "carla/Memory.h"
#include "carla/rpc/TrafficLightState.h"
#include "carla/trafficmanager/TrafficManager.h"
namespace carla {
using TM = traffic_manager::TrafficManager;
namespace client {
template <typename AttributesT>
static bool GetControlIsSticky(const AttributesT &attributes) {
for (auto &&attribute : attributes) {
if (attribute.GetId() == "sticky_control") {
return attribute.template As<bool>();
}
}
return true;
}
Vehicle::Vehicle(ActorInitializer init)
: Actor(std::move(init)),
_is_control_sticky(GetControlIsSticky(GetAttributes())) {}
void Vehicle::SetAutopilot(bool enabled, uint16_t tm_port) {
TM tm(GetEpisode(), tm_port);
if (enabled) {
tm.RegisterVehicles({shared_from_this()});
} else {
tm.UnregisterVehicles({shared_from_this()});
}
}
void Vehicle::ShowDebugTelemetry(bool enabled) {
GetEpisode().Lock()->ShowVehicleDebugTelemetry(*this, enabled);
}
void Vehicle::ApplyControl(const Control &control) {
if (!_is_control_sticky || (control != _control)) {
GetEpisode().Lock()->ApplyControlToVehicle(*this, control);
_control = control;
}
}
void Vehicle::ApplyPhysicsControl(const PhysicsControl &physics_control) {
GetEpisode().Lock()->ApplyPhysicsControlToVehicle(*this, physics_control);
}
void Vehicle::OpenDoor(const VehicleDoor door_idx) {
GetEpisode().Lock()->OpenVehicleDoor(*this, rpc::VehicleDoor(door_idx));
}
void Vehicle::CloseDoor(const VehicleDoor door_idx) {
GetEpisode().Lock()->CloseVehicleDoor(*this, rpc::VehicleDoor(door_idx));
}
void Vehicle::SetLightState(const LightState &light_state) {
GetEpisode().Lock()->SetLightStateToVehicle(*this, rpc::VehicleLightState(light_state));
}
void Vehicle::SetWheelSteerDirection(WheelLocation wheel_location, float angle_in_deg) {
GetEpisode().Lock()->SetWheelSteerDirection(*this, wheel_location, angle_in_deg);
}
float Vehicle::GetWheelSteerAngle(WheelLocation wheel_location) {
return GetEpisode().Lock()->GetWheelSteerAngle(*this, wheel_location);
}
Vehicle::Control Vehicle::GetControl() const {
return GetEpisode().Lock()->GetActorSnapshot(*this).state.vehicle_data.control;
}
Vehicle::PhysicsControl Vehicle::GetPhysicsControl() const {
return GetEpisode().Lock()->GetVehiclePhysicsControl(*this);
}
Vehicle::LightState Vehicle::GetLightState() const {
return GetEpisode().Lock()->GetVehicleLightState(*this).GetLightStateEnum();
}
float Vehicle::GetSpeedLimit() const {
return GetEpisode().Lock()->GetActorSnapshot(*this).state.vehicle_data.speed_limit;
}
rpc::TrafficLightState Vehicle::GetTrafficLightState() const {
return GetEpisode().Lock()->GetActorSnapshot(*this).state.vehicle_data.traffic_light_state;
}
bool Vehicle::IsAtTrafficLight() {
return GetEpisode().Lock()->GetActorSnapshot(*this).state.vehicle_data.has_traffic_light;
}
SharedPtr<TrafficLight> Vehicle::GetTrafficLight() const {
auto id = GetEpisode().Lock()->GetActorSnapshot(*this).state.vehicle_data.traffic_light_id;
return boost::static_pointer_cast<TrafficLight>(GetWorld().GetActor(id));
}
void Vehicle::EnableCarSim(std::string simfile_path) {
GetEpisode().Lock()->EnableCarSim(*this, simfile_path);
}
void Vehicle::UseCarSimRoad(bool enabled) {
GetEpisode().Lock()->UseCarSimRoad(*this, enabled);
}
void Vehicle::EnableChronoPhysics(
uint64_t MaxSubsteps,
float MaxSubstepDeltaTime,
std::string VehicleJSON,
std::string PowertrainJSON,
std::string TireJSON,
std::string BaseJSONPath) {
GetEpisode().Lock()->EnableChronoPhysics(*this,
MaxSubsteps,
MaxSubstepDeltaTime,
VehicleJSON,
PowertrainJSON,
TireJSON,
BaseJSONPath);
}
} // namespace client
} // namespace carla