CARLA
 
载入中...
搜索中...
未找到
Parameters.h
浏览该文件的文档.
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"
16#include "carla/Memory.h"
17#include "carla/rpc/ActorId.h"
18
21
22namespace carla {
23namespace traffic_manager {
24
25namespace cc = carla::client;
26namespace cg = carla::geom;
29using Path = std::vector<cg::Location>;
30using Route = std::vector<uint8_t>;
31
33 bool change_lane = false;
34 bool direction = false;
35};
36
38
39private:
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.
48 /// Global lane offset
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
103public:
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.
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.
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
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.
275
276 /// Method to retrieve maximum distance from hero vehicle when respawning vehicles.
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
float GetRandomLeftLaneChangePercentage(const ActorId &actor_id)
Method to query percentage probability of a random right lane change for a vehicle.
std::atomic< float > respawn_lower_bound
Minimum distance to respawn vehicles with respect to the hero vehicle.
Definition Parameters.h:83
float GetPercentageIgnoreWalkers(const ActorId &actor_id) const
Method to get % to ignore any walker.
AtomicMap< ActorId, ChangeLaneInfo > force_lane_change
Map containing force lane change commands.
Definition Parameters.h:55
ChangeLaneInfo GetForceLaneChange(const ActorId &actor_id)
Method to query lane change command for a vehicle.
AtomicMap< ActorId, bool > auto_lane_change
Map containing auto lane change commands.
Definition Parameters.h:57
float GetLaneOffset(const ActorId &actor_id) const
Method to query lane offset for a vehicle.
AtomicMap< ActorId, bool > upload_path
Parameter specifying if importing a custom path.
Definition Parameters.h:95
void SetLaneOffset(const ActorPtr &actor, const float offset)
Method to set a lane offset displacement from the center line.
float GetDistanceToLeadingVehicle(const ActorId &actor_id) const
Method to query distance to leading vehicle for a given vehicle.
void SetImportedRoute(const ActorPtr &actor, const Route route, const bool empty_buffer)
Method to set our own imported route.
bool GetCollisionDetection(const ActorId &reference_actor_id, const ActorId &other_actor_id) const
Method to query collision avoidance rule between a pair of vehicles.
void SetHybridPhysicsRadius(const float radius)
Method to set hybrid physics radius.
Route GetImportedRoute(const ActorId &actor_id) const
Method to get a custom route.
float global_lane_offset
Global lane offset
Definition Parameters.h:49
float global_percentage_difference_from_limit
Global target velocity limit % difference.
Definition Parameters.h:47
std::atomic< bool > synchronous_mode
Synchronous mode switch.
Definition Parameters.h:75
double GetSynchronousModeTimeOutInMiliSecond() const
Get synchronous mode time out
std::atomic< float > distance_margin
Distance margin
Definition Parameters.h:77
std::chrono::duration< double, std::milli > synchronous_time_out
Synchronous mode time out variable.
Definition Parameters.h:295
std::atomic< float > hybrid_physics_radius
Hybrid physics radius.
Definition Parameters.h:91
bool GetUploadRoute(const ActorId &actor_id) const
Method to get if we are uploading a route.
void UpdateUploadPath(const ActorId &actor_id, const Path path)
Method to update an already set list of points.
float GetKeepRightPercentage(const ActorId &actor_id)
Method to query percentage probability of keep right rule for a vehicle.
bool GetOSMMode() const
Method to get Open Street Map mode.
void SetRandomLeftLaneChangePercentage(const ActorPtr &actor, const float percentage)
Method to set % to randomly do a left lane change.
void SetGlobalDistanceToLeadingVehicle(const float dist)
Method to set the distance to leading vehicle for all registered vehicles.
AtomicMap< ActorId, float > perc_random_left
Map containing % of random left lane change.
Definition Parameters.h:69
AtomicMap< ActorId, float > perc_keep_right
Map containing % of keep right rule.
Definition Parameters.h:67
AtomicMap< ActorId, float > perc_ignore_walkers
Map containing % of ignoring walkers.
Definition Parameters.h:63
float GetHybridPhysicsRadius() const
Method to retrieve hybrid physics radius.
void UpdateImportedRoute(const ActorId &actor_id, const Route route)
Method to update an already set route.
float GetVehicleTargetVelocity(const ActorId &actor_id, const float speed_limit) const
Method to query target velocity for a vehicle.
void SetGlobalLaneOffset(float const offset)
Method to set a global lane offset displacement from the center line.
AtomicMap< ActorId, float > exact_desired_speed
Target velocity map for individual vehicles, based on a desired velocity.
Definition Parameters.h:45
AtomicMap< ActorId, bool > upload_route
Parameter specifying if importing a custom route.
Definition Parameters.h:99
bool GetUploadPath(const ActorId &actor_id) const
Method to get if we are uploading a path.
float min_lower_bound
Minimum possible distance to respawn vehicles with respect to the hero vehicle.
Definition Parameters.h:87
void SetDistanceToLeadingVehicle(const ActorPtr &actor, const float distance)
Method to specify how much distance a vehicle should maintain to the leading vehicle.
float GetUpperBoundaryRespawnDormantVehicles() const
Method to retrieve maximum distance from hero vehicle when respawning vehicles.
float GetRandomRightLaneChangePercentage(const ActorId &actor_id)
Method to query percentage probability of a random left lane change for a vehicle.
void SetForceLaneChange(const ActorPtr &actor, const bool direction)
Method to force lane change on a vehicle.
AtomicMap< ActorId, float > perc_run_traffic_light
Map containing % of running a traffic light.
Definition Parameters.h:59
float GetLowerBoundaryRespawnDormantVehicles() const
Method to retrieve minimum distance from hero vehicle when respawning vehicles.
void SetPercentageRunningSign(const ActorPtr &actor, const float perc)
Method to set % to run any traffic sign.
void SetCustomPath(const ActorPtr &actor, const Path path, const bool empty_buffer)
Method to set our own imported path.
std::atomic< bool > hybrid_physics_mode
Hybrid physics mode switch.
Definition Parameters.h:79
void RemoveImportedRoute(const ActorId &actor_id, const bool remove_path)
Method to remove a route.
bool GetAutoLaneChange(const ActorId &actor_id) const
Method to query auto lane change rule for a vehicle.
void SetPercentageIgnoreVehicles(const ActorPtr &actor, const float perc)
Method to set % to ignore any vehicle.
void SetKeepRightPercentage(const ActorPtr &actor, const float percentage)
Method to set % to keep on the right lane.
void SetMaxBoundaries(const float lower, const float upper)
Method to set limits for boundaries when respawning vehicles.
void SetSynchronousModeTimeOutInMiliSecond(const double time)
Set Synchronous mode time out.
void SetHybridPhysicsMode(const bool mode_switch)
Method to set hybrid physics mode.
AtomicMap< ActorId, float > perc_random_right
Map containing % of random right lane change.
Definition Parameters.h:71
float GetPercentageRunningSign(const ActorId &actor_id) const
Method to get % to run any traffic light.
void SetCollisionDetection(const ActorPtr &reference_actor, const ActorPtr &other_actor, const bool detect_collision)
Method to set collision detection rules between vehicles.
bool GetRespawnDormantVehicles() const
Method to retrieve if we are automatically respawning vehicles.
AtomicMap< ActorId, std::shared_ptr< AtomicActorSet > > ignore_collision
Map containing a set of actors to be ignored during collision detection.
Definition Parameters.h:51
void SetPercentageRunningLight(const ActorPtr &actor, const float perc)
Method to set % to run any traffic light.
AtomicMap< ActorId, float > perc_run_traffic_sign
Map containing % of running a traffic sign.
Definition Parameters.h:61
void SetRespawnDormantVehicles(const bool mode_switch)
Method to set if we are automatically respawning vehicles.
std::atomic< bool > osm_mode
Parameter specifying Open Street Map mode.
Definition Parameters.h:93
Path GetCustomPath(const ActorId &actor_id) const
Method to get a custom path.
void SetAutoLaneChange(const ActorPtr &actor, const bool enable)
Enable/disable automatic lane change on a vehicle.
AtomicMap< ActorId, float > distance_to_leading_vehicle
Map containing distance to leading vehicle command.
Definition Parameters.h:53
float GetPercentageIgnoreVehicles(const ActorId &actor_id) const
Method to get % to ignore any vehicle.
void SetDesiredSpeed(const ActorPtr &actor, const float value)
Set a vehicle's exact desired velocity.
void RemoveUploadPath(const ActorId &actor_id, const bool remove_path)
Method to remove a list of points.
bool GetSynchronousMode() const
Method to get synchronous mode.
void SetGlobalPercentageSpeedDifference(float const percentage)
Set a global % decrease in velocity with respect to the speed limit.
std::atomic< bool > respawn_dormant_vehicles
Automatic respawn mode switch.
Definition Parameters.h:81
AtomicMap< ActorId, float > lane_offset
Lane offset map for individual vehicles.
Definition Parameters.h:43
void SetPercentageIgnoreWalkers(const ActorPtr &actor, const float perc)
Method to set % to ignore any vehicle.
float GetPercentageRunningLight(const ActorId &actor_id) const
Method to get % to run any traffic light.
void SetBoundariesRespawnDormantVehicles(const float lower_bound, const float upper_bound)
Method to set boundaries for respawning vehicles.
bool GetUpdateVehicleLights(const ActorId &actor_id) const
Method to get if the vehicle lights should be updates automatically
void SetRandomRightLaneChangePercentage(const ActorPtr &actor, const float percentage)
Method to set % to randomly do a right lane change.
void SetPercentageSpeedDifference(const ActorPtr &actor, const float percentage)
Set a vehicle's % decrease in velocity with respect to the speed limit.
AtomicMap< ActorId, bool > auto_update_vehicle_lights
Map containing the automatic vehicle lights update flag
Definition Parameters.h:73
std::atomic< float > respawn_upper_bound
Maximum distance to respawn vehicles with respect to the hero vehicle.
Definition Parameters.h:85
AtomicMap< ActorId, Route > custom_route
Structure to hold all custom routes.
Definition Parameters.h:101
AtomicMap< ActorId, float > perc_ignore_vehicles
Map containing % of ignoring vehicles.
Definition Parameters.h:65
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
void SetOSMMode(const bool mode_switch)
Method to set Open Street Map mode.
AtomicMap< ActorId, Path > custom_path
Structure to hold all custom paths.
Definition Parameters.h:97
bool GetHybridPhysicsMode() const
Method to retrieve hybrid physics mode.
void SetSynchronousMode(const bool mode_switch=true)
Method to set synchronous mode.
void SetUpdateVehicleLights(const ActorPtr &actor, const bool do_update)
Method to set the automatic vehicle light state update flag.
float max_upper_bound
Maximum possible distance to respawn vehicles with respect to the hero vehicle.
Definition Parameters.h:89
carla::SharedPtr< cc::Actor > ActorPtr
std::vector< uint8_t > Route
std::vector< cg::Location > Path
This file contains definitions of common data structures used in traffic manager.
Definition Carla.cpp:133
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
rpc::ActorId ActorId
Definition ActorId.h:18