CARLA
WalkerAIController.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 
8 
10 
11 namespace carla {
12 namespace client {
13 
15  : Actor(std::move(init)) {}
16 
18  GetEpisode().Lock()->RegisterAIController(*this);
19 
20  // add the walker in the Recast & Detour
21  auto walker = GetParent();
22  if (walker != nullptr) {
23  auto nav = GetEpisode().Lock()->GetNavigation();
24  if (nav != nullptr) {
25  nav->AddWalker(walker->GetId(), walker->GetLocation());
26  }
27  }
28  }
29 
31  GetEpisode().Lock()->UnregisterAIController(*this);
32 
33  // remove the walker from the Recast & Detour
34  auto walker = GetParent();
35  if (walker != nullptr) {
36  auto nav = GetEpisode().Lock()->GetNavigation();
37  if (nav != nullptr) {
38  nav->RemoveWalker(walker->GetId());
39  }
40  }
41  }
42 
43  boost::optional<geom::Location> WalkerAIController::GetRandomLocation() {
44  auto nav = GetEpisode().Lock()->GetNavigation();
45  if (nav != nullptr) {
46  return nav->GetRandomLocation();
47  }
48  return {};
49  }
50 
52  auto nav = GetEpisode().Lock()->GetNavigation();
53  if (nav != nullptr) {
54  auto walker = GetParent();
55  if (walker != nullptr) {
56  if (!nav->SetWalkerTarget(walker->GetId(), destination)) {
57  log_warning("NAV: Failed to set request to go to ", destination.x, destination.y, destination.z);
58  }
59  } else {
60  log_warning("NAV: Failed to set request to go to ", destination.x, destination.y, destination.z, "(parent does not exist)");
61  }
62  }
63  }
64 
65  void WalkerAIController::SetMaxSpeed(const float max_speed) {
66  auto nav = GetEpisode().Lock()->GetNavigation();
67  if (nav != nullptr) {
68  auto walker = GetParent();
69  if (walker != nullptr) {
70  if (!nav->SetWalkerMaxSpeed(walker->GetId(), max_speed)) {
71  log_warning("NAV: failed to set max speed");
72  }
73  } else {
74  log_warning("NAV: failed to set max speed (parent does not exist)");
75  }
76  }
77  }
78 
79 } // namespace client
80 } // namespace carla
WalkerAIController(ActorInitializer init)
This file contains definitions of common data structures used in traffic manager. ...
Definition: Carla.cpp:99
Used to initialize Actor classes.
Definition: ActorState.h:93
void SetMaxSpeed(const float max_speed)
void GoToLocation(const carla::geom::Location &destination)
static void log_warning(Args &&... args)
Definition: Logging.h:96
SharedPtr< Actor > GetParent() const
Definition: ActorState.cpp:31
Represents an actor in the simulation.
Definition: client/Actor.h:18
SharedPtrType Lock() const
Same as TryLock but never return nullptr.
boost::optional< geom::Location > GetRandomLocation()