CARLA
Parameters.h
Go to the documentation of this file.
1 // Copyright (c) 2020 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 
9 #include <atomic>
10 #include <chrono>
11 #include <random>
12 
13 #include "carla/client/Actor.h"
14 #include "carla/client/Vehicle.h"
15 #include "carla/Memory.h"
16 #include "carla/rpc/ActorId.h"
17 
20 
21 namespace carla {
22 namespace traffic_manager {
23 
24 namespace cc = carla::client;
25 namespace cg = carla::geom;
27 using ActorId = carla::ActorId;
28 
30  bool change_lane = false;
31  bool direction = false;
32 };
33 
34 class Parameters {
35 
36 private:
37  /// Target velocity map for individual vehicles.
39  /// Global target velocity limit % difference.
40  float global_percentage_difference_from_limit = 0;
41  /// Map containing a set of actors to be ignored during collision detection.
43  /// Map containing distance to leading vehicle command.
45  /// Map containing force lane change commands.
47  /// Map containing auto lane change commands.
49  /// Map containing % of running a traffic light.
51  /// Map containing % of running a traffic sign.
53  /// Map containing % of ignoring walkers.
55  /// Map containing % of ignoring vehicles.
57  /// Map containing % of keep right rule.
59  /// Synchronous mode switch.
60  std::atomic<bool> synchronous_mode{false};
61  /// Distance margin
62  std::atomic<float> distance_margin{2.0};
63  /// Hybrid physics mode switch.
64  std::atomic<bool> hybrid_physics_mode{false};
65  /// Automatic respawn mode switch.
66  std::atomic<bool> respawn_dormant_vehicles{false};
67  /// Minimum distance to respawn vehicles with respect to the hero vehicle.
68  std::atomic<float> respawn_lower_bound{100.0};
69  /// Maximum distance to respawn vehicles with respect to the hero vehicle.
70  std::atomic<float> respawn_upper_bound{1000.0};
71  /// Minimum possible distance to respawn vehicles with respect to the hero vehicle.
73  /// Maximum possible distance to respawn vehicles with respect to the hero vehicle.
75  /// Hybrid physics radius.
76  std::atomic<float> hybrid_physics_radius {70.0};
77  /// Parameter specifying Open Street Map mode.
78  std::atomic<bool> osm_mode {true};
79 
80 public:
81  Parameters();
82  ~Parameters();
83 
84  ////////////////////////////////// SETTERS /////////////////////////////////////
85 
86  /// Set a vehicle's % decrease in velocity with respect to the speed limit.
87  /// If less than 0, it's a % increase.
88  void SetPercentageSpeedDifference(const ActorPtr &actor, const float percentage);
89 
90  /// Set a global % decrease in velocity with respect to the speed limit.
91  /// If less than 0, it's a % increase.
92  void SetGlobalPercentageSpeedDifference(float const percentage);
93 
94  /// Method to set collision detection rules between vehicles.
95  void SetCollisionDetection(
96  const ActorPtr &reference_actor,
97  const ActorPtr &other_actor,
98  const bool detect_collision);
99 
100  /// Method to force lane change on a vehicle.
101  /// Direction flag can be set to true for left and false for right.
102  void SetForceLaneChange(const ActorPtr &actor, const bool direction);
103 
104  /// Enable/disable automatic lane change on a vehicle.
105  void SetAutoLaneChange(const ActorPtr &actor, const bool enable);
106 
107  /// Method to specify how much distance a vehicle should maintain to
108  /// the leading vehicle.
109  void SetDistanceToLeadingVehicle(const ActorPtr &actor, const float distance);
110 
111  /// Method to set % to run any traffic sign.
112  void SetPercentageRunningSign(const ActorPtr &actor, const float perc);
113 
114  /// Method to set % to run any traffic light.
115  void SetPercentageRunningLight(const ActorPtr &actor, const float perc);
116 
117  /// Method to set % to ignore any vehicle.
118  void SetPercentageIgnoreVehicles(const ActorPtr &actor, const float perc);
119 
120  /// Method to set % to ignore any vehicle.
121  void SetPercentageIgnoreWalkers(const ActorPtr &actor, const float perc);
122 
123  /// Method to set probabilistic preference to keep on the right lane.
124  void SetKeepRightPercentage(const ActorPtr &actor, const float percentage);
125 
126  /// Method to set the distance to leading vehicle for all registered vehicles.
127  void SetGlobalDistanceToLeadingVehicle(const float dist);
128 
129  /// Set Synchronous mode time out.
130  void SetSynchronousModeTimeOutInMiliSecond(const double time);
131 
132  /// Method to set hybrid physics mode.
133  void SetHybridPhysicsMode(const bool mode_switch);
134 
135  /// Method to set synchronous mode.
136  void SetSynchronousMode(const bool mode_switch = true);
137 
138  /// Method to set hybrid physics radius.
139  void SetHybridPhysicsRadius(const float radius);
140 
141  /// Method to set Open Street Map mode.
142  void SetOSMMode(const bool mode_switch);
143 
144  /// Method to set if we are automatically respawning vehicles.
145  void SetRespawnDormantVehicles(const bool mode_switch);
146 
147  /// Method to set boundaries for respawning vehicles.
148  void SetBoundariesRespawnDormantVehicles(const float lower_bound, const float upper_bound);
149 
150  /// Method to set limits for boundaries when respawning vehicles.
151  void SetMaxBoundaries(const float lower, const float upper);
152 
153  ///////////////////////////////// GETTERS /////////////////////////////////////
154 
155  /// Method to retrieve hybrid physics radius.
156  float GetHybridPhysicsRadius() const;
157 
158  /// Method to query target velocity for a vehicle.
159  float GetVehicleTargetVelocity(const ActorId &actor_id, const float speed_limit) const;
160 
161  /// Method to query collision avoidance rule between a pair of vehicles.
162  bool GetCollisionDetection(const ActorId &reference_actor_id, const ActorId &other_actor_id) const;
163 
164  /// Method to query lane change command for a vehicle.
165  ChangeLaneInfo GetForceLaneChange(const ActorId &actor_id);
166 
167  /// Method to query percentage probability of keep right rule for a vehicle.
168  float GetKeepRightPercentage(const ActorId &actor_id);
169 
170  /// Method to query auto lane change rule for a vehicle.
171  bool GetAutoLaneChange(const ActorId &actor_id) const;
172 
173  /// Method to query distance to leading vehicle for a given vehicle.
174  float GetDistanceToLeadingVehicle(const ActorId &actor_id) const;
175 
176  /// Method to get % to run any traffic light.
177  float GetPercentageRunningSign(const ActorId &actor_id) const;
178 
179  /// Method to get % to run any traffic light.
180  float GetPercentageRunningLight(const ActorId &actor_id) const;
181 
182  /// Method to get % to ignore any vehicle.
183  float GetPercentageIgnoreVehicles(const ActorId &actor_id) const;
184 
185  /// Method to get % to ignore any walker.
186  float GetPercentageIgnoreWalkers(const ActorId &actor_id) const;
187 
188  /// Method to get synchronous mode.
189  bool GetSynchronousMode() const;
190 
191  /// Get synchronous mode time out
192  double GetSynchronousModeTimeOutInMiliSecond() const;
193 
194  /// Method to retrieve hybrid physics mode.
195  bool GetHybridPhysicsMode() const;
196 
197  /// Method to retrieve if we are automatically respawning vehicles.
198  bool GetRespawnDormantVehicles() const;
199 
200  /// Method to retrieve minimum distance from hero vehicle when respawning vehicles.
201  float GetLowerBoundaryRespawnDormantVehicles() const;
202 
203  /// Method to retrieve maximum distance from hero vehicle when respawning vehicles.
204  float GetUpperBoundaryRespawnDormantVehicles() const;
205 
206  /// Method to get Open Street Map mode.
207  bool GetOSMMode() const;
208 
209  /// Synchronous mode time out variable.
210  std::chrono::duration<double, std::milli> synchronous_time_out;
211 };
212 
213 } // namespace traffic_manager
214 } // namespace carla
AtomicMap< ActorId, float > perc_run_traffic_sign
Map containing % of running a traffic sign.
Definition: Parameters.h:52
float min_lower_bound
Minimum possible distance to respawn vehicles with respect to the hero vehicle.
Definition: Parameters.h:72
carla::SharedPtr< cc::Actor > ActorPtr
rpc::ActorId ActorId
Definition: ActorId.h:18
AtomicMap< ActorId, bool > auto_lane_change
Map containing auto lane change commands.
Definition: Parameters.h:48
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
This file contains definitions of common data structures used in traffic manager. ...
Definition: Carla.cpp:133
std::chrono::duration< double, std::milli > synchronous_time_out
Synchronous mode time out variable.
Definition: Parameters.h:210
AtomicMap< ActorId, float > perc_run_traffic_light
Map containing % of running a traffic light.
Definition: Parameters.h:50
AtomicMap< ActorId, ChangeLaneInfo > force_lane_change
Map containing force lane change commands.
Definition: Parameters.h:46
float max_upper_bound
Maximum possible distance to respawn vehicles with respect to the hero vehicle.
Definition: Parameters.h:74
AtomicMap< ActorId, float > perc_keep_right
Map containing % of keep right rule.
Definition: Parameters.h:58
AtomicMap< ActorId, float > percentage_difference_from_speed_limit
Target velocity map for individual vehicles.
Definition: Parameters.h:38
carla::ActorId ActorId
AtomicMap< ActorId, float > distance_to_leading_vehicle
Map containing distance to leading vehicle command.
Definition: Parameters.h:44
AtomicMap< ActorId, float > perc_ignore_walkers
Map containing % of ignoring walkers.
Definition: Parameters.h:54
AtomicMap< ActorId, std::shared_ptr< AtomicActorSet > > ignore_collision
Map containing a set of actors to be ignored during collision detection.
Definition: Parameters.h:42
AtomicMap< ActorId, float > perc_ignore_vehicles
Map containing % of ignoring vehicles.
Definition: Parameters.h:56