CARLA
 
载入中...
搜索中...
未找到
ALSM.h
浏览该文件的文档.
1
2#pragma once
3
4#include <memory>
5
9#include "carla/Memory.h"
10
22
23namespace carla {
24namespace traffic_manager {
25
26using namespace constants::HybridMode; // 引入混合模式常量
27using namespace constants::VehicleRemoval; // 引入车辆移除常量
28
29namespace chr = std::chrono; // 引用时间相关的命名空间
30namespace cg = carla::geom; // 引用几何相关的命名空间
31namespace cc = carla::client; // 引用客户端相关的命名空间
32
33using ParticipantList = carla::SharedPtr<cc::ActorList>; // 定义参与者列表共享指针类型
34using ParticipantMap = std::unordered_map<ActorId, ActorPtr>; // 定义参与者映射表类型
35using IdleTimeMap = std::unordered_map<ActorId, double>; // 定义闲置时间映射表类型
36using LocalMapPtr = std::shared_ptr<InMemoryMap>; // 定义本地地图共享指针类型
37
38/// ALSM: 代理生命周期和状态管理
39/// 此类具有更新运动状态本地缓存的功能
40/// 并管理模拟中车辆数量变化的内存和清理。
41class ALSM {
42
43private:
44 AtomicActorSet &registered_vehicles; // 引用已注册参与者的原子集合
45 ParticipantMap unregistered_participants; // 存储未注册参与者的结构
46 BufferMap &buffer_map; // 引用缓冲区映射
47 IdleTimeMap idle_time; // 存储参与者在位置上停留时间的结构
48 ParticipantMap hero_participants; // 存储角色名称为"hero"的参与者
49 TrackTraffic &track_traffic; // 引用交通跟踪对象
50 std::vector<ActorId>& marked_for_removal; // 标记待移除参与者的数组
51 const Parameters &parameters; // 引用参数对象
52 const cc::World &world; // 引用世界对象
53 const LocalMapPtr &local_map; // 引用本地地图指针
54 SimulationState &simulation_state; // 引用仿真状态对象
55 LocalizationStage &localization_stage; // 引用定位阶段对象
56 CollisionStage &collision_stage; // 引用碰撞阶段对象
57 TrafficLightStage &traffic_light_stage; // 引用交通灯阶段对象
58 MotionPlanStage &motion_plan_stage; // 引用运动规划阶段对象
59 VehicleLightStage &vehicle_light_stage; // 引用车辆灯光阶段对象
60 double elapsed_last_participant_destruction {0.0}; // 记录自上次因闲置过久而销毁参与者的时间
61 cc::Timestamp current_timestamp; // 当前时间戳
62 std::unordered_map<ActorId, bool> has_physics_enabled; // 存储每个参与者是否启用物理的映射
63
64 // 更新已注册参与者在某位置上停留的时间
65 void UpdateIdleTime(std::pair<ActorId, double>& max_idle_time, const ActorId& actor_id);
66
67 // 判断一辆车是否长时间停滞不前
68 bool IsVehicleStuck(const ActorId& actor_id);
69
70 // 确定自上次更新以来在仿真中新生成的参与者
71 void IdentifyNewParticipants(const ParticipantList &participant_list);
72
73 using DestroyeddParticipants = std::pair<ActorIdSet, ActorIdSet>; // 定义删除参与者的数据类型
74 // 确定在上一帧中删除的参与者
75 // 返回已注册和未注册参与者的数组
76 DestroyeddParticipants IdentifyDestroyedParticipants(const ParticipantList &participant_list);
77
78 using IdleInfo = std::pair<ActorId, double>; // 定义闲置信息的数据类型
79 void UpdateRegisteredParticipantsData(const bool hybrid_physics_mode, IdleInfo &max_idle_time);
80
81 // 更新参与者数据
82 void UpdateData(const bool hybrid_physics_mode, const Actor &vehicle,
83 const bool hero_actor_present, const float physics_radius_square);
84
85 // 更新未注册参与者的数据
86 void UpdateUnregisteredParticipantsData();
87
88public:
89 // 构造函数
90 ALSM(AtomicActorSet &registered_vehicles,
91 BufferMap &buffer_map,
92 TrackTraffic &track_traffic,
93 std::vector<ActorId>& marked_for_removal,
94 const Parameters &parameters,
95 const cc::World &world,
96 const LocalMapPtr &local_map,
97 SimulationState &simulation_state,
98 LocalizationStage &localization_stage,
99 CollisionStage &collision_stage,
100 TrafficLightStage &traffic_light_stage,
101 MotionPlanStage &motion_plan_stage,
102 VehicleLightStage &vehicle_light_stage);
103
104 // 更新方法
105 void Update();
106
107 // 从交通管理中移除参与者,并清理与该车辆相关的各种数据
108 void RemoveParticipant(const ActorId actor_id, const bool registered_actor);
109
110 // 重置方法
111 void Reset();
112};
TSharedPtr< const FActorInfo > carla::rpc::ActorState UWorld Actor
包含客户端相关类和定义的命名空间。
Definition AtomicList.h:17
std::shared_ptr< InMemoryMap > LocalMapPtr
本地地图指针类型,使用智能指针管理InMemoryMap对象
std::unordered_map< carla::ActorId, Buffer > BufferMap
CARLA模拟器的主命名空间。
Definition Carla.cpp:139
boost::shared_ptr< T > SharedPtr
使用这个SharedPtr(boost::shared_ptr)以保持与boost::python的兼容性, 但未来如果可能的话,我们希望能为std::shared_ptr制作一个Python适配器。
Definition Memory.h:19