Skip to content

Commit

Permalink
transportables now actually move #1922
Browse files Browse the repository at this point in the history
  • Loading branch information
behrisch committed Mar 14, 2024
1 parent 4d6c7fd commit 76689ff
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 23 deletions.
3 changes: 2 additions & 1 deletion src/microsim/devices/MSDevice_FCDReplay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@
#include <microsim/MSEdge.h>
#include <microsim/MSLane.h>
#include <microsim/MSRoute.h>
#include <microsim/MSEventControl.h>
#include <microsim/MSInsertionControl.h>
#include <microsim/transportables/MSTransportableControl.h>
#include <microsim/transportables/MSStageWaiting.h>
#include <microsim/transportables/MSStageWalking.h>
#include "MSTransportableDevice_FCDReplay.h"
#include "MSDevice_FCDReplay.h"

Expand Down Expand Up @@ -187,6 +187,7 @@ MSDevice_FCDReplay::FCDHandler::addTrafficObjects() {
if (isPerson) {
MSTransportable::MSTransportablePlan* plan = new MSTransportable::MSTransportablePlan();
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);
MSNet::getInstance()->getPersonControl().add(person);
MSTransportableDevice_FCDReplay* device = static_cast<MSTransportableDevice_FCDReplay*>(person->getDevice(typeid(MSTransportableDevice_FCDReplay)));
Expand Down
54 changes: 37 additions & 17 deletions src/microsim/devices/MSTransportableDevice_FCDReplay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,20 @@

#include <utils/options/OptionsCont.h>
#include <libsumo/Helper.h>
#include <microsim/MSEventControl.h>
#include <microsim/MSNet.h>
#include <microsim/transportables/MSStageWalking.h>
#include <microsim/transportables/MSTransportable.h>
#include <microsim/transportables/MSTransportableControl.h>
#include "MSTransportableDevice_FCDReplay.h"


// ===========================================================================
// static member initializations
// ===========================================================================
bool MSTransportableDevice_FCDReplay::myAmActive = false;


// ===========================================================================
// method definitions
// ===========================================================================
Expand All @@ -42,6 +53,10 @@ MSTransportableDevice_FCDReplay::buildDevices(MSTransportable& t, std::vector<MS
if (equippedByDefaultAssignmentOptions(oc, "fcd-replay", t, oc.isSet("device.fcd-replay.file"), true)) {
MSTransportableDevice_FCDReplay* device = new MSTransportableDevice_FCDReplay(t, "fcdReplay_" + t.getID());
into.push_back(device);
if (!myAmActive) {
MSNet::getInstance()->getBeginOfTimestepEvents()->addEvent(new MovePedestrians(), SIMSTEP + DELTA_T);
myAmActive = true;
}
}
}

Expand All @@ -58,18 +73,28 @@ MSTransportableDevice_FCDReplay::~MSTransportableDevice_FCDReplay() {
}


bool
MSTransportableDevice_FCDReplay::notifyMove(SUMOTrafficObject& t,
double /*oldPos*/,
double /*newPos*/,
double /*newSpeed*/) {
if (myTrajectory == nullptr || myTrajectory->empty()) {
// TODO remove person
return false;
SUMOTime
MSTransportableDevice_FCDReplay::MovePedestrians::execute(SUMOTime /* currentTime */) {
MSTransportableControl& c = MSNet::getInstance()->getPersonControl();
for (MSTransportableControl::constVehIt i = c.loadedBegin(); i != c.loadedEnd(); ++i) {
MSTransportableDevice_FCDReplay* device = static_cast<MSTransportableDevice_FCDReplay*>(i->second->getDevice(typeid(MSTransportableDevice_FCDReplay)));
if (device != nullptr) {
device->move();
}
}
MSPerson* person = dynamic_cast<MSPerson*>(&t);
if (person == nullptr) {
return false;
return DELTA_T;
}


void
MSTransportableDevice_FCDReplay::move() {
MSPerson* person = dynamic_cast<MSPerson*>(&myHolder);
if (person == nullptr || !person->hasDeparted()) {
return;
}
if (myTrajectory == nullptr || myTrajectory->empty()) {
myHolder.removeStage(0, false);
return;
}
const auto& p = myTrajectory->front();
MSLane* lane = nullptr;
Expand All @@ -79,18 +104,13 @@ MSTransportableDevice_FCDReplay::notifyMove(SUMOTrafficObject& t,
int routeOffset = 0;
ConstMSEdgeVector edges;
libsumo::Helper::moveToXYMap_matchingRoutePosition(std::get<0>(p), std::get<1>(p),
{person->getEdge()}, 0,
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);
// person->setPreviousSpeed(std::get<3>(p), std::numeric_limits<double>::min());
myTrajectory->erase(myTrajectory->begin());
if (myTrajectory->empty()) {
// TODO remove person
return false;
}
return true;
}


Expand Down
19 changes: 14 additions & 5 deletions src/microsim/devices/MSTransportableDevice_FCDReplay.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#pragma once
#include <config.h>

#include <utils/common/Command.h>
#include "MSTransportableDevice.h"
#include "MSDevice_FCDReplay.h"

Expand Down Expand Up @@ -59,11 +60,6 @@ class MSTransportableDevice_FCDReplay : public MSTransportableDevice {
/// @brief Destructor.
~MSTransportableDevice_FCDReplay();

bool notifyMove(SUMOTrafficObject& veh,
double oldPos,
double newPos,
double newSpeed);

/// @brief return the name for this type of device
const std::string deviceName() const {
return "fcd-replay";
Expand All @@ -73,6 +69,8 @@ class MSTransportableDevice_FCDReplay : public MSTransportableDevice {
myTrajectory = t;
}

void move();

private:
/** @brief Constructor
*
Expand All @@ -81,9 +79,20 @@ class MSTransportableDevice_FCDReplay : public MSTransportableDevice {
*/
MSTransportableDevice_FCDReplay(MSTransportable& holder, const std::string& id);

class MovePedestrians : public Command {
public:
SUMOTime execute(SUMOTime currentTime);
private:
/// @brief Invalidated assignment operator.
MovePedestrians& operator=(const MovePedestrians&) = delete;
};

private:
MSDevice_FCDReplay::Trajectory* myTrajectory = nullptr;

/// @brief whether an event for pedestrian processing was added
static bool myAmActive;

private:
/// @brief Invalidated copy constructor.
MSTransportableDevice_FCDReplay(const MSTransportableDevice_FCDReplay&);
Expand Down

0 comments on commit 76689ff

Please sign in to comment.