Fixes from PR
This commit is contained in:
parent
b41efd90cf
commit
b652e67295
|
@ -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()
|
||||
|
|
|
@ -40,19 +40,24 @@ namespace client {
|
|||
}
|
||||
}
|
||||
|
||||
geom::Location WalkerAIController::GetRandomLocation() {
|
||||
boost::optional<geom::Location> 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)");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,6 +10,8 @@
|
|||
#include "carla/client/detail/WalkerNavigation.h"
|
||||
#include "carla/geom/Vector3D.h"
|
||||
|
||||
#include <optional>
|
||||
|
||||
namespace carla {
|
||||
namespace client {
|
||||
|
||||
|
@ -22,7 +24,7 @@ namespace client {
|
|||
|
||||
void Stop();
|
||||
|
||||
geom::Location GetRandomLocation();
|
||||
boost::optional<geom::Location> GetRandomLocation();
|
||||
|
||||
void GoToLocation(const carla::geom::Location &destination);
|
||||
|
||||
|
|
|
@ -25,7 +25,7 @@ namespace client {
|
|||
return _episode.Lock()->GetBlueprintLibrary();
|
||||
}
|
||||
|
||||
geom::Location World::GetRandomLocationFromNavigation() const {
|
||||
boost::optional<geom::Location> World::GetRandomLocationFromNavigation() const {
|
||||
return _episode.Lock()->GetRandomLocationFromNavigation();
|
||||
}
|
||||
|
||||
|
|
|
@ -19,6 +19,8 @@
|
|||
#include "carla/rpc/VehiclePhysicsControl.h"
|
||||
#include "carla/rpc/WeatherParameters.h"
|
||||
|
||||
#include <optional>
|
||||
|
||||
namespace carla {
|
||||
namespace client {
|
||||
|
||||
|
@ -52,7 +54,7 @@ namespace client {
|
|||
SharedPtr<BlueprintLibrary> GetBlueprintLibrary() const;
|
||||
|
||||
/// Get a random location from the pedestrians navigation mesh
|
||||
geom::Location GetRandomLocationFromNavigation() const;
|
||||
boost::optional<geom::Location> GetRandomLocationFromNavigation() const;
|
||||
|
||||
/// Return the spectator actor. The spectator controls the view in the
|
||||
/// simulator window.
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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 <exception>
|
||||
|
|
|
@ -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 <vector>
|
||||
|
|
|
@ -169,7 +169,7 @@ namespace detail {
|
|||
navigation->UnregisterWalker(walker->GetId(), controller.GetId());
|
||||
}
|
||||
|
||||
geom::Location Simulator::GetRandomLocationFromNavigation() {
|
||||
boost::optional<geom::Location> Simulator::GetRandomLocationFromNavigation() {
|
||||
DEBUG_ASSERT(_episode != nullptr);
|
||||
auto navigation = _episode->CreateNavigationIfMissing();
|
||||
DEBUG_ASSERT(navigation != nullptr);
|
||||
|
|
|
@ -24,6 +24,7 @@
|
|||
#include "carla/rpc/TrafficLightState.h"
|
||||
|
||||
#include <memory>
|
||||
#include <optional>
|
||||
|
||||
namespace carla {
|
||||
namespace client {
|
||||
|
@ -184,7 +185,7 @@ namespace detail {
|
|||
|
||||
void UnregisterAIController(const WalkerAIController &controller);
|
||||
|
||||
geom::Location GetRandomLocationFromNavigation();
|
||||
boost::optional<geom::Location> GetRandomLocationFromNavigation();
|
||||
|
||||
std::shared_ptr<WalkerNavigation> GetNavigation() {
|
||||
return _episode->GetNavigation();
|
||||
|
@ -351,12 +352,6 @@ namespace detail {
|
|||
_client.SetReplayerTimeFactor(time_factor);
|
||||
}
|
||||
|
||||
/// @}
|
||||
// =========================================================================
|
||||
/// @name Operations with walkers
|
||||
// =========================================================================
|
||||
/// @{
|
||||
|
||||
/// @}
|
||||
// =========================================================================
|
||||
/// @name Operations with sensors
|
||||
|
|
|
@ -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<geom::Location> 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<geom::Location>(random_location);
|
||||
else
|
||||
return {};
|
||||
}
|
||||
|
||||
// set a new target point to go
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
|
||||
#include <iterator>
|
||||
#include <fstream>
|
||||
#include <mutex>
|
||||
|
||||
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<float>(rand()) / static_cast<float>(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<uint8_t> 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<uint8_t> content) {
|
||||
bool Navigation::Load( std::vector<uint8_t> 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<size_t>(tileHeader.dataSize));
|
||||
memcpy(data, &content[pos], static_cast<size_t>(tileHeader.dataSize));
|
||||
pos += static_cast<unsigned long>(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<carla::geom::Location> &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<std::mutex> 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<std::mutex> 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<std::mutex> 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<std::mutex> 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<std::mutex> 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<std::mutex> 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<std::mutex> 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<std::mutex> 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<std::mutex> 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<std::mutex> 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<std::mutex> lock(_mutex);
|
||||
|
||||
// update all
|
||||
_delta_seconds = state.GetTimestamp().delta_seconds;
|
||||
_crowd->update(static_cast<float>(_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<std::mutex> 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<std::mutex> 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<std::mutex> 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<std::mutex> 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<std::mutex> 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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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<uint8_t> content);
|
||||
bool Load(std::vector<uint8_t> 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<carla::geom::Location> &path);
|
||||
|
||||
// create the crowd object
|
||||
|
|
|
@ -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"))
|
||||
|
|
|
@ -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 <typename T>
|
||||
static void PrintListItem_(std::ostream &out, const T &item) {
|
||||
out << item;
|
||||
|
|
|
@ -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"])
|
||||
|
|
|
@ -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<AActor>(Description.Class, Transform, SpawnParameters);
|
||||
|
|
|
@ -39,8 +39,6 @@
|
|||
#include <carla/streaming/Server.h>
|
||||
#include <compiler/enable-ue4-macros.h>
|
||||
|
||||
#include "Components/CapsuleComponent.h"
|
||||
|
||||
#include <vector>
|
||||
|
||||
template <typename T>
|
||||
|
|
Loading…
Reference in New Issue