Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unboard train's passengers through doors when the rail line is curved (#14334) #14336

Merged
merged 3 commits into from
Feb 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions src/guisim/GUIVehicle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
#include <microsim/MSLink.h>
#include <microsim/MSStop.h>
#include <microsim/MSParkingArea.h>
#include <microsim/MSTrainHelper.h>
#include <microsim/logging/CastingFunctionBinding.h>
#include <microsim/logging/FunctionBinding.h>
#include <microsim/lcmodels/MSAbstractLaneChangeModel.h>
Expand All @@ -57,7 +58,6 @@
#include <microsim/devices/MSDevice_BTreceiver.h>
#include <microsim/devices/MSDevice_ElecHybrid.h>
#include <microsim/devices/MSDevice_Battery.h>
#include <microsim/transportables/MSTrainHelper.h>
#include <gui/GUIApplicationWindow.h>
#include <gui/GUIGlobals.h>
#include "GUIVehicle.h"
Expand Down Expand Up @@ -318,9 +318,8 @@ GUIVehicle::drawAction_drawCarriageClass(const GUIVisualizationSettings& s, bool
}
// bool reversed =
MSTrainHelper trainHelper(this, isReversed() && s.drawReversed, s.secondaryShape);
int numCarriages = trainHelper.getNumCarriages();
const int firstPassengerCarriage = trainHelper.getDefaultLength() == trainHelper.getLocomotiveLength() || numCarriages == 1
|| (getVClass() & (SVC_RAIL_ELECTRIC | SVC_RAIL_FAST | SVC_RAIL)) == 0 ? 0 : 1;
const int numCarriages = trainHelper.getNumCarriages();
const int firstPassengerCarriage = trainHelper.getFirstPassengerCarriage();
const int noPersonsBackCarriages = (getVehicleType().getGuiShape() == SUMOVehicleShape::TRUCK_SEMITRAILER || getVehicleType().getGuiShape() == SUMOVehicleShape::TRUCK_1TRAILER) && numCarriages > 1 ? 1 : 0;
const int firstContainerCarriage = numCarriages == 1 || getVehicleType().getGuiShape() == SUMOVehicleShape::TRUCK_1TRAILER ? 0 : 1;
const int seatsPerCarriage = (int)ceil(getVType().getPersonCapacity() / (numCarriages - firstPassengerCarriage - noPersonsBackCarriages));
Expand Down
2 changes: 2 additions & 0 deletions src/microsim/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ set(microsim_STAT_SRCS
MSDriverState.cpp
Command_RouteReplacement.h
Command_RouteReplacement.cpp
MSTrainHelper.cpp
MSTrainHelper.h
)

add_library(microsim STATIC ${microsim_STAT_SRCS})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ MSTrainHelper::getCarriageShapes(void) {
for (const Carriage* carriage: myCarriages) {
Position direction = carriage->front - carriage->back;
Position perp = Position(-direction.y(), direction.x());
perp.norm2D();
PositionVector shape;
shape.push_back(carriage->front + perp*myHalfWidth);
shape.push_back(carriage->front - perp*myHalfWidth);
Expand Down Expand Up @@ -73,6 +74,7 @@ MSTrainHelper::computeTrainDimensions(double exaggeration) {
myCarriageLengthWithGap = (myLength - myLocomotiveLength) / (myNumCarriages - 1);
myCarriageLength = myCarriageLengthWithGap - myCarriageGap;
}
myCarriageDoors = vtype.getParameter().carriageDoors;
}


Expand Down Expand Up @@ -102,6 +104,9 @@ MSTrainHelper::computeCarriages(bool secondaryShape, bool reversed) {
}
}

myFirstPassengerCarriage = myDefaultLength == myLocomotiveLength || myNumCarriages == 1
|| (myTrain->getVClass() & (SVC_RAIL_ELECTRIC | SVC_RAIL_FAST | SVC_RAIL)) == 0 ? 0 : 1;

