CARLA
WalkerEvent.cpp
Go to the documentation of this file.
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 #include "carla/nav/Navigation.h"
11 
12 namespace carla {
13 namespace nav {
14 
16  return EventResult::End;
17  }
18 
20  // refresh time and check
21  event.time -= _delta;
22  if (event.time <= 0.0)
23  return EventResult::End;
24  else
25  return EventResult::Continue;
26  }
27 
29  event.time -= _delta;
30  if (event.time <= 0.0) {
31  return EventResult::TimeOut;
32  } else {
33  carla::geom::Location currentUnrealPos;
35  _manager->GetNavigation()->GetWalkerPosition(_id, currentUnrealPos);
36  // check if we need to check for a trafficlight there (only the first time)
37  if (event.check_for_trafficlight) {
38  event.actor = _manager->GetTrafficLightAffecting(currentUnrealPos);
39  event.check_for_trafficlight = false;
40  }
41  // check if we need to wait for a trafficlight
42  if (event.actor) {
43  auto state = event.actor->GetState();
46  return EventResult::Continue;
47  }
48  }
50  // calculate the direction to look for vehicles
51  carla::geom::Location crosswalkEnd;
52  _manager->GetWalkerCrosswalkEnd(_id, crosswalkEnd);
53  carla::geom::Location direction;
54  direction.x = crosswalkEnd.x - currentUnrealPos.x;
55  direction.y = crosswalkEnd.y - currentUnrealPos.y;
56  direction.z = crosswalkEnd.z - currentUnrealPos.z;
57  // check if the agent has any vehicle around
58  if (_manager && !(_manager->GetNavigation()->HasVehicleNear(_id, 6.0f, direction))) {
59  return EventResult::End;
60  } else {
61  return EventResult::Continue;
62  }
63  }
64  }
65 
66 } // namespace nav
67 } // namespace carla
event to wait for a while
Definition: WalkerEvent.h:39
bool GetWalkerPosition(ActorId id, carla::geom::Location &location)
get the walker current location
Definition: Navigation.cpp:987
void PauseAgent(ActorId id, bool pause)
set an agent as paused for the crowd
This file contains definitions of common data structures used in traffic manager. ...
Definition: Carla.cpp:133
EventResult
result of an event
Definition: WalkerEvent.h:28
bool HasVehicleNear(ActorId id, float distance, carla::geom::Location direction)
return if the agent has a vehicle near (as neighbour)
EventResult operator()(WalkerEventIgnore &event)
Definition: WalkerEvent.cpp:15
Navigation * GetNavigation()
return the navigation object
Definition: WalkerManager.h:81
SharedPtr< carla::client::TrafficLight > GetTrafficLightAffecting(carla::geom::Location UnrealPos, float max_distance=-1.0f)
return the trafficlight affecting that position
event to pause and check for near vehicles
Definition: WalkerEvent.h:45
bool GetWalkerCrosswalkEnd(ActorId id, carla::geom::Location &location)
get the point in the route that end current crosswalk
empty event that just ignores
Definition: WalkerEvent.h:35
SharedPtr< carla::client::TrafficLight > actor
Definition: WalkerEvent.h:48