CARLA
 
载入中...
搜索中...
未找到
WalkerEvent.cpp
浏览该文件的文档.
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
11
12namespace carla {
13namespace nav {
14
15 // WalkerEventVisitor类的函数调用运算符重载,用于处理WalkerEventIgnore类型的事件
16 // 当传入WalkerEventIgnore类型的事件时,直接返回EventResult::End,表示该事件处理结束,无需进行其他操作
20
21 // WalkerEventVisitor类的函数调用运算符重载,用于处理WalkerEventWait类型的事件
22 // 参数event: 传入的WalkerEventWait类型的事件对象,包含了事件相关的时间等信息
23 // 首先将事件对象中的剩余时间(event.time)减去_delta(可能表示经过的时间间隔),
24 // 然后判断剩余时间是否小于等于0,如果是,则表示等待时间已结束,返回EventResult::End,表示该事件处理结束;
25 // 如果剩余时间大于0,则返回EventResult::Continue,表示事件还需继续等待,尚未结束。
27 // 刷新时间并检查
28 event.time -= _delta;
29 if (event.time <= 0.0)
30 return EventResult::End;
31 else
33 }
34
35 // WalkerEventVisitor类的函数调用运算符重载,用于处理WalkerEventStopAndCheck类型的事件
36 // 参数event: 传入的WalkerEventStopAndCheck类型的事件对象,包含了时间、是否检查交通信号灯、相关演员(actor)等信息
38 event.time -= _delta;
39 if (event.time <= 0.0) {
40 // 如果剩余时间小于等于0,说明超时了,返回EventResult::TimeOut,表示该事件因超时结束
42 } else {
43 carla::geom::Location currentUnrealPos;
44 // 通过管理器(_manager)获取导航对象(Navigation),并调用其PauseAgent方法暂停指定ID(_id)的代理,传入参数true表示暂停
46 // 通过管理器(_manager)获取导航对象(Navigation),并调用其GetWalkerPosition方法获取指定ID(_id)的行人(walker)当前位置,存储到currentUnrealPos变量中
47 _manager->GetNavigation()->GetWalkerPosition(_id, currentUnrealPos);
48
49 // 检查是否需要检查那里的交通信号灯(仅限第一次)
50 if (event.check_for_trafficlight) {
51 // 通过管理器(_manager)获取影响当前位置(currentUnrealPos)的交通信号灯演员(TrafficLight),并赋值给event.actor
52 event.actor = _manager->GetTrafficLightAffecting(currentUnrealPos);
53 // 将是否检查交通信号灯的标志设置为false,表示已经进行过一次检查了
54 event.check_for_trafficlight = false;
55 }
56
57 // 检查是否需要等待红绿灯
58 if (event.actor) {
59 // 获取交通信号灯演员(event.actor)的当前状态
60 auto state = event.actor->GetState();
61 // 如果交通信号灯状态为绿色(Green)或者黄色(Yellow),则表示可以继续前进,返回EventResult::Continue
65 }
66 }
67
68 // 恢复指定ID(_id)的代理运行,通过管理器(_manager)获取导航对象(Navigation),并调用其PauseAgent方法传入false表示恢复运行
70
71 // 计算寻找车辆的方向相关操作
72 carla::geom::Location crosswalkEnd;
73 _manager->GetWalkerCrosswalkEnd(_id, crosswalkEnd);
74 carla::geom::Location direction;
75 direction.x = crosswalkEnd.x - currentUnrealPos.x;
76 direction.y = crosswalkEnd.y - currentUnrealPos.y;
77 direction.z = crosswalkEnd.z - currentUnrealPos.z;
78
79 // 检查代理附近是否有车辆
80 if (_manager &&!(_manager->GetNavigation()->HasVehicleNear(_id, 6.0f, direction))) {
81 // 如果附近没有车辆(满足条件),返回EventResult::End,表示该事件处理结束,可以继续后续操作
82 return EventResult::End;
83 } else {
84 // 如果附近有车辆,返回EventResult::Continue,表示需要继续等待或者检查相关情况
86 }
87 }
88 }
89
90} // namespace nav
91} // namespace carla
bool GetWalkerPosition(ActorId id, carla::geom::Location &location)
获取行人的当前位置
void PauseAgent(ActorId id, bool pause)
将人群中的代理设置为暂停
bool HasVehicleNear(ActorId id, float distance, carla::geom::Location direction)
如果代理在附近有车辆(作为邻居),则返回
EventResult operator()(WalkerEventIgnore &event)
bool GetWalkerCrosswalkEnd(ActorId id, carla::geom::Location &location)
SharedPtr< carla::client::TrafficLight > GetTrafficLightAffecting(carla::geom::Location UnrealPos, float max_distance=-1.0f)
EventResult
事件的结果
Definition WalkerEvent.h:43
CARLA模拟器的主命名空间。
Definition Carla.cpp:139
暂停并检查附近车辆的事件
Definition WalkerEvent.h:68
SharedPtr< carla::client::TrafficLight > actor
Definition WalkerEvent.h:74
等待一段时间的事件
Definition WalkerEvent.h:59