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