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