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/Logging.h"
8 #include "carla/nav/Navigation.h"
10 #include "carla/nav/WalkerEvent.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  // calculate the direction to look for vehicles
34  carla::geom::Location currentUnrealPos;
35  carla::geom::Location crosswalkEnd;
36  carla::geom::Location direction;
37  _manager->GetNavigation()->GetWalkerPosition(_id, currentUnrealPos);
38  _manager->GetWalkerCrosswalkEnd(_id, crosswalkEnd);
39  direction.x = crosswalkEnd.x - currentUnrealPos.x;
40  direction.y = crosswalkEnd.y - currentUnrealPos.y;
41  direction.z = crosswalkEnd.z - currentUnrealPos.z;
42  // check if the agent has any vehicle around
43  if (_manager && !(_manager->GetNavigation()->HasVehicleNear(_id, 6.0f, direction))) {
44  return EventResult::End;
45  } else {
46  return EventResult::Continue;
47  }
48  }
49  }
50 
51 } // namespace nav
52 } // namespace carla
event to wait for a while
Definition: WalkerEvent.h:31
bool GetWalkerPosition(ActorId id, carla::geom::Location &location)
get the walker current location
Definition: Navigation.cpp:974
This file contains definitions of common data structures used in traffic manager. ...
Definition: Carla.cpp:99
EventResult
result of an event
Definition: WalkerEvent.h:20
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:75
event to pause and check for near vehicles
Definition: WalkerEvent.h:37
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:27