/
SimulationState.h
106 lines (74 loc) · 2.78 KB
/
SimulationState.h
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
#pragma once
#include <unordered_set>
#include "carla/trafficmanager/DataStructures.h"
namespace carla {
namespace traffic_manager {
enum ActorType {
Vehicle,
Pedestrian,
Any
};
struct KinematicState {
cg::Location location;
cg::Rotation rotation;
cg::Vector3D velocity;
float speed_limit;
bool physics_enabled;
bool is_dormant;
cg::Location hybrid_end_location;
};
using KinematicStateMap = std::unordered_map<ActorId, KinematicState>;
struct TrafficLightState {
TLS tl_state;
bool at_traffic_light;
};
using TrafficLightStateMap = std::unordered_map<ActorId, TrafficLightState>;
struct StaticAttributes {
ActorType actor_type;
float half_length;
float half_width;
float half_height;
};
using StaticAttributeMap = std::unordered_map<ActorId, StaticAttributes>;
/// This class holds the state of all the vehicles in the simlation.
class SimulationState {
private:
// Structure to hold ids of all actors in the simulation.
std::unordered_set<ActorId> actor_set;
// Structure containing dynamic motion related state of actors.
KinematicStateMap kinematic_state_map;
// Structure containing static attributes of actors.
StaticAttributeMap static_attribute_map;
// Structure containing dynamic traffic light related state of actors.
TrafficLightStateMap tl_state_map;
public :
SimulationState();
// Method to add an actor to the simulation state.
void AddActor(ActorId actor_id,
KinematicState kinematic_state,
StaticAttributes attributes,
TrafficLightState tl_state);
// Method to verify if an actor is present currently present in the simulation state.
bool ContainsActor(ActorId actor_id) const;
// Method to remove an actor from simulation state.
void RemoveActor(ActorId actor_id);
// Method to flush all states and actors.
void Reset();
void UpdateKinematicState(ActorId actor_id, KinematicState state);
void UpdateKinematicHybridEndLocation(ActorId actor_id, cg::Location location);
void UpdateTrafficLightState(ActorId actor_id, TrafficLightState state);
cg::Location GetLocation(const ActorId actor_id) const;
cg::Location GetHybridEndLocation(const ActorId actor_id) const;
cg::Rotation GetRotation(const ActorId actor_id) const;
cg::Vector3D GetHeading(const ActorId actor_id) const;
cg::Vector3D GetVelocity(const ActorId actor_id) const;
float GetSpeedLimit(const ActorId actor_id) const;
bool IsPhysicsEnabled(const ActorId actor_id) const;
bool IsDormant(const ActorId actor_id) const;
cg::Location GetHeroLocation(const ActorId actor_id) const;
TrafficLightState GetTLS(const ActorId actor_id) const;
ActorType GetType(const ActorId actor_id) const;
cg::Vector3D GetDimensions(const ActorId actor_id) const;
};
} // namespace traffic_manager
} // namespace carla