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/// 包含Carla客户端相关的头文件
14#include "carla/client/Actor.h"
16#include "carla/Memory.h"/// 包含Carla内存管理相关的头文件
17#include "carla/rpc/ActorId.h"/// 包含Carla Rpc 通信相关的头文件,定义了参与者的唯一标识符
18
19#include "carla/trafficmanager/AtomicActorSet.h"/// 包含Carla交通管理器的相关头文件
21
22namespace carla {
23 namespace traffic_manager {
24 /// 使用别名简化代码中的命名
25 namespace cc = carla::client;
26 namespace cg = carla::geom;
27 using ActorPtr = carla::SharedPtr<cc::Actor>;/// 参与者的智能指针类型
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 /// 基于速度限制差异的单个车辆目标速度映射
42 /// 单个车辆的车道偏移映射
44 /// 基于期望速度的单个车辆目标速度映射
46 /// 全局目标速度限制差异百分比
48 /// 全局车道偏移
50 /// 在碰撞检测期间要忽略的演员集合映射
52 /// 到前导车辆的距离映射
54 /// 强制换道命令映射
56 /// 自动换道命令映射
58 /// 闯交通信号灯百分比映射
60 /// 闯交通标志百分比映射
62 /// 忽略行人百分比映射
64 /// 忽略车辆百分比映射
66 /// 靠右行驶规则百分比映射
68 /// 随机左换道百分比映射
70 /// 随机右换道百分比映射
72 /// 车辆灯光自动更新标志映射
74 /// 同步开关
75 std::atomic<bool> synchronous_mode{ false };
76 /// 距离边距
77 std::atomic<float> distance_margin{ 2.0 };
78 /// 混合物理模式开关
79 std::atomic<bool> hybrid_physics_mode{ false };
80 /// 自动重生模式开关
81 std::atomic<bool> respawn_dormant_vehicles{ false };
82 /// 相对于主角车辆的最小重生距离
83 std::atomic<float> respawn_lower_bound{ 100.0 };
84 /// 相对于主角车辆的最大重生距离
85 std::atomic<float> respawn_upper_bound{ 1000.0 };
86 /// 相对于主角车辆的最小可能重生距离
88 /// 相对于主角车辆的最大可能重生距离
90 /// 混合物理半径
91 std::atomic<float> hybrid_physics_radius{ 70.0 };
92 /// Open Street Map模式参数
93 std::atomic<bool> osm_mode{ true };
94 /// 是否导入自定义路径的参数映射
96 /// 存储所有自定义路径的结构
98 /// 是否导入自定义路线的参数映射
100 /// 存储所有自定义路线的结构
102
103 public:
104 /// 构造函数
105 Parameters();
106 /// 析构函数
107 ~Parameters();
108
109 ////////////////////////////////// SETTERS /////////////////////////////////////
110
111 /// 设置车辆相对于速度限制的速度降低百分比
112 /// 如果小于0,则表示速度增加百分比
113 void SetPercentageSpeedDifference(const ActorPtr& actor, const float percentage);
114
115 /// 设置车道偏移量,从中心线开始的位移
116 /// 正值表示向右偏移,负值表示向左偏移
117 void SetLaneOffset(const ActorPtr& actor, const float offset);
118
119 /// 设置车辆的精确期望速度
120 void SetDesiredSpeed(const ActorPtr& actor, const float value);
121
122 /// 设置全局相对于速度限制的速度降低百分比
123 /// 如果小于0,则表示速度增加百分比
124 void SetGlobalPercentageSpeedDifference(float const percentage);
125
126 /// 设置全局车道偏移量,从中心线开始的位移
127 /// 正值表示向右偏移,负值表示向左偏移
128 void SetGlobalLaneOffset(float const offset);
129
130 /// 设置车辆之间的碰撞检测规则的方法
132 const ActorPtr& reference_actor, ///<参考车辆指针
133 const ActorPtr& other_actor, ///<另一车辆指针
134 const bool detect_collision); ///<是否碰撞的布尔值
135
136 /// 强制车辆换道的方法
137 /// 方向标志可以设置为true表示向左,false表示向右
138 void SetForceLaneChange(const ActorPtr& actor, const bool direction);///<车辆指针和方向布尔值
139
140 /// 启用/禁用车辆的自动换道功能
141 void SetAutoLaneChange(const ActorPtr& actor, const bool enable);///<车辆指针和启用或禁用的布尔值
142
143 /// 设置车辆应保持与前车距离的方法
144 void SetDistanceToLeadingVehicle(const ActorPtr& actor, const float distance);///<车辆指针和应保持的距离值
145
146 /// 设置无视交通标志的概率的方法
147 void SetPercentageRunningSign(const ActorPtr& actor, const float perc);///<车辆指针和无视标志的概率值
148
149 /// 设置无视交通信号灯的概率的方法
150 void SetPercentageRunningLight(const ActorPtr& actor, const float perc);///<车辆指针和无视信号灯的概率值
151
152 /// 设置无视其他车辆的概率的方法
153 void SetPercentageIgnoreVehicles(const ActorPtr& actor, const float perc);///<车辆指针和无视车辆的概率值
154
155 /// 设置无视其他车辆的概率的方法
156 void SetPercentageIgnoreWalkers(const ActorPtr& actor, const float perc);///<车辆指针和无视车辆的概率值
157
158 /// 设置强制靠右行驶的概率的方法
159 void SetKeepRightPercentage(const ActorPtr& actor, const float percentage);///<车辆指针和保持靠右行驶的概率值
160
161 /// 设置随机向左换道的概率的方法
162 void SetRandomLeftLaneChangePercentage(const ActorPtr& actor, const float percentage);///<车辆指针和随机向左换道的概率值
163
164 /// 设置随机向右换道的概率的方法
165 void SetRandomRightLaneChangePercentage(const ActorPtr& actor, const float percentage);///<车辆指针和随机向右换道的概率值
166
167 /// 设置是否自动更新车辆灯光状态的方法
168 void SetUpdateVehicleLights(const ActorPtr& actor, const bool do_update);///<车辆指针和是否更新的布尔值
169
170 /// 设置所有注册车辆应保持与前车的距离的方法
171 void SetGlobalDistanceToLeadingVehicle(const float dist);///< 所有车辆应保持的距离值
172
173 /// 设置同步模式超时时间
174 void SetSynchronousModeTimeOutInMiliSecond(const double time);///< 超时时间值
175
176 /// 设置混合物理模式的方法
177 void SetHybridPhysicsMode(const bool mode_switch);///< 是否启用混合物理模式的布尔值
178
179 /// 设置同步模式的方法
180 void SetSynchronousMode(const bool mode_switch = true);///< 是否启用同步模式的布尔值,默认启用
181
182 /// 设置混合物理半径的方法
183 void SetHybridPhysicsRadius(const float radius);///< 混合物理半径值
184
185 /// 设置Open Street Map模式的方法
186 void SetOSMMode(const bool mode_switch);///< 是否启用OSM模式的布尔值
187
188 /// 设置是否自动重生休眠车辆的方法
189 void SetRespawnDormantVehicles(const bool mode_switch); ///< 是否启用的布尔值
190
191 /// 设置重生休眠车辆的边界的方法
192 void SetBoundariesRespawnDormantVehicles(const float lower_bound, const float upper_bound);///< 下边界值和下边界值
193
194 /// 设置重生休眠车辆时的边界限制的方法
195 void SetMaxBoundaries(const float lower, const float upper);///< 下限值和下限值
196
197 /// 设置自定义路径的方法
198 void SetCustomPath(const ActorPtr& actor, const Path path, const bool empty_buffer);///< 车辆指针,路径数据和是否清空缓冲区的布尔值
199
200 /// 移除一组点的方法
201 void RemoveUploadPath(const ActorId& actor_id, const bool remove_path);///< 车辆ID和是否移除的布尔值
202
203 /// 更新已设置的点列表的方法
204 void UpdateUploadPath(const ActorId& actor_id, const Path path);///< 车辆ID和新的路径数据
205
206 /// 设置自定义路线的方法
207 void SetImportedRoute(const ActorPtr& actor, const Route route, const bool empty_buffer);///< 车辆指针,路线数据和是否清空缓冲区的布尔值
208
209 /// 移除路线的方法
210 void RemoveImportedRoute(const ActorId& actor_id, const bool remove_path);///<车辆ID和是否移除的布尔值
211
212 /// 更新已设置路线的方法
213 void UpdateImportedRoute(const ActorId& actor_id, const Route route);///< 车辆ID和新的路线数据
214
215 ///////////////////////////////// 获取器 /////////////////////////////////////
216
217 /// 获取混合物理半径的方法
218 float GetHybridPhysicsRadius() const;
219
220 /// 查询车辆目标速度的方法
221 float GetVehicleTargetVelocity(const ActorId& actor_id, const float speed_limit) const;
222
223 /// 查询车辆车道偏移量的方法
224 float GetLaneOffset(const ActorId& actor_id) const;
225
226 /// 查询一对车辆之间避碰规则的方法
227 bool GetCollisionDetection(const ActorId& reference_actor_id, const ActorId& other_actor_id) const;
228
229 ///查询车辆变道指令的方法
231
232 /// 查询车辆保持右侧规则的百分比概率的方法
233 float GetKeepRightPercentage(const ActorId& actor_id);
234
235 /// 查询车辆随机右变道百分比概率的方法
236 float GetRandomLeftLaneChangePercentage(const ActorId& actor_id);
237
238 ///查询车辆随机向左变道百分比概率的方法
239 float GetRandomRightLaneChangePercentage(const ActorId& actor_id);
240
241 /// 查询车辆自动变道规则的方法
242 bool GetAutoLaneChange(const ActorId& actor_id) const;
243
244 /// 查询给定车辆与前方车辆之间距离的方法
245 float GetDistanceToLeadingVehicle(const ActorId& actor_id) const;
246
247 /// 获取百分比以运行任何交通灯的方法
248 float GetPercentageRunningSign(const ActorId& actor_id) const;
249
250 /// 获取百分比以运行任何交通灯的方法
251 float GetPercentageRunningLight(const ActorId& actor_id) const;
252
253 /// 方法获取百分比以忽略任何车辆
254 float GetPercentageIgnoreVehicles(const ActorId& actor_id) const;
255
256 ///获取百分比以忽略任何步行者的方法
257 float GetPercentageIgnoreWalkers(const ActorId& actor_id) const;
258
259 /// 获取车辆灯光是否应自动更新的方法
260 bool GetUpdateVehicleLights(const ActorId& actor_id) const;
261
262 /// 获取同步模式的方法
263 bool GetSynchronousMode() const;
264
265 /// 获取同步模式超时
267
268 /// 获取混合物理模式的方法
269 bool GetHybridPhysicsMode() const;
270
271 /// 获取是否自动重生载具的方法
272 bool GetRespawnDormantVehicles() const;
273
274 /// 获取车辆重生时与英雄车辆之间最小距离的方法
276
277 /// 获取车辆重生时与英雄车辆之间最大距离的方法
279
280 /// 获取Open Street Map模式的方法
281 bool GetOSMMode() const;
282
283 /// 获取是否正在上传路径的方法
284 bool GetUploadPath(const ActorId& actor_id) const;
285
286 /// 获取自定义路径的方法
287 Path GetCustomPath(const ActorId& actor_id) const;
288
289 /// 获取是否正在上传路线的方法
290 bool GetUploadRoute(const ActorId& actor_id) const;
291
292 /// 获取自定义路由的方法
293 Route GetImportedRoute(const ActorId& actor_id) const;
294
295 /// 同步模式超时变量
296 std::chrono::duration<double, std::milli> synchronous_time_out;
297 };
298
299 } // namespace traffic_manager
300} // namespace carla
一个线程安全的、基于unordered_map的原子映射类。
Definition AtomicMap.h:28
float GetRandomLeftLaneChangePercentage(const ActorId &actor_id)
查询车辆随机右变道百分比概率的方法
std::atomic< float > respawn_lower_bound
相对于主角车辆的最小重生距离
Definition Parameters.h:83
float GetPercentageIgnoreWalkers(const ActorId &actor_id) const
获取百分比以忽略任何步行者的方法
AtomicMap< ActorId, ChangeLaneInfo > force_lane_change
强制换道命令映射
Definition Parameters.h:55
ChangeLaneInfo GetForceLaneChange(const ActorId &actor_id)
查询车辆变道指令的方法
AtomicMap< ActorId, bool > auto_lane_change
自动换道命令映射
Definition Parameters.h:57
float GetLaneOffset(const ActorId &actor_id) const
查询车辆车道偏移量的方法
AtomicMap< ActorId, bool > upload_path
是否导入自定义路径的参数映射
Definition Parameters.h:95
void SetLaneOffset(const ActorPtr &actor, const float offset)
设置车道偏移量,从中心线开始的位移 正值表示向右偏移,负值表示向左偏移
float GetDistanceToLeadingVehicle(const ActorId &actor_id) const
查询给定车辆与前方车辆之间距离的方法
void SetImportedRoute(const ActorPtr &actor, const Route route, const bool empty_buffer)
设置自定义路线的方法
bool GetCollisionDetection(const ActorId &reference_actor_id, const ActorId &other_actor_id) const
查询一对车辆之间避碰规则的方法
void SetHybridPhysicsRadius(const float radius)
设置混合物理半径的方法
Route GetImportedRoute(const ActorId &actor_id) const
获取自定义路由的方法
float global_lane_offset
全局车道偏移
Definition Parameters.h:49
float global_percentage_difference_from_limit
全局目标速度限制差异百分比
Definition Parameters.h:47
std::atomic< bool > synchronous_mode
同步开关
Definition Parameters.h:75
double GetSynchronousModeTimeOutInMiliSecond() const
获取同步模式超时
std::atomic< float > distance_margin
距离边距
Definition Parameters.h:77
std::chrono::duration< double, std::milli > synchronous_time_out
同步模式超时变量
Definition Parameters.h:296
std::atomic< float > hybrid_physics_radius
混合物理半径
Definition Parameters.h:91
bool GetUploadRoute(const ActorId &actor_id) const
获取是否正在上传路线的方法
void UpdateUploadPath(const ActorId &actor_id, const Path path)
更新已设置的点列表的方法
float GetKeepRightPercentage(const ActorId &actor_id)
查询车辆保持右侧规则的百分比概率的方法
bool GetOSMMode() const
获取Open Street Map模式的方法
void SetRandomLeftLaneChangePercentage(const ActorPtr &actor, const float percentage)
设置随机向左换道的概率的方法
void SetGlobalDistanceToLeadingVehicle(const float dist)
设置所有注册车辆应保持与前车的距离的方法
AtomicMap< ActorId, float > perc_random_left
随机左换道百分比映射
Definition Parameters.h:69
AtomicMap< ActorId, float > perc_keep_right
靠右行驶规则百分比映射
Definition Parameters.h:67
AtomicMap< ActorId, float > perc_ignore_walkers
忽略行人百分比映射
Definition Parameters.h:63
float GetHybridPhysicsRadius() const
获取混合物理半径的方法
void UpdateImportedRoute(const ActorId &actor_id, const Route route)
更新已设置路线的方法
float GetVehicleTargetVelocity(const ActorId &actor_id, const float speed_limit) const
查询车辆目标速度的方法
void SetGlobalLaneOffset(float const offset)
设置全局车道偏移量,从中心线开始的位移 正值表示向右偏移,负值表示向左偏移
AtomicMap< ActorId, float > exact_desired_speed
基于期望速度的单个车辆目标速度映射
Definition Parameters.h:45
AtomicMap< ActorId, bool > upload_route
是否导入自定义路线的参数映射
Definition Parameters.h:99
bool GetUploadPath(const ActorId &actor_id) const
获取是否正在上传路径的方法
float min_lower_bound
相对于主角车辆的最小可能重生距离
Definition Parameters.h:87
void SetDistanceToLeadingVehicle(const ActorPtr &actor, const float distance)
设置车辆应保持与前车距离的方法
float GetUpperBoundaryRespawnDormantVehicles() const
获取车辆重生时与英雄车辆之间最大距离的方法
float GetRandomRightLaneChangePercentage(const ActorId &actor_id)
查询车辆随机向左变道百分比概率的方法
void SetForceLaneChange(const ActorPtr &actor, const bool direction)
强制车辆换道的方法 方向标志可以设置为true表示向左,false表示向右
AtomicMap< ActorId, float > perc_run_traffic_light
闯交通信号灯百分比映射
Definition Parameters.h:59
float GetLowerBoundaryRespawnDormantVehicles() const
获取车辆重生时与英雄车辆之间最小距离的方法
void SetPercentageRunningSign(const ActorPtr &actor, const float perc)
设置无视交通标志的概率的方法
void SetCustomPath(const ActorPtr &actor, const Path path, const bool empty_buffer)
设置自定义路径的方法
std::atomic< bool > hybrid_physics_mode
混合物理模式开关
Definition Parameters.h:79
void RemoveImportedRoute(const ActorId &actor_id, const bool remove_path)
移除路线的方法
bool GetAutoLaneChange(const ActorId &actor_id) const
查询车辆自动变道规则的方法
void SetPercentageIgnoreVehicles(const ActorPtr &actor, const float perc)
设置无视其他车辆的概率的方法
void SetKeepRightPercentage(const ActorPtr &actor, const float percentage)
设置强制靠右行驶的概率的方法
void SetMaxBoundaries(const float lower, const float upper)
设置重生休眠车辆时的边界限制的方法
void SetSynchronousModeTimeOutInMiliSecond(const double time)
设置同步模式超时时间
void SetHybridPhysicsMode(const bool mode_switch)
设置混合物理模式的方法
AtomicMap< ActorId, float > perc_random_right
随机右换道百分比映射
Definition Parameters.h:71
float GetPercentageRunningSign(const ActorId &actor_id) const
获取百分比以运行任何交通灯的方法
void SetCollisionDetection(const ActorPtr &reference_actor, const ActorPtr &other_actor, const bool detect_collision)
设置车辆之间的碰撞检测规则的方法
bool GetRespawnDormantVehicles() const
获取是否自动重生载具的方法
AtomicMap< ActorId, std::shared_ptr< AtomicActorSet > > ignore_collision
在碰撞检测期间要忽略的演员集合映射
Definition Parameters.h:51
void SetPercentageRunningLight(const ActorPtr &actor, const float perc)
设置无视交通信号灯的概率的方法
AtomicMap< ActorId, float > perc_run_traffic_sign
闯交通标志百分比映射
Definition Parameters.h:61
void SetRespawnDormantVehicles(const bool mode_switch)
设置是否自动重生休眠车辆的方法
std::atomic< bool > osm_mode
Open Street Map模式参数
Definition Parameters.h:93
Path GetCustomPath(const ActorId &actor_id) const
获取自定义路径的方法
void SetAutoLaneChange(const ActorPtr &actor, const bool enable)
启用/禁用车辆的自动换道功能
AtomicMap< ActorId, float > distance_to_leading_vehicle
到前导车辆的距离映射
Definition Parameters.h:53
float GetPercentageIgnoreVehicles(const ActorId &actor_id) const
方法获取百分比以忽略任何车辆
void SetDesiredSpeed(const ActorPtr &actor, const float value)
设置车辆的精确期望速度
void RemoveUploadPath(const ActorId &actor_id, const bool remove_path)
移除一组点的方法
bool GetSynchronousMode() const
获取同步模式的方法
void SetGlobalPercentageSpeedDifference(float const percentage)
设置全局相对于速度限制的速度降低百分比 如果小于0,则表示速度增加百分比
std::atomic< bool > respawn_dormant_vehicles
自动重生模式开关
Definition Parameters.h:81
AtomicMap< ActorId, float > lane_offset
单个车辆的车道偏移映射
Definition Parameters.h:43
void SetPercentageIgnoreWalkers(const ActorPtr &actor, const float perc)
设置无视其他车辆的概率的方法
float GetPercentageRunningLight(const ActorId &actor_id) const
获取百分比以运行任何交通灯的方法
void SetBoundariesRespawnDormantVehicles(const float lower_bound, const float upper_bound)
设置重生休眠车辆的边界的方法
bool GetUpdateVehicleLights(const ActorId &actor_id) const
获取车辆灯光是否应自动更新的方法
void SetRandomRightLaneChangePercentage(const ActorPtr &actor, const float percentage)
设置随机向右换道的概率的方法
void SetPercentageSpeedDifference(const ActorPtr &actor, const float percentage)
设置车辆相对于速度限制的速度降低百分比 如果小于0,则表示速度增加百分比
AtomicMap< ActorId, bool > auto_update_vehicle_lights
车辆灯光自动更新标志映射
Definition Parameters.h:73
std::atomic< float > respawn_upper_bound
相对于主角车辆的最大重生距离
Definition Parameters.h:85
AtomicMap< ActorId, Route > custom_route
存储所有自定义路线的结构
Definition Parameters.h:101
AtomicMap< ActorId, float > perc_ignore_vehicles
忽略车辆百分比映射
Definition Parameters.h:65
AtomicMap< ActorId, float > percentage_difference_from_speed_limit
基于速度限制差异的单个车辆目标速度映射
Definition Parameters.h:41
void SetOSMMode(const bool mode_switch)
设置Open Street Map模式的方法
AtomicMap< ActorId, Path > custom_path
存储所有自定义路径的结构
Definition Parameters.h:97
bool GetHybridPhysicsMode() const
获取混合物理模式的方法
void SetSynchronousMode(const bool mode_switch=true)
设置同步模式的方法
void SetUpdateVehicleLights(const ActorPtr &actor, const bool do_update)
设置是否自动更新车辆灯光状态的方法
float max_upper_bound
相对于主角车辆的最大可能重生距离
Definition Parameters.h:89
包含客户端相关类和定义的命名空间。
Definition AtomicList.h:17
carla::SharedPtr< cc::Actor > ActorPtr
使用别名简化代码中的命名
std::vector< uint8_t > Route
路线类型,由一系列地理位置组成
std::vector< cg::Location > Path
参与者的唯一标识符类型
carla::ActorId ActorId
参与者的智能指针类型
CARLA模拟器的主命名空间。
Definition Carla.cpp:139
boost::shared_ptr< T > SharedPtr
使用这个SharedPtr(boost::shared_ptr)以保持与boost::python的兼容性, 但未来如果可能的话,我们希望能为std::shared_ptr制作一个Python适配器。
Definition Memory.h:19
rpc::ActorId ActorId
Definition ActorId.h:26
路线类型,由一系列字节组成,表示路线信息
Definition Parameters.h:32