CARLA
Loading...
Searching...
No Matches
MotionPlanStage.h
Go to the documentation of this file.
1
2/// This file has functionality for motion planning based on information
3/// from localization, collision avoidance and traffic light response.
4
5#pragma once
6
15
16namespace carla {
17namespace traffic_manager {
18
19using LocalMapPtr = std::shared_ptr<InMemoryMap>;
20using TLMap = std::unordered_map<std::string, SharedPtr<client::Actor>>;
21
23private:
24 const std::vector<ActorId> &vehicle_id_list;
29 // PID paramenters for various road conditions.
30 const std::vector<float> urban_longitudinal_parameters;
31 const std::vector<float> highway_longitudinal_parameters;
32 const std::vector<float> urban_lateral_parameters;
33 const std::vector<float> highway_lateral_parameters;
37 // Structure holding the controller state for registered vehicles.
38 std::unordered_map<ActorId, StateEntry> pid_state_map;
39 // Structure to keep track of duration between teleportation
40 // in hybrid physics mode.
41 std::unordered_map<ActorId, cc::Timestamp> teleportation_instance;
42 // Stuck/misaligned-vehicle recovery bookkeeping: when the vehicle first
43 // stopped making commanded progress, and the K-turn maneuver state
44 // (current phase deadline + whether the phase reverses).
48 // Turn direction latched at maneuver entry. Recomputing it from the
49 // instantaneous deviation sign every tick makes the maneuver cancel
50 // itself when the target sits near dead-astern: each rock past 180 deg
51 // flips the sign and the phases undo each other.
53 };
54 std::unordered_map<ActorId, double> stuck_since;
55 std::unordered_map<ActorId, RecoveryState> recovery_state;
60 std::unordered_map<ActorId, std::pair<float, bool>> &large_vehicles;
61
62 std::pair<bool, float> CollisionHandling(const CollisionHazardData &collision_hazard,
63 const bool tl_hazard,
64 const cg::Vector3D ego_velocity,
65 const cg::Vector3D ego_heading,
66 const float max_target_velocity);
67
68 bool SafeAfterJunction(const LocalizationData &localization,
69 const bool tl_hazard,
70 const bool collision_emergency_stop);
71
72 [[nodiscard]] float CalculateBaseOffset(
73 const ActorId actor_id,
74 const Buffer &waypoint_buffer,
75 const bool is_target_junction,
76 const uint64_t target_index);
77
78 /// Returns true when the lateral band that the wide-turn offset would swing
79 /// `actor_id` into is occupied by a nearby vehicle. Gathers the overlapping
80 /// vehicles from track_traffic and delegates the geometric decision to the
81 /// pure IsOffsetSideOccupied helper.
82 [[nodiscard]] bool IsWideTurnSideOccupied(
83 const ActorId actor_id,
84 const cg::Vector3D offset_direction,
85 const float offset_magnitude);
86
87 float GetLandmarkTargetVelocity(const SimpleWaypoint& waypoint,
88 const cg::Location vehicle_location,
89 const ActorId actor_id,
90 float max_target_velocity);
91
92 float GetTurnTargetVelocity(const Buffer &waypoint_buffer,
93 const cg::Location vehicle_location,
94 float max_target_velocity);
95
96public:
97 MotionPlanStage(const std::vector<ActorId> &vehicle_id_list,
100 const BufferMap &buffer_map,
102 const std::vector<float> &urban_longitudinal_parameters,
103 const std::vector<float> &highway_longitudinal_parameters,
104 const std::vector<float> &urban_lateral_parameters,
105 const std::vector<float> &highway_lateral_parameters,
108 const TLFrame &tl_frame,
111 const LocalMapPtr &local_map,
112 std::unordered_map<ActorId, std::pair<float, bool>> &large_vehicles);
113
114 /// Pins one frame for the whole cycle; reading it per vehicle lets a frame
115 /// land mid-cycle and skews the controller period within a cycle.
116 void SetCycleTimestamp(const cc::Timestamp &timestamp);
117
118 void Update(const unsigned long index);
119
120 void RemoveActor(const ActorId actor_id);
121
122 void Reset();
123};
124
125} // namespace traffic_manager
126} // namespace carla
const std::vector< float > urban_longitudinal_parameters
std::unordered_map< ActorId, RecoveryState > recovery_state
const LocalizationFrame & localization_frame
std::unordered_map< ActorId, double > stuck_since
const std::vector< float > highway_lateral_parameters
std::unordered_map< ActorId, cc::Timestamp > teleportation_instance
bool SafeAfterJunction(const LocalizationData &localization, const bool tl_hazard, const bool collision_emergency_stop)
void Update(const unsigned long index)
const std::vector< float > highway_longitudinal_parameters
float CalculateBaseOffset(const ActorId actor_id, const Buffer &waypoint_buffer, const bool is_target_junction, const uint64_t target_index)
const std::vector< ActorId > & vehicle_id_list
float GetLandmarkTargetVelocity(const SimpleWaypoint &waypoint, const cg::Location vehicle_location, const ActorId actor_id, float max_target_velocity)
float GetTurnTargetVelocity(const Buffer &waypoint_buffer, const cg::Location vehicle_location, float max_target_velocity)
std::unordered_map< ActorId, std::pair< float, bool > > & large_vehicles
bool IsWideTurnSideOccupied(const ActorId actor_id, const cg::Vector3D offset_direction, const float offset_magnitude)
Returns true when the lateral band that the wide-turn offset would swing actor_id into is occupied by...
void RemoveActor(const ActorId actor_id)
void SetCycleTimestamp(const cc::Timestamp &timestamp)
Pins one frame for the whole cycle; reading it per vehicle lets a frame land mid-cycle and skews the ...
const std::vector< float > urban_lateral_parameters
std::unordered_map< ActorId, StateEntry > pid_state_map
std::pair< bool, float > CollisionHandling(const CollisionHazardData &collision_hazard, const bool tl_hazard, const cg::Vector3D ego_velocity, const cg::Vector3D ego_heading, const float max_target_velocity)
This is a simple wrapper class on Carla's waypoint object.
This class holds the state of all the vehicles in the simlation.
Stage type interface.
Definition Stage.h:12
std::deque< std::shared_ptr< SimpleWaypoint > > Buffer
std::shared_ptr< InMemoryMap > LocalMapPtr
Definition ALSM.h:38
std::unordered_map< carla::ActorId, Buffer > BufferMap
std::unordered_map< std::string, SharedPtr< client::Actor > > TLMap
std::vector< CollisionHazardData > CollisionFrame
std::vector< bool > TLFrame
std::vector< carla::rpc::Command > ControlFrame
std::vector< LocalizationData > LocalizationFrame
This file contains definitions of common data structures used in traffic manager.