CARLA
 
载入中...
搜索中...
未找到
WalkerNavigation.h
浏览该文件的文档.
1// Copyright (c) 2019 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 "carla/AtomicList.h" // 引入原子列表头文件
10#include "carla/nav/Navigation.h" // 引入导航头文件
11#include "carla/NonCopyable.h" // 引入不可复制类的头文件
12#include "carla/client/Timestamp.h" // 引入时间戳头文件
13#include "carla/rpc/ActorId.h" // 引入参与者ID头文件
14
15#include <memory> // 引入智能指针头文件
16
17namespace carla { // 定义carla命名空间
18namespace client { // 定义client子命名空间
19namespace detail { // 定义detail子命名空间
20
21 class Episode; // 前向声明Episode类
22 class EpisodeState; // 前向声明EpisodeState类
23 class Simulator; // 前向声明Simulator类
24
25 class WalkerNavigation // 定义WalkerNavigation类
26 : public std::enable_shared_from_this<WalkerNavigation>, // 允许共享自身指针
27 private NonCopyable { // 禁止复制
28
29 public:
30
31 explicit WalkerNavigation(std::weak_ptr<Simulator> simulator); // 构造函数,接受弱指针模拟器
32
33 void RegisterWalker(ActorId walker_id, ActorId controller_id) { // 注册行人
34 _walkers.Push(WalkerHandle { walker_id, controller_id }); // 添加到列表中
35 }
36
37 void UnregisterWalker(ActorId walker_id, ActorId controller_id) { // 注销行人
38 auto list = _walkers.Load(); // 加载行人列表
39 unsigned int i = 0; // 初始化索引
40 while (i < list->size()) { // 遍历列表
41 if ((*list)[i].walker == walker_id && // 如果找到匹配的行人
42 (*list)[i].controller == controller_id) { // 且控制器匹配
43 _walkers.DeleteByIndex(i); // 从列表中删除
44 break; // 退出循环
45 }
46 ++i; // 继续下一个索引
47 }
48 }
49
50 void RemoveWalker(ActorId walker_id) { // 移除行人
51 _nav.RemoveAgent(walker_id); // 从导航中移除行人
52 }
53
54 void AddWalker(ActorId walker_id, carla::geom::Location location) { // 添加行人
55 _nav.AddWalker(walker_id, location); // 在导航中创建行人
56 }
57
58 void Tick(std::shared_ptr<Episode> episode); // 更新函数,接受剧集的共享指针
59
60 // 从导航网格中获取随机位置
61 boost::optional<geom::Location> GetRandomLocation() {
62 geom::Location random_location(0, 0, 0); // 初始化随机位置
63 if (_nav.GetRandomLocation(random_location)) // 如果成功获取随机位置
64 return boost::optional<geom::Location>(random_location); // 返回随机位置
65 else
66 return {}; // 否则返回空
67 }
68
69 // 设置行人的目标点
71 return _nav.SetWalkerTarget(id, to); // 设置目标位置
72 }
73
74 // 设置行人的最大速度
75 bool SetWalkerMaxSpeed(ActorId id, float max_speed) {
76 return _nav.SetWalkerMaxSpeed(id, max_speed); // 设置最大速度
77 }
78
79 // 设置可以过马路的行人百分比
80 void SetPedestriansCrossFactor(float percentage) {
81 _nav.SetPedestriansCrossFactor(percentage); // 设置过马路的比例
82 }
83
84 void SetPedestriansSeed(unsigned int seed) { // 设置行人的随机种子
85 _nav.SetSeed(seed); // 设置随机种子
86 }
87
88 private:
89
90 std::weak_ptr<Simulator> _simulator; // 存储弱指针模拟器
91
92 unsigned long _next_check_index; // 存储下一个检查索引
93
94 carla::nav::Navigation _nav; // 存储导航对象
95
96 struct WalkerHandle { // 定义WalkerHandle结构
97 ActorId walker; // 存储行人ID
98 ActorId controller; // 存储控制器ID
99 };
100
102
103 /// 检查一些行人,如果不存在,则将其从人群中移除
104 void CheckIfWalkerExist(std::vector<WalkerHandle> walkers, const EpisodeState &state);
105 /// 添加/更新/删除人群中的所有车辆
106 void UpdateVehiclesInCrowd(std::shared_ptr<Episode> episode, bool show_debug = false);
107 };
108
109} // namespace detail
110} // namespace client
111} // namespace carla
这个类用于禁止拷贝和移动构造函数及赋值操作
持有一个指向列表的原子指针。
Definition AtomicList.h:24
表示某一帧的所有参与者的状态
boost::optional< geom::Location > GetRandomLocation()
void UpdateVehiclesInCrowd(std::shared_ptr< Episode > episode, bool show_debug=false)
添加/更新/删除人群中的所有车辆
void SetPedestriansCrossFactor(float percentage)
void RegisterWalker(ActorId walker_id, ActorId controller_id)
bool SetWalkerMaxSpeed(ActorId id, float max_speed)
WalkerNavigation(std::weak_ptr< Simulator > simulator)
std::weak_ptr< Simulator > _simulator
void Tick(std::shared_ptr< Episode > episode)
void CheckIfWalkerExist(std::vector< WalkerHandle > walkers, const EpisodeState &state)
检查一些行人,如果不存在,则将其从人群中移除
void AddWalker(ActorId walker_id, carla::geom::Location location)
void UnregisterWalker(ActorId walker_id, ActorId controller_id)
bool SetWalkerTarget(ActorId id, const carla::geom::Location to)
管理行人导航,使用 Recast & Detour 库进行低层计算。
Definition Navigation.h:86
bool SetWalkerMaxSpeed(ActorId id, float max_speed)
设置新的最大速度
bool RemoveAgent(ActorId id)
移除代理
bool SetWalkerTarget(ActorId id, carla::geom::Location to)
设置新的目标点以通过有事件的路线
void SetSeed(unsigned int seed)
设置随机数种子
bool GetRandomLocation(carla::geom::Location &location, dtQueryFilter *filter=nullptr) const
获取导航的随机位置
void SetPedestriansCrossFactor(float percentage)
设置行人代理在路径跟随过程中穿过马路的概率
bool AddWalker(ActorId id, carla::geom::Location from)
创建新的行人
carla::ActorId ActorId
参与者的智能指针类型
CARLA模拟器的主命名空间。
Definition Carla.cpp:139
包含CARLA客户端相关类和函数的命名空间。