Skip to content

Commit

Permalink
improving matching to non-ped edges and adding angle #1922
Browse files Browse the repository at this point in the history
  • Loading branch information
behrisch committed Mar 14, 2024
1 parent 76689ff commit 2087175
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 29 deletions.
2 changes: 1 addition & 1 deletion src/libsumo/Helper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1792,7 +1792,7 @@ Helper::moveToXYMap_matchingRoutePosition(const Position& pos, const std::string
}
}

assert(lane != 0);
assert(lane != nullptr);
// quit if no solution was found, reporting a failure
if (lane == nullptr) {
#ifdef DEBUG_MOVEXY
Expand Down
22 changes: 8 additions & 14 deletions src/microsim/devices/MSDevice_FCDReplay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
#include <utils/geom/Position.h>
#include <utils/options/OptionsCont.h>
#include <utils/xml/XMLSubSys.h>
#include <libsumo/Helper.h>
#include <libsumo/Vehicle.h>
#include <microsim/MSNet.h>
#include <microsim/MSEdge.h>
#include <microsim/MSLane.h>
Expand Down Expand Up @@ -105,18 +105,10 @@ MSDevice_FCDReplay::notifyMove(SUMOTrafficObject& veh,
return false;
}
const auto& p = myTrajectory->front();
MSLane* lane = nullptr;
double lanePos;
double lanePosLat = 0;
double bestDistance = std::numeric_limits<double>::max();
int routeOffset = 0;
ConstMSEdgeVector edges;
libsumo::Helper::moveToXYMap_matchingRoutePosition(std::get<0>(p), std::get<1>(p),
v->getRoute().getEdges(), v->getRoutePosition(),
v->getVehicleType().getVehicleClass(), true,
bestDistance, &lane, lanePos, routeOffset);
libsumo::Helper::setRemoteControlled(v, std::get<0>(p), lane, std::get<2>(p), lanePosLat,
libsumo::INVALID_DOUBLE_VALUE, routeOffset, edges, SIMSTEP);
const std::string& edgeID = SUMOXMLDefinitions::getEdgeIDFromLane(std::get<1>(p));
const int laneIdx = SUMOXMLDefinitions::getIndexFromLane(std::get<1>(p));
libsumo::Vehicle::moveToXY(veh.getID(), edgeID, laneIdx, std::get<0>(p).x(), std::get<0>(p).y(),
std::get<4>(p), 7);
v->setPreviousSpeed(std::get<3>(p), std::numeric_limits<double>::min());
myTrajectory->erase(myTrajectory->begin());
if (myTrajectory->empty()) {
Expand Down Expand Up @@ -147,7 +139,8 @@ MSDevice_FCDReplay::FCDHandler::myStartElement(int element, const SUMOSAXAttribu
const std::string edgeOrLane = attrs.getOpt<std::string>(isPerson ? SUMO_ATTR_EDGE : SUMO_ATTR_LANE, id.c_str(), ok, "");
const double speed = attrs.getOpt<double>(SUMO_ATTR_SPEED, id.c_str(), ok, INVALID_DOUBLE);
const double pos = attrs.getOpt<double>(SUMO_ATTR_POSITION, id.c_str(), ok, INVALID_DOUBLE);
myTrajectories[id].push_back({Position(x, y), edgeOrLane, pos, speed});
const double angle = attrs.getOpt<double>(SUMO_ATTR_ANGLE, id.c_str(), ok, INVALID_DOUBLE);
myTrajectories[id].push_back({Position(x, y), edgeOrLane, pos, speed, angle});
const MSEdge* const edge = MSEdge::dictionary(isPerson ? edgeOrLane : SUMOXMLDefinitions::getEdgeIDFromLane(edgeOrLane));
if (myRoutes.count(id) == 0) {
myRoutes[id] = {myTime, type, isPerson, {edge}};
Expand Down Expand Up @@ -189,6 +182,7 @@ MSDevice_FCDReplay::FCDHandler::addTrafficObjects() {
plan->push_back(new MSStageWaiting(std::get<3>(desc.second).front(), nullptr, 0, params->depart, params->departPos, "awaiting departure", true));
plan->push_back(new MSStageWalking(id, std::get<3>(desc.second), nullptr, -1, params->departSpeed, params->departPos, 0, 0));
MSTransportable* person = MSNet::getInstance()->getPersonControl().buildPerson(params, vehicleType, plan, nullptr);
person->getSingularType().setVClass(SVC_IGNORING);
MSNet::getInstance()->getPersonControl().add(person);
MSTransportableDevice_FCDReplay* device = static_cast<MSTransportableDevice_FCDReplay*>(person->getDevice(typeid(MSTransportableDevice_FCDReplay)));
if (device == nullptr) { // Person did not get a replay device
Expand Down
2 changes: 1 addition & 1 deletion src/microsim/devices/MSDevice_FCDReplay.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class MSDevice_FCDReplay : public MSVehicleDevice {
return "fcd-replay";
}

typedef std::vector<std::tuple<Position, std::string, double, double> > Trajectory;
typedef std::vector<std::tuple<Position, std::string, double, double, double> > Trajectory;

void setTrajectory(Trajectory* const t) {
myTrajectory = t;
Expand Down
16 changes: 3 additions & 13 deletions src/microsim/devices/MSTransportableDevice_FCDReplay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@
#include <config.h>

#include <utils/options/OptionsCont.h>
#include <libsumo/Helper.h>
#include <libsumo/Person.h>
#include <microsim/MSEventControl.h>
#include <microsim/MSNet.h>
#include <microsim/transportables/MSPerson.h>
#include <microsim/transportables/MSStageWalking.h>
#include <microsim/transportables/MSTransportable.h>
#include <microsim/transportables/MSTransportableControl.h>
Expand Down Expand Up @@ -97,18 +98,7 @@ MSTransportableDevice_FCDReplay::move() {
return;
}
const auto& p = myTrajectory->front();
MSLane* lane = nullptr;
double lanePos;
double lanePosLat = 0;
double bestDistance = std::numeric_limits<double>::max();
int routeOffset = 0;
ConstMSEdgeVector edges;
libsumo::Helper::moveToXYMap_matchingRoutePosition(std::get<0>(p), std::get<1>(p),
static_cast<MSStageWalking*>(person->getCurrentStage())->getRoute(), person->getRoutePosition(),
person->getVehicleType().getVehicleClass(), true,
bestDistance, &lane, lanePos, routeOffset);
libsumo::Helper::setRemoteControlled(person, std::get<0>(p), lane, std::get<2>(p), lanePosLat,
libsumo::INVALID_DOUBLE_VALUE, routeOffset, edges, SIMSTEP);
libsumo::Person::moveToXY(person->getID(), std::get<1>(p), std::get<0>(p).x(), std::get<0>(p).y(), std::get<4>(p), 7);
// person->setPreviousSpeed(std::get<3>(p), std::numeric_limits<double>::min());
myTrajectory->erase(myTrajectory->begin());
}
Expand Down

0 comments on commit 2087175

Please sign in to comment.