Unblocking walkers when they are blocked by something
This commit is contained in:
parent
5b7fcbd689
commit
0ee3dd0305
|
@ -55,6 +55,10 @@ namespace nav {
|
|||
static const int MAX_QUERY_SEARCH_NODES = 2048;
|
||||
static const float AGENT_HEIGHT = 1.8f;
|
||||
static const float AGENT_RADIUS = 0.3f;
|
||||
|
||||
static const float AGENT_LOW_SPEED = 0.5f;
|
||||
static const float AGENT_LOW_SPEED_SQUARED = AGENT_LOW_SPEED * AGENT_LOW_SPEED;
|
||||
static const float AGENT_LOW_SPEED_TIME = 3.0f;
|
||||
|
||||
static const float AREA_WATER_COST = 10.0f;
|
||||
|
||||
|
@ -67,6 +71,7 @@ namespace nav {
|
|||
_ready = false;
|
||||
_mappedWalkersId.clear();
|
||||
_mappedVehiclesId.clear();
|
||||
_walkersBlockedTime.clear();
|
||||
_yaw_walkers.clear();
|
||||
_binaryMesh.clear();
|
||||
dtFreeCrowd(_crowd);
|
||||
|
@ -359,7 +364,7 @@ namespace nav {
|
|||
params.collisionQueryRange = params.radius * 15.0f;
|
||||
params.pathOptimizationRange = params.radius * 30.0f;
|
||||
params.obstacleAvoidanceType = 3;
|
||||
params.separationWeight = 0.1f;
|
||||
params.separationWeight = 0.3f;
|
||||
|
||||
// set if the agent can cross roads or not
|
||||
if (frand() <= _probabilityCrossing) {
|
||||
|
@ -469,7 +474,7 @@ namespace nav {
|
|||
params.collisionQueryRange = params.radius * 20.0f;
|
||||
params.pathOptimizationRange = 0.0f;
|
||||
params.obstacleAvoidanceType = 3;
|
||||
params.separationWeight = 0.1f;
|
||||
params.separationWeight = 0.5f;
|
||||
|
||||
// flags
|
||||
params.updateFlags = 0;
|
||||
|
@ -693,15 +698,40 @@ namespace nav {
|
|||
continue;
|
||||
}
|
||||
|
||||
// count the time the agent is quiet or in low speed
|
||||
float speed = carla::geom::Vector3D(ag->nvel[0], ag->nvel[1], ag->nvel[2]).SquaredLength();
|
||||
bool resetTargetPos = false;
|
||||
bool useSameFilter = false;
|
||||
if (speed <= AGENT_LOW_SPEED_SQUARED) {
|
||||
// count time
|
||||
_walkersBlockedTime[i] += _delta_seconds;
|
||||
// check time
|
||||
if (_walkersBlockedTime[i] >= AGENT_LOW_SPEED_TIME) {
|
||||
resetTargetPos = true;
|
||||
useSameFilter = true;
|
||||
_walkersBlockedTime[i] = 0;
|
||||
}
|
||||
} else {
|
||||
// reset time
|
||||
_walkersBlockedTime[i] = 0;
|
||||
}
|
||||
|
||||
// check distance to the target point
|
||||
const float *end = &ag->cornerVerts[(ag->ncorners - 1) * 3];
|
||||
carla::geom::Vector3D dist(end[0] - ag->npos[0], end[1] - ag->npos[1], end[2] - ag->npos[2]);
|
||||
if (dist.SquaredLength() <= 2) {
|
||||
resetTargetPos = true;
|
||||
}
|
||||
|
||||
// check to assign a new target position
|
||||
if (resetTargetPos) {
|
||||
// set if the agent can cross roads or not
|
||||
if (frand() <= _probabilityCrossing) {
|
||||
SetAgentFilter(i, 1);
|
||||
} else {
|
||||
SetAgentFilter(i, 0);
|
||||
if (!useSameFilter) {
|
||||
if (frand() <= _probabilityCrossing) {
|
||||
SetAgentFilter(i, 1);
|
||||
} else {
|
||||
SetAgentFilter(i, 0);
|
||||
}
|
||||
}
|
||||
// set a new random target
|
||||
carla::geom::Location location;
|
||||
|
|
|
@ -90,8 +90,10 @@ namespace nav {
|
|||
/// mapping Id
|
||||
std::unordered_map<ActorId, int> _mappedWalkersId;
|
||||
std::unordered_map<ActorId, int> _mappedVehiclesId;
|
||||
/// Store walkers yaw angle from previous tick
|
||||
/// store walkers yaw angle from previous tick
|
||||
std::unordered_map<ActorId, float> _yaw_walkers;
|
||||
/// saves how much time an agent is quiet or in low speed (to avoid agents blocked by some reason)
|
||||
std::unordered_map<int, float> _walkersBlockedTime;
|
||||
|
||||
mutable std::mutex _mutex;
|
||||
|
||||
|
|
|
@ -148,7 +148,7 @@ def main():
|
|||
walker_bp.set_attribute('is_invincible', 'false')
|
||||
# set the max speed
|
||||
if walker_bp.has_attribute('speed'):
|
||||
walker_speed.append(random.choice(walker_bp.get_attribute('speed').recommended_values))
|
||||
walker_speed.append(random.choice(walker_bp.get_attribute('speed').recommended_values[1:]))
|
||||
else:
|
||||
print("Walker has no speed")
|
||||
walker_speed.append(0.0)
|
||||
|
@ -184,7 +184,7 @@ def main():
|
|||
|
||||
# 5. initialize each controller and set target to walk to (list is [controler, actor, controller, actor ...])
|
||||
# set how many pedestrians can cross the road
|
||||
world.set_pedestrians_cross_factor(0.05)
|
||||
world.set_pedestrians_cross_factor(0.5)
|
||||
for i in range(0, len(all_id), 2):
|
||||
# start walker
|
||||
all_actors[i].start()
|
||||
|
|
Loading…
Reference in New Issue