const double lateralOffset = (myTrain->isParking() && myTrain->getNextStopParameter()->posLat == INVALID_DOUBLE
? (myTrain->getLane()->getWidth() * (MSGlobals::gLefthand ? -1 : 1))
: -myTrain->getLateralPositionOnLane());
Expand Down Expand Up @@ -141,7 +146,13 @@ MSTrainHelper::computeCarriages(bool secondaryShape, bool reversed) {

carriage->front = lane->getShape(secondaryShape).positionAtOffset(carriageOffset * lane->getLengthGeometryFactor(secondaryShape), lateralOffset);
carriage->back = backLane->getShape(secondaryShape).positionAtOffset(carriageBackOffset * lane->getLengthGeometryFactor(secondaryShape), lateralOffset);
// TODO: compute the doors.
Position direction = carriage->front - carriage->back;
direction.norm2D();
double carriageLength = (i == myFirstCarriageNo ? myLocomotiveLength : myCarriageLengthWithGap - myCarriageGap);
for (int j = 1; j <= myCarriageDoors; j++) {
const double doorOffset = j * carriageLength / (myCarriageDoors + 1);
carriage->doors.push_back(carriage->front - direction*doorOffset);
}
myCarriages.push_back(carriage);

carriageOffset -= (curCLength + myCarriageGap);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class MSVehicle;
*/
class MSTrainHelper {
public:
MSTrainHelper(const MSVehicle* vehicle, bool reversed, bool secondaryShape=false, double exaggeration=1.0)
MSTrainHelper(const MSVehicle* vehicle, bool reversed=false, bool secondaryShape=false, double exaggeration=1.0)
: myTrain(vehicle) {
computeTrainDimensions(exaggeration);
computeCarriages(secondaryShape, reversed);
Expand Down Expand Up @@ -92,9 +92,17 @@ class MSTrainHelper {
return myFirstCarriageLength;
}

inline int getCarriageDoors(void) const {
return myCarriageDoors;
}

inline int getFirstCarriageNo(void) const {
return myFirstCarriageNo;
}

inline int getFirstPassengerCarriage(void) const {
return myFirstPassengerCarriage;
}

inline bool isReversed(void) const {
return myIsReversed;
Expand Down Expand Up @@ -125,10 +133,12 @@ class MSTrainHelper {
double myCarriageLengthWithGap;
double myCarriageLength;
double myFirstCarriageLength;
int myCarriageDoors;
int myFirstCarriageNo;
int myFirstPassengerCarriage;
bool myIsReversed;
std::vector<Carriage*> myCarriages;

void computeTrainDimensions(double exaggeration);
void computeCarriages(bool secondaryShape, bool reversed);
};
};
2 changes: 0 additions & 2 deletions src/microsim/transportables/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ set(microsim_transportables_STAT_SRCS
MSTransportable.h
MSTransportableControl.cpp
MSTransportableControl.h
MSTrainHelper.cpp
MSTrainHelper.h
${microsim_transportables_JPS_SRCS}
)

Expand Down
37 changes: 18 additions & 19 deletions src/microsim/transportables/MSStageDriving.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,14 @@
#include <microsim/MSInsertionControl.h>
#include <microsim/MSVehicleControl.h>
#include <microsim/MSStoppingPlace.h>
#include <microsim/transportables/MSPerson.h>
#include <microsim/MSTrainHelper.h>
#include <microsim/devices/MSTransportableDevice.h>
#include <microsim/devices/MSDevice_Taxi.h>
#include <microsim/devices/MSDevice_Tripinfo.h>
#include <microsim/transportables/MSTransportableControl.h>
#include <microsim/transportables/MSStageDriving.h>
#include <microsim/transportables/MSPModel.h>
#include <microsim/transportables/MSPerson.h>


#define DEFAULT_CARRIAGE_DOOR_WIDTH 1.5
Expand Down Expand Up @@ -429,25 +430,23 @@ MSStageDriving::setArrived(MSNet* net, MSTransportable* transportable, SUMOTime
}
}
if (useDoors) {
// TODO refactor this with GUIVehicle::drawAction_drawCarriageClass
const SUMOVTypeParameter& pars = myVehicle->getVehicleType().getParameter();
const double totalLength = myVehicle->getVehicleType().getLength();
const int numCarriages = MAX2(1, 1 + (int)((totalLength - pars.locomotiveLength) / (pars.carriageLength + pars.carriageGap) + 0.5));
const int firstPassengerCarriage = numCarriages == 1
|| (myVehicle->getVClass() & (SVC_RAIL_ELECTRIC | SVC_RAIL_FAST | SVC_RAIL)) == 0 ? 0 : 1;
const int randomCarriage = RandHelper::rand(numCarriages - firstPassengerCarriage) + firstPassengerCarriage;
const double positionOnLane = myVehicle->getPositionOnLane();
if (randomCarriage == 0) {
const double randomDoorOffset = (RandHelper::rand(pars.carriageDoors) + 1.) / (pars.carriageDoors + 1.) * pars.locomotiveLength;
myArrivalPos = positionOnLane - randomDoorOffset;
} else {
const double carriageLengthWithGap = totalLength / numCarriages;
const double frontPosOnLane = positionOnLane - pars.locomotiveLength - pars.carriageGap - carriageLengthWithGap * (randomCarriage - 1);
const double randomDoorOffset = (RandHelper::rand(pars.carriageDoors) + 1.) / (pars.carriageDoors + 1.) * (carriageLengthWithGap - pars.carriageGap);
myArrivalPos = frontPosOnLane - randomDoorOffset;
const MSVehicle* train = dynamic_cast<const MSVehicle*>(myVehicle);
if (train != nullptr) {
const MSTrainHelper trainHelper(train);
const std::vector<MSTrainHelper::Carriage*>& carriages = trainHelper.getCarriages();
const int randomCarriageIx = RandHelper::rand(trainHelper.getNumCarriages() - trainHelper.getFirstPassengerCarriage()) + trainHelper.getFirstPassengerCarriage();
const MSTrainHelper::Carriage* randomCarriage = carriages[randomCarriageIx];
const int randomDoorIx = RandHelper::rand(trainHelper.getCarriageDoors());
Position randomDoor = randomCarriage->doors[randomDoorIx];
// Jitter the position before projection because of possible train curvature.
Position direction = randomCarriage->front - randomCarriage->back;
direction.norm2D();
randomDoor.add(direction * RandHelper::rand(-0.5 * DEFAULT_CARRIAGE_DOOR_WIDTH, 0.5 * DEFAULT_CARRIAGE_DOOR_WIDTH));
// Project onto the lane.
myArrivalPos = myVehicle->getLane()->getShape().nearest_offset_to_point2D(randomDoor);
myArrivalPos = myVehicle->getLane()->interpolateGeometryPosToLanePos(myArrivalPos);
myArrivalPos = MIN2(MAX2(0., myArrivalPos), myVehicle->getEdge()->getLength());
}
myArrivalPos += RandHelper::rand(-0.5 * DEFAULT_CARRIAGE_DOOR_WIDTH, 0.5 * DEFAULT_CARRIAGE_DOOR_WIDTH);
myArrivalPos = MIN2(MAX2(0., myArrivalPos), myVehicle->getEdge()->getLength());
}
}
} else {
Expand Down
Loading
Loading