From b652e672954354820c7b0aef2dcc3314dc8377dc Mon Sep 17 00:00:00 2001 From: bernatx Date: Mon, 1 Jul 2019 16:23:47 +0200 Subject: [PATCH] Fixes from PR --- LibCarla/cmake/client/CMakeLists.txt | 33 +++++-- .../carla/client/WalkerAIController.cpp | 22 +++-- .../source/carla/client/WalkerAIController.h | 4 +- LibCarla/source/carla/client/World.cpp | 2 +- LibCarla/source/carla/client/World.h | 4 +- .../source/carla/client/detail/Client.cpp | 1 - .../source/carla/client/detail/Episode.cpp | 1 + LibCarla/source/carla/client/detail/Episode.h | 1 - .../source/carla/client/detail/Simulator.cpp | 2 +- .../source/carla/client/detail/Simulator.h | 9 +- .../carla/client/detail/WalkerNavigation.h | 9 +- LibCarla/source/carla/nav/Navigation.cpp | 87 ++++++++++++------- LibCarla/source/carla/nav/Navigation.h | 8 +- PythonAPI/carla/source/libcarla/World.cpp | 2 +- PythonAPI/carla/source/libcarla/libcarla.cpp | 6 ++ PythonAPI/examples/spawn_npc.py | 28 +++--- .../Source/Carla/AI/AIControllerFactory.cpp | 7 -- .../Carla/Source/Carla/Server/CarlaServer.cpp | 2 - 18 files changed, 134 insertions(+), 94 deletions(-) diff --git a/LibCarla/cmake/client/CMakeLists.txt b/LibCarla/cmake/client/CMakeLists.txt index c550c69a5..1ee7612bc 100644 --- a/LibCarla/cmake/client/CMakeLists.txt +++ b/LibCarla/cmake/client/CMakeLists.txt @@ -17,7 +17,7 @@ install(DIRECTORY "${BOOST_INCLUDE_PATH}/boost" DESTINATION include/system) file(GLOB boost_libraries "${BOOST_LIB_PATH}/*.*") install(FILES ${boost_libraries} DESTINATION lib) -# Windows need libpng alongside with zlib to be installed, and also recast&detour libs +# Windows need libpng alongside with zlib to be installed if (WIN32) # Install zlib headers. file(GLOB zlib_includes "${ZLIB_INCLUDE_PATH}/*") @@ -211,15 +211,16 @@ if (LIBCARLA_BUILD_RELEASE) if (NOT DEFINED CMAKE_CXX_FLAGS_RELEASE_CLIENT) set(CMAKE_CXX_FLAGS_RELEASE_CLIENT ${CMAKE_CXX_FLAGS_RELEASE}) endif() - set_target_properties(carla_client PROPERTIES COMPILE_FLAGS "${CMAKE_CXX_FLAGS_RELEASE_CLIENT}") - endif (WIN32) + set_target_properties(carla_client PROPERTIES COMPILE_FLAGS "${CMAKE_CXX_FLAGS_RELEASE_CLIENT}") target_link_libraries(carla_client "${RECAST_LIB_PATH}/libRecast.a") target_link_libraries(carla_client "${RECAST_LIB_PATH}/libDetour.a") target_link_libraries(carla_client "${RECAST_LIB_PATH}/libDetourCrowd.a") - endif() + endif (WIN32) + +endif() if (LIBCARLA_BUILD_DEBUG) @@ -232,11 +233,25 @@ if (LIBCARLA_BUILD_DEBUG) install(TARGETS carla_client_debug DESTINATION lib) - set_target_properties(carla_client_debug PROPERTIES COMPILE_FLAGS "${CMAKE_CXX_FLAGS_DEBUG}") + if (WIN32) # @todo Fix PythonAPI build on Windows. + set_target_properties(carla_client_debug PROPERTIES COMPILE_FLAGS "${CMAKE_CXX_FLAGS_DEBUG}") + + target_link_libraries(carla_client_debug "${RECAST_LIB_PATH}/Recast.lib") + target_link_libraries(carla_client_debug "${RECAST_LIB_PATH}/Detour.lib") + target_link_libraries(carla_client_debug "${RECAST_LIB_PATH}/DetourCrowd.lib") + else () + if (NOT DEFINED CMAKE_CXX_FLAGS_DEBUG_CLIENT) + set(CMAKE_CXX_FLAGS_DEBUG_CLIENT ${CMAKE_CXX_FLAGS_DEBUG}) + endif() + + set_target_properties(carla_client_debug PROPERTIES COMPILE_FLAGS "${CMAKE_CXX_FLAGS_DEBUG_CLIENT}") + + target_link_libraries(carla_client_debug "${RECAST_LIB_PATH}/libRecast.a") + target_link_libraries(carla_client_debug "${RECAST_LIB_PATH}/libDetour.a") + target_link_libraries(carla_client_debug "${RECAST_LIB_PATH}/libDetourCrowd.a") + + endif (WIN32) + target_compile_definitions(carla_client_debug PUBLIC -DBOOST_ASIO_ENABLE_BUFFER_DEBUGGING) - target_link_libraries(carla_client_debug "${RECAST_LIB_PATH}/libRecast.a") - target_link_libraries(carla_client_debug "${RECAST_LIB_PATH}/libDetour.a") - target_link_libraries(carla_client_debug "${RECAST_LIB_PATH}/libDetourCrowd.a") - endif() diff --git a/LibCarla/source/carla/client/WalkerAIController.cpp b/LibCarla/source/carla/client/WalkerAIController.cpp index 49514a349..e0661e642 100644 --- a/LibCarla/source/carla/client/WalkerAIController.cpp +++ b/LibCarla/source/carla/client/WalkerAIController.cpp @@ -40,19 +40,24 @@ namespace client { } } - geom::Location WalkerAIController::GetRandomLocation() { + boost::optional WalkerAIController::GetRandomLocation() { auto nav = GetEpisode().Lock()->GetNavigation(); if (nav != nullptr) { return nav->GetRandomLocation(); } - return geom::Location(0, 0, 0); + return {}; } void WalkerAIController::GoToLocation(const carla::geom::Location &destination) { auto nav = GetEpisode().Lock()->GetNavigation(); if (nav != nullptr) { - if (!nav->SetWalkerTarget(GetParent()->GetId(), destination)) { - logging::log("NAV: Failed to set request to go to ", destination.x, destination.y, destination.z); + auto walker = GetParent(); + if (walker != nullptr) { + if (!nav->SetWalkerTarget(walker->GetId(), destination)) { + log_warning("NAV: Failed to set request to go to ", destination.x, destination.y, destination.z); + } + } else { + log_warning("NAV: Failed to set request to go to ", destination.x, destination.y, destination.z, "(parent does not exist)"); } } } @@ -60,8 +65,13 @@ namespace client { void WalkerAIController::SetMaxSpeed(const float max_speed) { auto nav = GetEpisode().Lock()->GetNavigation(); if (nav != nullptr) { - if (!nav->SetWalkerMaxSpeed(GetParent()->GetId(), max_speed)) { - logging::log("NAV: failed to set max speed"); + auto walker = GetParent(); + if (walker != nullptr) { + if (!nav->SetWalkerMaxSpeed(walker->GetId(), max_speed)) { + log_warning("NAV: failed to set max speed"); + } + } else { + log_warning("NAV: failed to set max speed (parent does not exist)"); } } } diff --git a/LibCarla/source/carla/client/WalkerAIController.h b/LibCarla/source/carla/client/WalkerAIController.h index ef80aba29..44e64b52a 100644 --- a/LibCarla/source/carla/client/WalkerAIController.h +++ b/LibCarla/source/carla/client/WalkerAIController.h @@ -10,6 +10,8 @@ #include "carla/client/detail/WalkerNavigation.h" #include "carla/geom/Vector3D.h" +#include + namespace carla { namespace client { @@ -22,7 +24,7 @@ namespace client { void Stop(); - geom::Location GetRandomLocation(); + boost::optional GetRandomLocation(); void GoToLocation(const carla::geom::Location &destination); diff --git a/LibCarla/source/carla/client/World.cpp b/LibCarla/source/carla/client/World.cpp index 80560be72..4e692d8bf 100644 --- a/LibCarla/source/carla/client/World.cpp +++ b/LibCarla/source/carla/client/World.cpp @@ -25,7 +25,7 @@ namespace client { return _episode.Lock()->GetBlueprintLibrary(); } - geom::Location World::GetRandomLocationFromNavigation() const { + boost::optional World::GetRandomLocationFromNavigation() const { return _episode.Lock()->GetRandomLocationFromNavigation(); } diff --git a/LibCarla/source/carla/client/World.h b/LibCarla/source/carla/client/World.h index 79b0139be..0963bfabd 100644 --- a/LibCarla/source/carla/client/World.h +++ b/LibCarla/source/carla/client/World.h @@ -19,6 +19,8 @@ #include "carla/rpc/VehiclePhysicsControl.h" #include "carla/rpc/WeatherParameters.h" +#include + namespace carla { namespace client { @@ -52,7 +54,7 @@ namespace client { SharedPtr GetBlueprintLibrary() const; /// Get a random location from the pedestrians navigation mesh - geom::Location GetRandomLocationFromNavigation() const; + boost::optional GetRandomLocationFromNavigation() const; /// Return the spectator actor. The spectator controls the view in the /// simulator window. diff --git a/LibCarla/source/carla/client/detail/Client.cpp b/LibCarla/source/carla/client/detail/Client.cpp index 9814eda39..436f1319a 100644 --- a/LibCarla/source/carla/client/detail/Client.cpp +++ b/LibCarla/source/carla/client/detail/Client.cpp @@ -9,7 +9,6 @@ #include "carla/Exception.h" #include "carla/Version.h" #include "carla/client/TimeoutException.h" -#include "carla/nav/Navigation.h" #include "carla/rpc/ActorDescription.h" #include "carla/rpc/BoneTransformData.h" #include "carla/rpc/Client.h" diff --git a/LibCarla/source/carla/client/detail/Episode.cpp b/LibCarla/source/carla/client/detail/Episode.cpp index a36134222..6cee3c018 100644 --- a/LibCarla/source/carla/client/detail/Episode.cpp +++ b/LibCarla/source/carla/client/detail/Episode.cpp @@ -8,6 +8,7 @@ #include "carla/Logging.h" #include "carla/client/detail/Client.h" +#include "carla/client/detail/WalkerNavigation.h" #include "carla/sensor/Deserializer.h" #include diff --git a/LibCarla/source/carla/client/detail/Episode.h b/LibCarla/source/carla/client/detail/Episode.h index 9425e42a2..15f09ba24 100644 --- a/LibCarla/source/carla/client/detail/Episode.h +++ b/LibCarla/source/carla/client/detail/Episode.h @@ -14,7 +14,6 @@ #include "carla/client/detail/CachedActorList.h" #include "carla/client/detail/CallbackList.h" #include "carla/client/detail/EpisodeState.h" -#include "carla/client/detail/WalkerNavigation.h" #include "carla/rpc/EpisodeInfo.h" #include diff --git a/LibCarla/source/carla/client/detail/Simulator.cpp b/LibCarla/source/carla/client/detail/Simulator.cpp index bce0ce1b6..afde90c39 100644 --- a/LibCarla/source/carla/client/detail/Simulator.cpp +++ b/LibCarla/source/carla/client/detail/Simulator.cpp @@ -169,7 +169,7 @@ namespace detail { navigation->UnregisterWalker(walker->GetId(), controller.GetId()); } - geom::Location Simulator::GetRandomLocationFromNavigation() { + boost::optional Simulator::GetRandomLocationFromNavigation() { DEBUG_ASSERT(_episode != nullptr); auto navigation = _episode->CreateNavigationIfMissing(); DEBUG_ASSERT(navigation != nullptr); diff --git a/LibCarla/source/carla/client/detail/Simulator.h b/LibCarla/source/carla/client/detail/Simulator.h index 022d9c7fd..2a64f632b 100644 --- a/LibCarla/source/carla/client/detail/Simulator.h +++ b/LibCarla/source/carla/client/detail/Simulator.h @@ -24,6 +24,7 @@ #include "carla/rpc/TrafficLightState.h" #include +#include namespace carla { namespace client { @@ -184,7 +185,7 @@ namespace detail { void UnregisterAIController(const WalkerAIController &controller); - geom::Location GetRandomLocationFromNavigation(); + boost::optional GetRandomLocationFromNavigation(); std::shared_ptr GetNavigation() { return _episode->GetNavigation(); @@ -351,12 +352,6 @@ namespace detail { _client.SetReplayerTimeFactor(time_factor); } - /// @} - // ========================================================================= - /// @name Operations with walkers - // ========================================================================= - /// @{ - /// @} // ========================================================================= /// @name Operations with sensors diff --git a/LibCarla/source/carla/client/detail/WalkerNavigation.h b/LibCarla/source/carla/client/detail/WalkerNavigation.h index 51b8d921c..57334c1ce 100644 --- a/LibCarla/source/carla/client/detail/WalkerNavigation.h +++ b/LibCarla/source/carla/client/detail/WalkerNavigation.h @@ -10,7 +10,6 @@ #include "carla/nav/Navigation.h" #include "carla/NonCopyable.h" #include "carla/client/Timestamp.h" -#include "carla/client/detail/Client.h" #include "carla/client/detail/EpisodeProxy.h" #include "carla/rpc/ActorId.h" @@ -62,10 +61,12 @@ namespace detail { void Tick(const EpisodeState &episode_state); // Get Random location in nav mesh - geom::Location GetRandomLocation() { + boost::optional GetRandomLocation() { geom::Location random_location(0, 0, 0); - _nav.GetRandomLocation(random_location, 1.0f); - return random_location; + if (_nav.GetRandomLocation(random_location, 1.0f)) + return boost::optional(random_location); + else + return {}; } // set a new target point to go diff --git a/LibCarla/source/carla/nav/Navigation.cpp b/LibCarla/source/carla/nav/Navigation.cpp index f1923c0b0..e55113821 100644 --- a/LibCarla/source/carla/nav/Navigation.cpp +++ b/LibCarla/source/carla/nav/Navigation.cpp @@ -13,6 +13,7 @@ #include #include +#include namespace carla { namespace nav { @@ -55,7 +56,7 @@ namespace nav { static const float AGENT_RADIUS = 0.3f; // return a random float - float frand() { + static float frand() { return static_cast(rand()) / static_cast(RAND_MAX); } @@ -70,7 +71,7 @@ namespace nav { } // load navigation data - bool Navigation::Load(const std::string filename) { + bool Navigation::Load(const std::string &filename) { std::ifstream f; std::istream_iterator start(f), end; @@ -83,14 +84,15 @@ namespace nav { f.close(); // parse the content - return Load(content); + return Load(std::move(content)); } // load navigation data from memory - bool Navigation::Load(const std::vector content) { + bool Navigation::Load( std::vector content) { const int NAVMESHSET_MAGIC = 'M' << 24 | 'S' << 16 | 'E' << 8 | 'T'; // 'MSET'; const int NAVMESHSET_VERSION = 1; #pragma pack(push, 1) + struct NavMeshSetHeader { int magic; int version; @@ -155,7 +157,6 @@ namespace nav { } // read the tile - memset(data, 0, static_cast(tileHeader.dataSize)); memcpy(data, &content[pos], static_cast(tileHeader.dataSize)); pos += static_cast(tileHeader.dataSize); if (pos > content.size()) { @@ -179,7 +180,7 @@ namespace nav { _navQuery->init(_navMesh, MAX_QUERY_SEARCH_NODES); // copy - _binaryMesh = content; + _binaryMesh = std::move(content); _ready = true; // create and init the crowd manager @@ -243,7 +244,7 @@ namespace nav { } // return the path points to go from one position to another - bool Navigation::GetPath(const carla::geom::Location from, const carla::geom::Location to, + bool Navigation::GetPath(carla::geom::Location from, carla::geom::Location to, dtQueryFilter * filter, std::vector &path) { // path found float m_straightPath[MAX_POLYS * 3]; @@ -255,6 +256,9 @@ namespace nav { dtPolyRef m_polys[MAX_POLYS]; int m_npolys; + // force single thread running this + std::lock_guard lock(_mutex); + // check if all is ready if (!_ready) { return false; @@ -262,9 +266,6 @@ namespace nav { DEBUG_ASSERT(_navQuery != nullptr); - // force single thread running this - std::lock_guard lock(_mutex); - // point extension float m_polyPickExt[3]; m_polyPickExt[0] = 2; @@ -327,6 +328,9 @@ namespace nav { bool Navigation::AddWalker(ActorId id, carla::geom::Location from) { dtCrowdAgentParams params; + // force single thread running this + std::lock_guard lock(_mutex); + // check if all is ready if (!_ready) { return false; @@ -353,9 +357,6 @@ namespace nav { params.obstacleAvoidanceType = 3; params.separationWeight = 0.5f; - // force single thread running this - std::lock_guard lock(_mutex); - // from Unreal coordinates (subtract half height to move pivot from center (unreal) to bottom (recast)) float PointFrom[3] = { from.x, from.z - (AGENT_HEIGHT / 2.0f), from.y }; // add walker @@ -375,6 +376,9 @@ namespace nav { // remove a walker bool Navigation::RemoveWalker(ActorId id) { + // force single thread running this + std::lock_guard lock(_mutex); + // check if all is ready if (!_ready) { return false; @@ -388,9 +392,6 @@ namespace nav { return false; } - // force single thread running this - std::lock_guard lock(_mutex); - // remove from crowd _crowd->removeAgent(it->second); @@ -403,6 +404,9 @@ namespace nav { // set new max speed bool Navigation::SetWalkerMaxSpeed(ActorId id, float max_speed) { + // force single thread running this + std::lock_guard lock(_mutex); + // check if all is ready if (!_ready) { return false; @@ -416,9 +420,6 @@ namespace nav { return false; } - // force single thread running this - std::lock_guard lock(_mutex); - // get the agent dtCrowdAgent *agent = _crowd->getEditableAgent(it->second); if (agent) { @@ -461,9 +462,9 @@ namespace nav { return false; } + // lock mutex if (use_lock) { - // force single thread running this - std::lock_guard lock(_mutex); + _mutex.lock(); } // set target position @@ -473,15 +474,29 @@ namespace nav { dtPolyRef targetRef; _navQuery->findNearestPoly(pointTo, _crowd->getQueryHalfExtents(), filter, &targetRef, nearest); if (!targetRef) { + // unlock mutex + if (use_lock) { + _mutex.unlock(); + } return false; } - return _crowd->requestMoveTarget(index, targetRef, pointTo); + bool res = _crowd->requestMoveTarget(index, targetRef, pointTo); + + // unlock mutex + if (use_lock) { + _mutex.unlock(); + } + + return res; } // update all walkers in crowd void Navigation::UpdateCrowd(const client::detail::EpisodeState &state) { + // force single thread running this + std::lock_guard lock(_mutex); + // check if all is ready if (!_ready) { return; @@ -489,9 +504,6 @@ namespace nav { DEBUG_ASSERT(_crowd != nullptr); - // force single thread running this - std::lock_guard lock(_mutex); - // update all _delta_seconds = state.GetTimestamp().delta_seconds; _crowd->update(static_cast(_delta_seconds), nullptr); @@ -518,6 +530,9 @@ namespace nav { // get the walker current transform bool Navigation::GetWalkerTransform(ActorId id, carla::geom::Transform &trans) { + // force single thread running this + std::lock_guard lock(_mutex); + // check if all is ready if (!_ready) { return false; @@ -537,9 +552,6 @@ namespace nav { return false; } - // force single thread running this - std::lock_guard lock(_mutex); - // get the walker const dtCrowdAgent *agent = _crowd->getAgent(index); @@ -566,6 +578,9 @@ namespace nav { float Navigation::GetWalkerSpeed(ActorId id) { + // force single thread running this + std::lock_guard lock(_mutex); + // check if all is ready if (!_ready) { return 0.0f; @@ -585,9 +600,6 @@ namespace nav { return 0.0f; } - // force single thread running this - std::lock_guard lock(_mutex); - // get the walker const dtCrowdAgent *agent = _crowd->getAgent(index); return sqrt(agent->vel[0] * agent->vel[0] + agent->vel[1] * agent->vel[1] + agent->vel[2] * @@ -613,9 +625,9 @@ namespace nav { filter = &filter2; } + // lock mutex if (use_lock) { - // force single thread running this - std::lock_guard lock(_mutex); + _mutex.lock(); } // search @@ -633,11 +645,20 @@ namespace nav { break; } } else { + // unlock mutex + if (use_lock) { + _mutex.unlock(); + } throw_exception(std::runtime_error( "no valid random point from navigation could be found, check filter or mesh.")); } } while (1); + // unlock mutex + if (use_lock) { + _mutex.unlock(); + } + return true; } diff --git a/LibCarla/source/carla/nav/Navigation.h b/LibCarla/source/carla/nav/Navigation.h index 339971f5b..b2ffc93b2 100644 --- a/LibCarla/source/carla/nav/Navigation.h +++ b/LibCarla/source/carla/nav/Navigation.h @@ -21,7 +21,7 @@ namespace carla { namespace nav { - class Navigation { + class Navigation : private NonCopyable { public: @@ -29,11 +29,11 @@ namespace nav { ~Navigation(); // load navigation data - bool Load(const std::string filename); + bool Load(const std::string &filename); // load navigation data from memory - bool Load(const std::vector content); + bool Load(std::vector content); // return the path points to go from one position to another - bool GetPath(const carla::geom::Location from, const carla::geom::Location to, dtQueryFilter * filter, + bool GetPath(carla::geom::Location from, carla::geom::Location to, dtQueryFilter * filter, std::vector &path); // create the crowd object diff --git a/PythonAPI/carla/source/libcarla/World.cpp b/PythonAPI/carla/source/libcarla/World.cpp index 7473359e4..3b76a391f 100644 --- a/PythonAPI/carla/source/libcarla/World.cpp +++ b/PythonAPI/carla/source/libcarla/World.cpp @@ -131,7 +131,7 @@ void export_world() { .add_property("debug", &cc::World::MakeDebugHelper) .def("get_blueprint_library", CONST_CALL_WITHOUT_GIL(cc::World, GetBlueprintLibrary)) .def("get_map", CONST_CALL_WITHOUT_GIL(cc::World, GetMap)) - .def("get_random_location_from_navigation", &cc::World::GetRandomLocationFromNavigation) + .def("get_random_location_from_navigation", CALL_RETURNING_OPTIONAL_WITHOUT_GIL(cc::World, GetRandomLocationFromNavigation)) .def("get_spectator", CONST_CALL_WITHOUT_GIL(cc::World, GetSpectator)) .def("get_settings", CONST_CALL_WITHOUT_GIL(cc::World, GetSettings)) .def("apply_settings", CALL_WITHOUT_GIL_1(cc::World, ApplySettings, cr::EpisodeSettings), arg("settings")) diff --git a/PythonAPI/carla/source/libcarla/libcarla.cpp b/PythonAPI/carla/source/libcarla/libcarla.cpp index ca55d9814..f0d24a6da 100644 --- a/PythonAPI/carla/source/libcarla/libcarla.cpp +++ b/PythonAPI/carla/source/libcarla/libcarla.cpp @@ -96,6 +96,12 @@ return optional.has_value() ? boost::python::object(*optional) : boost::python::object(); \ } +#define CALL_RETURNING_OPTIONAL_WITHOUT_GIL(cls, fn) +[](const cls &self) { \ + carla::PythonUtil::ReleaseGIL unlock; \ + auto optional = self.fn(); \ + return optional.has_value() ? boost::python::object(*optional) : boost::python::object(); \ + } + template static void PrintListItem_(std::ostream &out, const T &item) { out << item; diff --git a/PythonAPI/examples/spawn_npc.py b/PythonAPI/examples/spawn_npc.py index e01eca778..b9732355b 100755 --- a/PythonAPI/examples/spawn_npc.py +++ b/PythonAPI/examples/spawn_npc.py @@ -53,33 +53,35 @@ def main(): default=50, type=int, help='number of walkers (default: 50)') - argparser.add_argument( - '-d', '--delay', - metavar='D', - default=2.0, - type=float, - help='delay in seconds between spawns (default: 2.0)') argparser.add_argument( '--safe', action='store_true', help='avoid spawning vehicles prone to accidents') argparser.add_argument( - '--filter', + '--filterv', metavar='PATTERN', default='vehicle.*', - help='actor filter (default: "vehicle.*")') + help='vehicles filter (default: "vehicle.*")') + argparser.add_argument( + '--filterw', + metavar='PATTERN', + default='walker.pedestrian.*', + help='pedestrians filter (default: "walker.pedestrian.*")') args = argparser.parse_args() logging.basicConfig(format='%(levelname)s: %(message)s', level=logging.INFO) vehicles_list = [] + walkers_list = [] + all_id = [] client = carla.Client(args.host, args.port) client.set_timeout(2.0) try: world = client.get_world() - blueprints = world.get_blueprint_library().filter(args.filter) + blueprints = world.get_blueprint_library().filter(args.filterv) + blueprintsWalkers = world.get_blueprint_library().filter(args.filterw) if args.safe: blueprints = [x for x in blueprints if int(x.get_attribute('number_of_wheels')) == 4] @@ -129,18 +131,15 @@ def main(): # ------------- # 1. take all the random locations to spawn spawn_points = [] - location_error = carla.Location(0, 0, 0) for i in range(args.number_of_walkers): spawn_point = carla.Transform() spawn_point.location = world.get_random_location_from_navigation() - # if the returned location is at (0,0,0) we can consider a problem - if (spawn_point.location != location_error): + if (spawn_point.location != None): spawn_points.append(spawn_point) batch = [] - walkers_list = [] # 2. we spawn the walker object for spawn_point in spawn_points: - walker_bp = random.choice(world.get_blueprint_library().filter('walker.pedestrian.*')) + walker_bp = random.choice(blueprintsWalkers) # set as not invencible if walker_bp.has_attribute('is_invincible'): walker_bp.set_attribute('is_invincible', 'false') @@ -163,7 +162,6 @@ def main(): else: walkers_list[i]["con"] = results[i].actor_id # 4. we put altogether the walkers and controllers id to get the objects from their id - all_id = [] for i in range(len(walkers_list)): all_id.append(walkers_list[i]["con"]) all_id.append(walkers_list[i]["id"]) diff --git a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/AI/AIControllerFactory.cpp b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/AI/AIControllerFactory.cpp index fc41dfbf4..5c87fbd80 100644 --- a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/AI/AIControllerFactory.cpp +++ b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/AI/AIControllerFactory.cpp @@ -32,13 +32,6 @@ FActorSpawnResult AAIControllerFactory::SpawnActor( return {}; } - UCarlaGameInstance *GameInstance = UCarlaStatics::GetGameInstance(World); - if (GameInstance == nullptr) - { - UE_LOG(LogCarla, Error, TEXT("AAIControllerFactory: cannot spawn controller, incompatible game instance.")); - return {}; - } - FActorSpawnParameters SpawnParameters; SpawnParameters.SpawnCollisionHandlingOverride = ESpawnActorCollisionHandlingMethod::AlwaysSpawn; auto *Controller = World->SpawnActor(Description.Class, Transform, SpawnParameters); diff --git a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Server/CarlaServer.cpp b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Server/CarlaServer.cpp index f032b9eb3..66370fb12 100644 --- a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Server/CarlaServer.cpp +++ b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Server/CarlaServer.cpp @@ -39,8 +39,6 @@ #include #include -#include "Components/CapsuleComponent.h" - #include template