CARLA
 
载入中...
搜索中...
未找到
Parameters.cpp
浏览该文件的文档.
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
9
10namespace carla {
11namespace traffic_manager {
12
14
15 /// Set default synchronous mode time out.
16 synchronous_time_out = std::chrono::duration<int, std::milli>(10);
17}
18
20
21//////////////////////////////////// SETTERS //////////////////////////////////
22
23void Parameters::SetHybridPhysicsMode(const bool mode_switch) {
24
25 hybrid_physics_mode.store(mode_switch);
26}
27
28void Parameters::SetRespawnDormantVehicles(const bool mode_switch) {
29
30 respawn_dormant_vehicles.store(mode_switch);
31}
32
33void Parameters::SetMaxBoundaries(const float lower, const float upper) {
34 min_lower_bound = lower;
35 max_upper_bound = upper;
36}
37
38void Parameters::SetBoundariesRespawnDormantVehicles(const float lower_bound, const float upper_bound) {
39 respawn_lower_bound = min_lower_bound > lower_bound ? min_lower_bound : lower_bound;
40 respawn_upper_bound = max_upper_bound < upper_bound ? max_upper_bound : upper_bound;
41}
42
43void Parameters::SetPercentageSpeedDifference(const ActorPtr &actor, const float percentage) {
44
45 float new_percentage = std::min(100.0f, percentage);
46 percentage_difference_from_speed_limit.AddEntry({actor->GetId(), new_percentage});
47 if (exact_desired_speed.Contains(actor->GetId())) {
48 exact_desired_speed.RemoveEntry(actor->GetId());
49 }
50}
51
52void Parameters::SetLaneOffset(const ActorPtr &actor, const float offset) {
53 const auto entry = std::make_pair(actor->GetId(), offset);
54 lane_offset.AddEntry(entry);
55}
56
57void Parameters::SetDesiredSpeed(const ActorPtr &actor, const float value) {
58
59 float new_value = std::max(0.0f, value);
60 exact_desired_speed.AddEntry({actor->GetId(), new_value});
63 }
64}
65
67 float new_percentage = std::min(100.0f, percentage);
69}
70
71void Parameters::SetGlobalLaneOffset(const float offset) {
72 global_lane_offset = offset;
73}
74
75void Parameters::SetCollisionDetection(const ActorPtr &reference_actor, const ActorPtr &other_actor, const bool detect_collision) {
76 const ActorId reference_id = reference_actor->GetId();
77 const ActorId other_id = other_actor->GetId();
78
79 if (detect_collision) {
80 if (ignore_collision.Contains(reference_id)) {
81 std::shared_ptr<AtomicActorSet> actor_set = ignore_collision.GetValue(reference_id);
82 if (actor_set->Contains(other_id)) {
83 actor_set->Remove({other_id});
84 }
85 }
86 } else {
87 if (ignore_collision.Contains(reference_id)) {
88 std::shared_ptr<AtomicActorSet> actor_set = ignore_collision.GetValue(reference_id);
89 if (!actor_set->Contains(other_id)) {
90 actor_set->Insert({other_actor});
91 }
92 } else {
93 std::shared_ptr<AtomicActorSet> actor_set = std::make_shared<AtomicActorSet>();
94 actor_set->Insert({other_actor});
95 auto entry = std::make_pair(reference_id, actor_set);
96 ignore_collision.AddEntry(entry);
97 }
98 }
99}
100
101void Parameters::SetForceLaneChange(const ActorPtr &actor, const bool direction) {
102
103 const ChangeLaneInfo lane_change_info = {true, direction};
104 const auto entry = std::make_pair(actor->GetId(), lane_change_info);
105 force_lane_change.AddEntry(entry);
106}
107
108void Parameters::SetKeepRightPercentage(const ActorPtr &actor, const float percentage) {
109
110 const auto entry = std::make_pair(actor->GetId(), percentage);
112}
113
114void Parameters::SetRandomLeftLaneChangePercentage(const ActorPtr &actor, const float percentage) {
115
116 const auto entry = std::make_pair(actor->GetId(), percentage);
118}
119
120void Parameters::SetRandomRightLaneChangePercentage(const ActorPtr &actor, const float percentage) {
121
122 const auto entry = std::make_pair(actor->GetId(), percentage);
124
125}
126
127void Parameters::SetUpdateVehicleLights(const ActorPtr &actor, const bool do_update) {
128
129 const auto entry = std::make_pair(actor->GetId(), do_update);
131}
132
133void Parameters::SetAutoLaneChange(const ActorPtr &actor, const bool enable) {
134
135 const auto entry = std::make_pair(actor->GetId(), enable);
137}
138
139void Parameters::SetDistanceToLeadingVehicle(const ActorPtr &actor, const float distance) {
140
141 float new_distance = std::max(0.0f, distance);
142 const auto entry = std::make_pair(actor->GetId(), new_distance);
144}
145
146void Parameters::SetSynchronousMode(const bool mode_switch) {
147 synchronous_mode.store(mode_switch);
148}
149
151 synchronous_time_out = std::chrono::duration<double, std::milli>(time);
152}
153
155
156 distance_margin.store(dist);
157}
158
159void Parameters::SetPercentageRunningLight(const ActorPtr &actor, const float perc) {
160
161 float new_perc = cg::Math::Clamp(perc, 0.0f, 100.0f);
162 const auto entry = std::make_pair(actor->GetId(), new_perc);
164}
165
166void Parameters::SetPercentageRunningSign(const ActorPtr &actor, const float perc) {
167
168 float new_perc = cg::Math::Clamp(perc, 0.0f, 100.0f);
169 const auto entry = std::make_pair(actor->GetId(), new_perc);
171}
172
173void Parameters::SetPercentageIgnoreVehicles(const ActorPtr &actor, const float perc) {
174
175 float new_perc = cg::Math::Clamp(perc, 0.0f, 100.0f);
176 const auto entry = std::make_pair(actor->GetId(), new_perc);
178}
179
180void Parameters::SetPercentageIgnoreWalkers(const ActorPtr &actor, const float perc) {
181
182 float new_perc = cg::Math::Clamp(perc,0.0f,100.0f);
183 const auto entry = std::make_pair(actor->GetId(), new_perc);
185}
186
187void Parameters::SetHybridPhysicsRadius(const float radius) {
188 float new_radius = std::max(radius, 0.0f);
189 hybrid_physics_radius.store(new_radius);
190}
191
192void Parameters::SetOSMMode(const bool mode_switch) {
193 osm_mode.store(mode_switch);
194}
195
196void Parameters::SetCustomPath(const ActorPtr &actor, const Path path, const bool empty_buffer) {
197 const auto entry = std::make_pair(actor->GetId(), path);
198 custom_path.AddEntry(entry);
199 const auto entry2 = std::make_pair(actor->GetId(), empty_buffer);
200 upload_path.AddEntry(entry2);
201}
202
203void Parameters::RemoveUploadPath(const ActorId &actor_id, const bool remove_path) {
204 if (!remove_path) {
205 upload_path.RemoveEntry(actor_id);
206 } else {
207 custom_path.RemoveEntry(actor_id);
208 }
209}
210
211void Parameters::UpdateUploadPath(const ActorId &actor_id, const Path path) {
212 custom_path.RemoveEntry(actor_id);
213 const auto entry = std::make_pair(actor_id, path);
214 custom_path.AddEntry(entry);
215}
216
217void Parameters::SetImportedRoute(const ActorPtr &actor, const Route route, const bool empty_buffer) {
218 const auto entry = std::make_pair(actor->GetId(), route);
219 custom_route.AddEntry(entry);
220 const auto entry2 = std::make_pair(actor->GetId(), empty_buffer);
221 upload_route.AddEntry(entry2);
222}
223
224void Parameters::RemoveImportedRoute(const ActorId &actor_id, const bool remove_path) {
225 if (!remove_path) {
226 upload_route.RemoveEntry(actor_id);
227 } else {
228 custom_route.RemoveEntry(actor_id);
229 }
230}
231
232void Parameters::UpdateImportedRoute(const ActorId &actor_id, const Route route) {
233 custom_route.RemoveEntry(actor_id);
234 const auto entry = std::make_pair(actor_id, route);
235 custom_route.AddEntry(entry);
236}
237
238//////////////////////////////////// GETTERS //////////////////////////////////
239
241
242 return hybrid_physics_radius.load();
243}
244
246 return synchronous_mode.load();
247}
248
252
253float Parameters::GetVehicleTargetVelocity(const ActorId &actor_id, const float speed_limit) const {
254
255 float percentage_difference = global_percentage_difference_from_limit;
256
258 percentage_difference = percentage_difference_from_speed_limit.GetValue(actor_id);
259 } else if (exact_desired_speed.Contains(actor_id)) {
260 return exact_desired_speed.GetValue(actor_id);
261 }
262
263 return speed_limit * (1.0f - percentage_difference / 100.0f);
264}
265
266float Parameters::GetLaneOffset(const ActorId &actor_id) const {
267 float offset = global_lane_offset;
268
269 if (lane_offset.Contains(actor_id)) {
270 offset = lane_offset.GetValue(actor_id);
271 }
272
273 return offset;
274}
275
276bool Parameters::GetCollisionDetection(const ActorId &reference_actor_id, const ActorId &other_actor_id) const {
277
278 bool avoid_collision = true;
279
280 if (ignore_collision.Contains(reference_actor_id) &&
281 ignore_collision.GetValue(reference_actor_id)->Contains(other_actor_id)) {
282 avoid_collision = false;
283 }
284
285 return avoid_collision;
286}
287
289
290 ChangeLaneInfo change_lane_info {false, false};
291
292 if (force_lane_change.Contains(actor_id)) {
293 change_lane_info = force_lane_change.GetValue(actor_id);
294 }
295
296 force_lane_change.RemoveEntry(actor_id);
297
298 return change_lane_info;
299}
300
302
303 float percentage = -1.0f;
304
305 if (perc_keep_right.Contains(actor_id)) {
306 percentage = perc_keep_right.GetValue(actor_id);
307 }
308
309 return percentage;
310}
311
313
314 float percentage = -1.0f;
315
316 if (perc_random_left.Contains(actor_id)) {
317 percentage = perc_random_left.GetValue(actor_id);
318 }
319
320 return percentage;
321}
322
324
325 float percentage = -1.0f;
326
327 if (perc_random_right.Contains(actor_id)) {
328 percentage = perc_random_right.GetValue(actor_id);
329 }
330
331 return percentage;
332}
333
334bool Parameters::GetAutoLaneChange(const ActorId &actor_id) const {
335
336 bool auto_lane_change_policy = true;
337
338 if (auto_lane_change.Contains(actor_id)) {
339 auto_lane_change_policy = auto_lane_change.GetValue(actor_id);
340 }
341
342 return auto_lane_change_policy;
343}
344
346
347 float specific_distance_margin = 0.0f;
349 specific_distance_margin = distance_to_leading_vehicle.GetValue(actor_id);
350 } else {
351 specific_distance_margin = distance_margin;
352 }
353
354 return specific_distance_margin;
355}
356
357float Parameters::GetPercentageRunningLight(const ActorId &actor_id) const {
358
359 float percentage = 0.0f;
360
361 if (perc_run_traffic_light.Contains(actor_id)) {
362 percentage = perc_run_traffic_light.GetValue(actor_id);
363 }
364
365 return percentage;
366}
367
368float Parameters::GetPercentageRunningSign(const ActorId &actor_id) const {
369
370 float percentage = 0.0f;
371
372 if (perc_run_traffic_sign.Contains(actor_id)) {
373 percentage = perc_run_traffic_sign.GetValue(actor_id);
374 }
375
376 return percentage;
377}
378
380
381 float percentage = 0.0f;
382
383 if (perc_ignore_walkers.Contains(actor_id)) {
384 percentage = perc_ignore_walkers.GetValue(actor_id);
385 }
386
387 return percentage;
388}
389
390bool Parameters::GetUpdateVehicleLights(const ActorId &actor_id) const {
391 bool do_update = false;
392
393 if (auto_update_vehicle_lights.Contains(actor_id)) {
394 do_update = auto_update_vehicle_lights.GetValue(actor_id);
395 }
396
397 return do_update;
398}
399
401
402 float percentage = 0.0f;
403
404 if (perc_ignore_vehicles.Contains(actor_id)) {
405 percentage = perc_ignore_vehicles.GetValue(actor_id);
406 }
407
408 return percentage;
409}
410
412
413 return hybrid_physics_mode.load();
414}
415
417
418 return respawn_dormant_vehicles.load();
419}
420
425
430
431
433
434 return osm_mode.load();
435}
436
437bool Parameters::GetUploadPath(const ActorId &actor_id) const {
438
439 bool custom_path_bool = false;
440
441 if (upload_path.Contains(actor_id)) {
442 custom_path_bool = upload_path.GetValue(actor_id);
443 }
444
445 return custom_path_bool;
446}
447
448Path Parameters::GetCustomPath(const ActorId &actor_id) const {
449
450 Path custom_path_import;
451
452 if (custom_path.Contains(actor_id)) {
453 custom_path_import = custom_path.GetValue(actor_id);
454 }
455
456 return custom_path_import;
457}
458
459
460bool Parameters::GetUploadRoute(const ActorId &actor_id) const {
461
462 bool custom_route_bool = false;
463
464 if (upload_route.Contains(actor_id)) {
465 custom_route_bool = upload_route.GetValue(actor_id);
466 }
467
468 return custom_route_bool;
469}
470
472
473 Route custom_route_import;
474
475 if (custom_route.Contains(actor_id)) {
476 custom_route_import = custom_route.GetValue(actor_id);
477 }
478
479 return custom_route_import;
480}
481
482
483} // namespace traffic_manager
484} // namespace carla
void RemoveEntry(const Key &key)
Definition AtomicMap.h:50
const Value & GetValue(const Key &key) const
Definition AtomicMap.h:44
bool Contains(const Key &key) const
Definition AtomicMap.h:38
void AddEntry(const std::pair< Key, Value > &entry)
Definition AtomicMap.h:27
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