Pedestrians check if a vehicle is near before crossing

This commit is contained in:
bernatx 2019-10-23 11:10:23 +02:00 committed by bernat
parent 3280e1bd6e
commit 1c4b8c4bea
7 changed files with 39 additions and 13 deletions

View File

@ -47,9 +47,9 @@ namespace nav {
static const int MAX_AGENTS = 500; static const int MAX_AGENTS = 500;
static const int MAX_QUERY_SEARCH_NODES = 2048; static const int MAX_QUERY_SEARCH_NODES = 2048;
static const float AGENT_HEIGHT = 1.8f; static const float AGENT_HEIGHT = 1.8f;
static const float AGENT_RADIUS = 0.3f; static const float AGENT_RADIUS = 0.4f;
static const float AGENT_UNBLOCK_DISTANCE = 1.0f; static const float AGENT_UNBLOCK_DISTANCE = 0.5f;
static const float AGENT_UNBLOCK_DISTANCE_SQUARED = AGENT_UNBLOCK_DISTANCE * AGENT_UNBLOCK_DISTANCE; static const float AGENT_UNBLOCK_DISTANCE_SQUARED = AGENT_UNBLOCK_DISTANCE * AGENT_UNBLOCK_DISTANCE;
static const float AGENT_UNBLOCK_TIME = 2.0f; static const float AGENT_UNBLOCK_TIME = 2.0f;
@ -545,8 +545,8 @@ namespace nav {
DEBUG_ASSERT(_crowd != nullptr); DEBUG_ASSERT(_crowd != nullptr);
// get the bounding box extension plus some space around // get the bounding box extension plus some space around
float hx = vehicle.bounding.extent.x + 1.5f; float hx = vehicle.bounding.extent.x + 1.0f;
float hy = vehicle.bounding.extent.y + 1.5f; float hy = vehicle.bounding.extent.y + 1.0f;
// define the 4 corners of the bounding box // define the 4 corners of the bounding box
cg::Vector3D boxCorner1 {-hx, -hy, 0}; cg::Vector3D boxCorner1 {-hx, -hy, 0};
cg::Vector3D boxCorner2 { hx, -hy, 0}; cg::Vector3D boxCorner2 { hx, -hy, 0};
@ -1160,5 +1160,24 @@ namespace nav {
agent->paused = pause; agent->paused = pause;
} }
bool Navigation::hasVehicleNear(ActorId id) {
// get the internal index (walker or vehicle)
auto it = _mappedWalkersId.find(id);
if (it == _mappedWalkersId.end()) {
it = _mappedVehiclesId.find(id);
if (it == _mappedVehiclesId.end()) {
return false;
}
}
bool result;
{
// critical section, force single thread running this
std::lock_guard<std::mutex> lock(_mutex);
result = _crowd->hasVehicleNear(it->second);
}
return result;
}
} // namespace nav } // namespace nav
} // namespace carla } // namespace carla

View File

@ -93,6 +93,8 @@ namespace nav {
void SetPedestriansCrossFactor(float percentage); void SetPedestriansCrossFactor(float percentage);
/// set an agent as paused for the crowd /// set an agent as paused for the crowd
void PauseAgent(ActorId id, bool pause); void PauseAgent(ActorId id, bool pause);
/// return if the agent has a vehicle near (as neighbour)
bool hasVehicleNear(ActorId id);
dtCrowd *GetCrowd() { return _crowd; }; dtCrowd *GetCrowd() { return _crowd; };

View File

@ -5,6 +5,7 @@
// For a copy, see <https://opensource.org/licenses/MIT>. // For a copy, see <https://opensource.org/licenses/MIT>.
#include "carla/Logging.h" #include "carla/Logging.h"
#include "carla/nav/Navigation.h"
#include "carla/nav/WalkerEvent.h" #include "carla/nav/WalkerEvent.h"
namespace carla { namespace carla {
@ -21,9 +22,8 @@ namespace nav {
} }
bool WalkerEventVisitor::operator()(WalkerEventStopAndCheck &event, double delta) { bool WalkerEventVisitor::operator()(WalkerEventStopAndCheck &event, double delta) {
// refresh time and check // check if the agent has any vehicle around
event.time -= delta; return (!event.nav->hasVehicleNear(event.id));
return (event.time <= 0.0f);
} }
} // namespace nav } // namespace nav

View File

@ -8,9 +8,14 @@
#include <boost/variant.hpp> #include <boost/variant.hpp>
#include "carla/rpc/ActorId.h"
// #include "carla/nav/Navigation.h"
namespace carla { namespace carla {
namespace nav { namespace nav {
class Navigation;
struct WalkerEventIgnore { struct WalkerEventIgnore {
}; };
@ -20,8 +25,9 @@ namespace nav {
}; };
struct WalkerEventStopAndCheck { struct WalkerEventStopAndCheck {
double time; ActorId id;
WalkerEventStopAndCheck(double duration) : time(duration) {}; Navigation *nav;
WalkerEventStopAndCheck(ActorId id, Navigation *nav) : id(id), nav(nav) {};
}; };
using WalkerEvent = boost::variant<WalkerEventIgnore, WalkerEventWait, WalkerEventStopAndCheck>; using WalkerEvent = boost::variant<WalkerEventIgnore, WalkerEventWait, WalkerEventStopAndCheck>;

View File

@ -123,8 +123,7 @@ namespace nav {
// stop and check // stop and check
case SAMPLE_POLYAREA_ROAD: case SAMPLE_POLYAREA_ROAD:
case SAMPLE_POLYAREA_CROSS: case SAMPLE_POLYAREA_CROSS:
// info.route.emplace_back(WalkerEventStopAndCheck(4), std::move(path[i])); info.route.emplace_back(WalkerEventStopAndCheck(id, _nav), std::move(path[i]));
info.route.emplace_back(WalkerEventIgnore(), std::move(path[i]));
break; break;
default: default:

View File

@ -289,7 +289,7 @@ unset GTEST_BASENAME
# -- Get Recast&Detour and compile it with libc++ ------------------------------ # -- Get Recast&Detour and compile it with libc++ ------------------------------
# ============================================================================== # ==============================================================================
RECAST_COMMIT="163651bfa4aab314a1a3e7b1c476b3cbc5e4fdf1" RECAST_COMMIT="8af33f0c5ae996fe4223d2d40852c5fd06cf9f36"
RECAST_BASENAME=recast-${CXX_TAG} RECAST_BASENAME=recast-${CXX_TAG}
RECAST_INCLUDE=${PWD}/${RECAST_BASENAME}-install/include RECAST_INCLUDE=${PWD}/${RECAST_BASENAME}-install/include

View File

@ -38,7 +38,7 @@ set RECAST_INSTALL=recast-install
set RECAST_INSTALL_DIR=%BUILD_DIR%%RECAST_INSTALL%\ set RECAST_INSTALL_DIR=%BUILD_DIR%%RECAST_INSTALL%\
set RECAST_BUILD_DIR=%RECAST_SRC_DIR%build set RECAST_BUILD_DIR=%RECAST_SRC_DIR%build
set RECAST_COMMIT="163651bfa4aab314a1a3e7b1c476b3cbc5e4fdf1" set RECAST_COMMIT="8af33f0c5ae996fe4223d2d40852c5fd06cf9f36"
set RECAST_BASENAME=%RECAST_SRC% set RECAST_BASENAME=%RECAST_SRC%