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  /// Hybrid physics radius.
66  std::atomic<float> hybrid_physics_radius {70.0};
67  /// Parameter specifying Open Street Map mode.
68  std::atomic<bool> osm_mode {true};
69 
70 public:
71  Parameters();
72  ~Parameters();
73 
74  ////////////////////////////////// SETTERS /////////////////////////////////////
75 
76  /// Set a vehicle's % decrease in velocity with respect to the speed limit.
77  /// If less than 0, it's a % increase.
78  void SetPercentageSpeedDifference(const ActorPtr &actor, const float percentage);
79 
80  /// Set a global % decrease in velocity with respect to the speed limit.
81  /// If less than 0, it's a % increase.
82  void SetGlobalPercentageSpeedDifference(float const percentage);
83 
84  /// Method to set collision detection rules between vehicles.
85  void SetCollisionDetection(
86  const ActorPtr &reference_actor,
87  const ActorPtr &other_actor,
88  const bool detect_collision);
89 
90  /// Method to force lane change on a vehicle.
91  /// Direction flag can be set to true for left and false for right.
92  void SetForceLaneChange(const ActorPtr &actor, const bool direction);
93 
94  /// Enable/disable automatic lane change on a vehicle.
95  void SetAutoLaneChange(const ActorPtr &actor, const bool enable);
96 
97  /// Method to specify how much distance a vehicle should maintain to
98  /// the leading vehicle.
99  void SetDistanceToLeadingVehicle(const ActorPtr &actor, const float distance);
100 
101  /// Method to set % to run any traffic sign.
102  void SetPercentageRunningSign(const ActorPtr &actor, const float perc);
103 
104  /// Method to set % to run any traffic light.
105  void SetPercentageRunningLight(const ActorPtr &actor, const float perc);
106 
107  /// Method to set % to ignore any vehicle.
108  void SetPercentageIgnoreVehicles(const ActorPtr &actor, const float perc);
109 
110  /// Method to set % to ignore any vehicle.
111  void SetPercentageIgnoreWalkers(const ActorPtr &actor, const float perc);
112 
113  /// Method to set probabilistic preference to keep on the right lane.
114  void SetKeepRightPercentage(const ActorPtr &actor, const float percentage);
115 
116  /// Method to set the distance to leading vehicle for all registered vehicles.
117  void SetGlobalDistanceToLeadingVehicle(const float dist);
118 
119  /// Set Synchronous mode time out.
120  void SetSynchronousModeTimeOutInMiliSecond(const double time);
121 
122  /// Method to set hybrid physics mode.
123  void SetHybridPhysicsMode(const bool mode_switch);
124 
125  /// Method to set synchronous mode.
126  void SetSynchronousMode(const bool mode_switch = true);
127 
128  /// Method to set hybrid physics radius.
129  void SetHybridPhysicsRadius(const float radius);
130 
131  /// Method to set Open Street Map mode.
132  void SetOSMMode(const bool mode_switch);
133 
134  ///////////////////////////////// GETTERS /////////////////////////////////////
135 
136  /// Method to retrieve hybrid physics radius.
137  float GetHybridPhysicsRadius() const;
138 
139  /// Method to query target velocity for a vehicle.
140  float GetVehicleTargetVelocity(const ActorId &actor_id, const float speed_limit) const;
141 
142  /// Method to query collision avoidance rule between a pair of vehicles.
143  bool GetCollisionDetection(const ActorId &reference_actor_id, const ActorId &other_actor_id) const;
144 
145  /// Method to query lane change command for a vehicle.
146  ChangeLaneInfo GetForceLaneChange(const ActorId &actor_id);
147 
148  /// Method to query percentage probability of keep right rule for a vehicle.
149  float GetKeepRightPercentage(const ActorId &actor_id);
150 
151  /// Method to query auto lane change rule for a vehicle.
152  bool GetAutoLaneChange(const ActorId &actor_id) const;
153 
154  /// Method to query distance to leading vehicle for a given vehicle.
155  float GetDistanceToLeadingVehicle(const ActorId &actor_id) const;
156 
157  /// Method to get % to run any traffic light.
158  float GetPercentageRunningSign(const ActorId &actor_id) const;
159 
160  /// Method to get % to run any traffic light.
161  float GetPercentageRunningLight(const ActorId &actor_id) const;
162 
163  /// Method to get % to ignore any vehicle.
164  float GetPercentageIgnoreVehicles(const ActorId &actor_id) const;
165 
166  /// Method to get % to ignore any walker.
167  float GetPercentageIgnoreWalkers(const ActorId &actor_id) const;
168 
169  /// Method to get synchronous mode.
170  bool GetSynchronousMode() const;
171 
172  /// Get synchronous mode time out
173  double GetSynchronousModeTimeOutInMiliSecond() const;
174 
175  /// Method to retrieve hybrid physics mode.
176  bool GetHybridPhysicsMode() const;
177 
178  /// Method to get Open Street Map mode.
179  bool GetOSMMode() const;
180 
181  /// Synchronous mode time out variable.
182  std::chrono::duration<double, std::milli> synchronous_time_out;
183 };
184 
185 } // namespace traffic_manager
186 } // namespace carla
AtomicMap< ActorId, float > perc_run_traffic_sign
Map containing % of running a traffic sign.
Definition: Parameters.h:52
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:99
std::chrono::duration< double, std::milli > synchronous_time_out
Synchronous mode time out variable.
Definition: Parameters.h:182
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
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