Skip to content

Commit

Permalink
smoothing reaction to pedestrians on walkingarea. refs #11642
Browse files Browse the repository at this point in the history
  • Loading branch information
namdre committed Jun 16, 2023
1 parent b94736f commit 12904ed
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 13 deletions.
29 changes: 18 additions & 11 deletions src/microsim/MSLink.cpp
Expand Up @@ -1776,16 +1776,19 @@ MSLink::checkWalkingAreaFoe(const MSVehicle* ego, const MSLane* foeLane, std::ve
}
#endif
if (dist < ego->getVehicleType().getWidth() / 2 || inFront) {
if (inFront && isOnComingPed(ego, p)) {
// account for pedestrian movement while closing in
const double timeToStop = (ego->getSpeed() + ACCEL2SPEED(ego->getCarFollowModel().getMaxAccel())) / ego->getCarFollowModel().getMaxDecel();
const double pedDist = p->getMaxSpeed() * MAX2(timeToStop, TS);
dist = MAX2(0.0, dist - pedDist);
if (inFront) {
const double oncomingFactor = isOnComingPed(ego, p);
if (oncomingFactor > 0) {
// account for pedestrian movement while closing in
const double timeToStop = (ego->getSpeed() + ACCEL2SPEED(ego->getCarFollowModel().getMaxAccel())) / ego->getCarFollowModel().getMaxDecel();
const double pedDist = p->getMaxSpeed() * MAX2(timeToStop, TS) * oncomingFactor;
dist = MAX2(0.0, dist - pedDist);
#ifdef DEBUG_WALKINGAREA
if (ego->isSelected()) {
std::cout << " timeToStop=" << timeToStop << " pedDist=" << pedDist << " dist2=" << dist << "\n";
}
if (ego->isSelected()) {
std::cout << " timeToStop=" << timeToStop << " pedDist=" << pedDist << " factor=" << oncomingFactor << " dist2=" << dist << "\n";
}
#endif
}
}
if (ignoreFoe(ego, p)) {
continue;
Expand Down Expand Up @@ -1819,16 +1822,20 @@ MSLink::isInFront(const MSVehicle* ego, const PositionVector& egoPath, const Pos
}


bool
double
MSLink::isOnComingPed(const MSVehicle* ego, const MSPerson* p) const {
const double pedToEgoAngle = p->getPosition().angleTo2D(ego->getPosition());
const double angleDiff = fabs(GeomHelper::angleDiff(p->getAngle(), pedToEgoAngle));
#ifdef DEBUG_WALKINGAREA
if (ego->isSelected()) {
std::cout << " ped-angleDiff=" << RAD2DEG(angleDiff) << "\n";
std::cout << " ped-angleDiff=" << RAD2DEG(angleDiff) << " res=" << cos(angleDiff) << "\n";
}
#endif
return angleDiff < DEG2RAD(75);
if (angleDiff <= DEG2RAD(90)) {;
return cos(angleDiff);
} else {
return 0;
}
}


Expand Down
4 changes: 2 additions & 2 deletions src/microsim/MSLink.h
Expand Up @@ -681,8 +681,8 @@ class MSLink {
/// @brief whether the given person is in front of the car
bool isInFront(const MSVehicle* ego, const PositionVector& egoPath, const Position& pPos) const;

/// @brief whether the given person is walking towards the car
bool isOnComingPed(const MSVehicle* ego, const MSPerson* p) const;
/// @brief whether the given person is walking towards the car returned as a factor in [0, 1]
double isOnComingPed(const MSVehicle* ego, const MSPerson* p) const;

/// @brief return extrapolated position of the given person after the given time
Position getFuturePosition(const MSPerson* p, double timeHorizon = 1) const;
Expand Down

0 comments on commit 12904ed

Please sign in to comment.