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 #include <unordered_map>
13 
14 #include "carla/client/Actor.h"
15 #include "carla/client/Vehicle.h"
16 #include "carla/Memory.h"
17 #include "carla/rpc/ActorId.h"
18 
21 
22 namespace carla {
23 namespace traffic_manager {
24 
25 namespace cc = carla::client;
26 namespace cg = carla::geom;
28 using ActorId = carla::ActorId;
29 using Path = std::vector<cg::Location>;
30 using Route = std::vector<uint8_t>;
31 
33  bool change_lane = false;
34  bool direction = false;
35 };
36 
37 class Parameters {
38 
39 private:
40  /// Target velocity map for individual vehicles.
42  /// Global target velocity limit % difference.
43  float global_percentage_difference_from_limit = 0;
44  /// Map containing a set of actors to be ignored during collision detection.
46  /// Map containing distance to leading vehicle command.
48  /// Map containing force lane change commands.
50  /// Map containing auto lane change commands.
52  /// Map containing % of running a traffic light.
54  /// Map containing % of running a traffic sign.
56  /// Map containing % of ignoring walkers.
58  /// Map containing % of ignoring vehicles.
60  /// Map containing % of keep right rule.
62  /// Map containing % of random left lane change.
64  /// Map containing % of random right lane change.
66  /// Map containing the automatic vehicle lights update flag
68  /// Synchronous mode switch.
69  std::atomic<bool> synchronous_mode{false};
70  /// Distance margin
71  std::atomic<float> distance_margin{2.0};
72  /// Hybrid physics mode switch.
73  std::atomic<bool> hybrid_physics_mode{false};
74  /// Automatic respawn mode switch.
75  std::atomic<bool> respawn_dormant_vehicles{false};
76  /// Minimum distance to respawn vehicles with respect to the hero vehicle.
77  std::atomic<float> respawn_lower_bound{100.0};
78  /// Maximum distance to respawn vehicles with respect to the hero vehicle.
79  std::atomic<float> respawn_upper_bound{1000.0};
80  /// Minimum possible distance to respawn vehicles with respect to the hero vehicle.
82  /// Maximum possible distance to respawn vehicles with respect to the hero vehicle.
84  /// Hybrid physics radius.
85  std::atomic<float> hybrid_physics_radius {70.0};
86  /// Parameter specifying Open Street Map mode.
87  std::atomic<bool> osm_mode {true};
88  /// Parameter specifying if importing a custom path.
90  /// Structure to hold all custom paths.
92  /// Parameter specifying if importing a custom route.
94  /// Structure to hold all custom routes.
96 
97 public:
98  Parameters();
99  ~Parameters();
100 
101  ////////////////////////////////// SETTERS /////////////////////////////////////
102 
103  /// Set a vehicle's % decrease in velocity with respect to the speed limit.
104  /// If less than 0, it's a % increase.
105  void SetPercentageSpeedDifference(const ActorPtr &actor, const float percentage);
106 
107  /// Set a global % decrease in velocity with respect to the speed limit.
108  /// If less than 0, it's a % increase.
109  void SetGlobalPercentageSpeedDifference(float const percentage);
110 
111  /// Method to set collision detection rules between vehicles.
112  void SetCollisionDetection(
113  const ActorPtr &reference_actor,
114  const ActorPtr &other_actor,
115  const bool detect_collision);
116 
117  /// Method to force lane change on a vehicle.
118  /// Direction flag can be set to true for left and false for right.
119  void SetForceLaneChange(const ActorPtr &actor, const bool direction);
120 
121  /// Enable/disable automatic lane change on a vehicle.
122  void SetAutoLaneChange(const ActorPtr &actor, const bool enable);
123 
124  /// Method to specify how much distance a vehicle should maintain to
125  /// the leading vehicle.
126  void SetDistanceToLeadingVehicle(const ActorPtr &actor, const float distance);
127 
128  /// Method to set % to run any traffic sign.
129  void SetPercentageRunningSign(const ActorPtr &actor, const float perc);
130 
131  /// Method to set % to run any traffic light.
132  void SetPercentageRunningLight(const ActorPtr &actor, const float perc);
133 
134  /// Method to set % to ignore any vehicle.
135  void SetPercentageIgnoreVehicles(const ActorPtr &actor, const float perc);
136 
137  /// Method to set % to ignore any vehicle.
138  void SetPercentageIgnoreWalkers(const ActorPtr &actor, const float perc);
139 
140  /// Method to set % to keep on the right lane.
141  void SetKeepRightPercentage(const ActorPtr &actor, const float percentage);
142 
143  /// Method to set % to randomly do a left lane change.
144  void SetRandomLeftLaneChangePercentage(const ActorPtr &actor, const float percentage);
145 
146  /// Method to set % to randomly do a right lane change.
147  void SetRandomRightLaneChangePercentage(const ActorPtr &actor, const float percentage);
148 
149  /// Method to set the automatic vehicle light state update flag.
150  void SetUpdateVehicleLights(const ActorPtr &actor, const bool do_update);
151 
152  /// Method to set the distance to leading vehicle for all registered vehicles.
153  void SetGlobalDistanceToLeadingVehicle(const float dist);
154 
155  /// Set Synchronous mode time out.
156  void SetSynchronousModeTimeOutInMiliSecond(const double time);
157 
158  /// Method to set hybrid physics mode.
159  void SetHybridPhysicsMode(const bool mode_switch);
160 
161  /// Method to set synchronous mode.
162  void SetSynchronousMode(const bool mode_switch = true);
163 
164  /// Method to set hybrid physics radius.
165  void SetHybridPhysicsRadius(const float radius);
166 
167  /// Method to set Open Street Map mode.
168  void SetOSMMode(const bool mode_switch);
169 
170  /// Method to set if we are automatically respawning vehicles.
171  void SetRespawnDormantVehicles(const bool mode_switch);
172 
173  /// Method to set boundaries for respawning vehicles.
174  void SetBoundariesRespawnDormantVehicles(const float lower_bound, const float upper_bound);
175 
176  /// Method to set limits for boundaries when respawning vehicles.
177  void SetMaxBoundaries(const float lower, const float upper);
178 
179  /// Method to set our own imported path.
180  void SetCustomPath(const ActorPtr &actor, const Path path, const bool empty_buffer);
181 
182  /// Method to remove a list of points.
183  void RemoveUploadPath(const ActorId &actor_id, const bool remove_path);
184 
185  /// Method to update an already set list of points.
186  void UpdateUploadPath(const ActorId &actor_id, const Path path);
187 
188  /// Method to set our own imported route.
189  void SetImportedRoute(const ActorPtr &actor, const Route route, const bool empty_buffer);
190 
191  /// Method to remove a route.
192  void RemoveImportedRoute(const ActorId &actor_id, const bool remove_path);
193 
194  /// Method to update an already set route.
195  void UpdateImportedRoute(const ActorId &actor_id, const Route route);
196 
197  ///////////////////////////////// GETTERS /////////////////////////////////////
198 
199  /// Method to retrieve hybrid physics radius.
200  float GetHybridPhysicsRadius() const;
201 
202  /// Method to query target velocity for a vehicle.
203  float GetVehicleTargetVelocity(const ActorId &actor_id, const float speed_limit) const;
204 
205  /// Method to query collision avoidance rule between a pair of vehicles.
206  bool GetCollisionDetection(const ActorId &reference_actor_id, const ActorId &other_actor_id) const;
207 
208  /// Method to query lane change command for a vehicle.
209  ChangeLaneInfo GetForceLaneChange(const ActorId &actor_id);
210 
211  /// Method to query percentage probability of keep right rule for a vehicle.
212  float GetKeepRightPercentage(const ActorId &actor_id);
213 
214  /// Method to query percentage probability of a random right lane change for a vehicle.
215  float GetRandomLeftLaneChangePercentage(const ActorId &actor_id);
216 
217  /// Method to query percentage probability of a random left lane change for a vehicle.
218  float GetRandomRightLaneChangePercentage(const ActorId &actor_id);
219 
220  /// Method to query auto lane change rule for a vehicle.
221  bool GetAutoLaneChange(const ActorId &actor_id) const;
222 
223  /// Method to query distance to leading vehicle for a given vehicle.
224  float GetDistanceToLeadingVehicle(const ActorId &actor_id) const;
225 
226  /// Method to get % to run any traffic light.
227  float GetPercentageRunningSign(const ActorId &actor_id) const;
228 
229  /// Method to get % to run any traffic light.
230  float GetPercentageRunningLight(const ActorId &actor_id) const;
231 
232  /// Method to get % to ignore any vehicle.
233  float GetPercentageIgnoreVehicles(const ActorId &actor_id) const;
234 
235  /// Method to get % to ignore any walker.
236  float GetPercentageIgnoreWalkers(const ActorId &actor_id) const;
237 
238  /// Method to get if the vehicle lights should be updates automatically
239  bool GetUpdateVehicleLights(const ActorId &actor_id) const;
240 
241  /// Method to get synchronous mode.
242  bool GetSynchronousMode() const;
243 
244  /// Get synchronous mode time out
245  double GetSynchronousModeTimeOutInMiliSecond() const;
246 
247  /// Method to retrieve hybrid physics mode.
248  bool GetHybridPhysicsMode() const;
249 
250  /// Method to retrieve if we are automatically respawning vehicles.
251  bool GetRespawnDormantVehicles() const;
252 
253  /// Method to retrieve minimum distance from hero vehicle when respawning vehicles.
254  float GetLowerBoundaryRespawnDormantVehicles() const;
255 
256  /// Method to retrieve maximum distance from hero vehicle when respawning vehicles.
257  float GetUpperBoundaryRespawnDormantVehicles() const;
258 
259  /// Method to get Open Street Map mode.
260  bool GetOSMMode() const;
261 
262  /// Method to get if we are uploading a path.
263  bool GetUploadPath(const ActorId &actor_id) const;
264 
265  /// Method to get a custom path.
266  Path GetCustomPath(const ActorId &actor_id) const;
267 
268  /// Method to get if we are uploading a route.
269  bool GetUploadRoute(const ActorId &actor_id) const;
270 
271  /// Method to get a custom route.
272  Route GetImportedRoute(const ActorId &actor_id) const;
273 
274  /// Synchronous mode time out variable.
275  std::chrono::duration<double, std::milli> synchronous_time_out;
276 };
277 
278 } // namespace traffic_manager
279 } // namespace carla
AtomicMap< ActorId, float > perc_run_traffic_sign
Map containing % of running a traffic sign.
Definition: Parameters.h:55
AtomicMap< ActorId, bool > upload_route
Parameter specifying if importing a custom route.
Definition: Parameters.h:93
float min_lower_bound
Minimum possible distance to respawn vehicles with respect to the hero vehicle.
Definition: Parameters.h:81
carla::SharedPtr< cc::Actor > ActorPtr
AtomicMap< ActorId, float > perc_random_left
Map containing % of random left lane change.
Definition: Parameters.h:63
rpc::ActorId ActorId
Definition: ActorId.h:18
std::vector< cg::Location > Path
AtomicMap< ActorId, bool > auto_lane_change
Map containing auto lane change commands.
Definition: Parameters.h:51
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:275
AtomicMap< ActorId, float > perc_run_traffic_light
Map containing % of running a traffic light.
Definition: Parameters.h:53
AtomicMap< ActorId, ChangeLaneInfo > force_lane_change
Map containing force lane change commands.
Definition: Parameters.h:49
float max_upper_bound
Maximum possible distance to respawn vehicles with respect to the hero vehicle.
Definition: Parameters.h:83
AtomicMap< ActorId, float > perc_keep_right
Map containing % of keep right rule.
Definition: Parameters.h:61
AtomicMap< ActorId, Route > custom_route
Structure to hold all custom routes.
Definition: Parameters.h:95
AtomicMap< ActorId, float > percentage_difference_from_speed_limit
Target velocity map for individual vehicles.
Definition: Parameters.h:41
AtomicMap< ActorId, bool > auto_update_vehicle_lights
Map containing the automatic vehicle lights update flag.
Definition: Parameters.h:67
AtomicMap< ActorId, bool > upload_path
Parameter specifying if importing a custom path.
Definition: Parameters.h:89
AtomicMap< ActorId, Path > custom_path
Structure to hold all custom paths.
Definition: Parameters.h:91
carla::ActorId ActorId
AtomicMap< ActorId, float > distance_to_leading_vehicle
Map containing distance to leading vehicle command.
Definition: Parameters.h:47
std::vector< uint8_t > Route
AtomicMap< ActorId, float > perc_random_right
Map containing % of random right lane change.
Definition: Parameters.h:65
AtomicMap< ActorId, float > perc_ignore_walkers
Map containing % of ignoring walkers.
Definition: Parameters.h:57
AtomicMap< ActorId, std::shared_ptr< AtomicActorSet > > ignore_collision
Map containing a set of actors to be ignored during collision detection.
Definition: Parameters.h:45
AtomicMap< ActorId, float > perc_ignore_vehicles
Map containing % of ignoring vehicles.
Definition: Parameters.h:59