21 #include <grpc++/grpc++.h> 26 #include "hybridsim.grpc.pb.h" 31 using grpc::ClientContext;
36 const std::string address = oc.
getString(
"pedestrian.remote.address");
37 myHybridsimStub = hybridsim::HybridSimulation::NewStub(grpc::CreateChannel(
38 address, grpc::InsecureChannelCredentials()));
60 double offset = departureOffsetAlongLane == 0 ? 0.4 : -0.4;
61 departureOffsetAlongLane += offset;
64 hybridsim::Coordinate* departureCoordinate = req.mutable_enterlocation();
65 departureCoordinate->set_x(departurePos.
x());
66 departureCoordinate->set_y(departurePos.
y());
71 hybridsim::Coordinate* arrivalCoordinate = req.mutable_leavelocation();
72 arrivalCoordinate->set_x(arrivalPos.
x());
73 arrivalCoordinate->set_y(arrivalPos.
y());
77 for (ConstMSEdgeVector::const_iterator it = stage->
getRoute().begin(); it != stage->
getRoute().end(); it++) {
82 const MSEdge* nxt = *(it + 1);
97 int frId = dir ==
FORWARD ? std::get<0>(transitions) : std::get<1>(transitions);
98 int toId = dir ==
FORWARD ? std::get<1>(transitions) : std::get<0>(transitions);
99 hybridsim::Destination* destFr = req.add_dests();
100 destFr->set_id(frId);
101 hybridsim::Destination* destTo = req.add_dests();
102 destTo->set_id(toId);
106 hybridsim::Boolean rpl;
107 ClientContext context;
110 ProcessError(
"Person: " + person->
getID() +
" could not be transferred to remote simulation");
114 ProcessError(
"Remote simulation declined to accept person: " + person->
getID() +
".");
122 hybridsim::Empty req;
123 hybridsim::Empty rpl;
124 ClientContext context1;
135 hybridsim::LeftClosedRightOpenTimeInterval interval;
136 interval.set_fromtimeincluding(time /
DELTA_T);
141 hybridsim::Empty rpl;
142 ClientContext context1;
143 Status st =
myHybridsimStub->simulatedTimeInerval(&context1, interval, &rpl);
149 hybridsim::Empty req2;
150 hybridsim::Trajectories trajectories;
151 ClientContext context2;
152 Status st2 =
myHybridsimStub->receiveTrajectories(&context2, req2, &trajectories);
154 ProcessError(
"Could not receive trajectories from remote simulation");
156 for (hybridsim::Trajectory trajectory : trajectories.trajectories()) {
159 pState->
setPosition(trajectory.x(), trajectory.y());
160 pState->
setPhi(trajectory.phi());
165 if (nextTargetEdge == nextStageEdge) {
167 std::cout <<
"next edge" << std::endl;
177 hybridsim::Empty req3;
178 hybridsim::Agents agents;
179 ClientContext context3;
180 Status st3 =
myHybridsimStub->queryRetrievableAgents(&context3, req3, &agents);
185 for (hybridsim::Agent agent : agents.agents()) {
196 hybridsim::Empty rpl2;
197 ClientContext context4;
198 Status st4 =
myHybridsimStub->confirmRetrievedAgents(&context4, agents, &rpl2);
223 hybridsim::Scenario req;
227 if (e->isInternal()) {
230 if (e->isWalkingArea()) {
234 for (
MSLane* l : e->getLanes()) {
242 hybridsim::Edge* edge = req.add_edges();
247 edge->set_type(hybridsim::Edge_Type_OBSTACLE);
249 edge = req.add_edges();
254 edge->set_type(hybridsim::Edge_Type_OBSTACLE);
256 edge = req.add_edges();
261 edge->set_type(hybridsim::Edge_Type_OBSTACLE);
263 edge = req.add_edges();
268 edge->set_type(hybridsim::Edge_Type_OBSTACLE);
271 hybridsim::Empty rpl;
272 ClientContext context;
275 ProcessError(
"Remote side could not initialize scenario!");
283 if (shape.size() < 2) {
293 hybridsim::Edge* edge = scenario.add_edges();
294 edge->mutable_c0()->set_x(frst.
x());
295 edge->mutable_c0()->set_y(frst.
y());
296 edge->mutable_c1()->set_x(scnd.
x());
297 edge->mutable_c1()->set_y(scnd.
y());
298 edge->set_type(hybridsim::Edge_Type_OBSTACLE);
305 if (centerLine.size() < 2) {
316 hybridsim::Edge_Type edgeType;
318 edgeType = hybridsim::Edge_Type_TRANSITION_HOLDOVER;
320 edgeType = hybridsim::Edge_Type_TRANSITION_INTERNAL;
322 edgeType = hybridsim::Edge_Type_TRANSITION;
326 Position frst = *centerLine.begin();
327 Position scnd = *(centerLine.begin() + 1);
329 Position thrd = *(centerLine.end() - 1);
330 Position frth = *(centerLine.end() - 2);
341 hybridsim::Edge_Type type,
int id) {
343 double dx = scnd.
x() - frst.
x();
344 double dy = scnd.
y() - frst.
y();
345 double length = sqrt(dx * dx + dy * dy);
348 double x0 = frst.
x() - dy * width / 2.;
349 double y0 = frst.
y() + dx * width / 2.;
350 double x1 = frst.
x() + dy * width / 2.;
351 double y1 = frst.
y() - dx * width / 2.;
352 hybridsim::Edge* edge = scenario.add_edges();
353 edge->mutable_c0()->set_x(x0);
354 edge->mutable_c0()->set_y(y0);
355 edge->mutable_c1()->set_x(x1);
356 edge->mutable_c1()->set_y(y1);
357 edge->set_type(type);
362 PositionVector::const_iterator it = shape.begin();
367 for (; it != shape.end(); it++) {
368 hybridsim::Edge* edge = scenario.add_edges();
369 edge->mutable_c0()->set_x(frst.
x());
370 edge->mutable_c0()->set_y(frst.
y());
371 edge->mutable_c1()->set_x((*it).x());
372 edge->mutable_c1()->set_y((*it).y());
373 edge->set_type(hybridsim::Edge_Type_OBSTACLE);
385 : myPerson(person), myPhi(0), myPosition(0, 0), myStage(stage) {
double xmax() const
Returns maximum x-coordinate.
PState(MSPerson *person, MSPerson::MSPersonStage_Walking *stage)
double getDepartPos() const
virtual void cleanupHelper()
MSEdge & getEdge() const
Returns the lane's edge.
double getWidth() const
Returns the lane's width.
const MSEdge * getNextRouteEdge() const
double getArrivalPos() const
const std::vector< MSLane * > & getLanes() const
Returns this edge's lanes.
double ymax() const
Returns maximum y-coordinate.
MSLane * getFirstPedestrianLane(const MSEdge *const &edge)
double x() const
Returns the x-position.
bool hasInternalLinks() const
return whether the network contains internal links
void makeStartOrEndTransition(Position position, Position scnd, double width, hybridsim::Scenario &scenario, hybridsim::Edge_Type type, int i)
bool isWalkingArea() const
return whether this edge is walking area
MSPModel_Remote(const OptionsCont &oc, MSNet *net)
MSPerson::MSPersonStage_Walking * getStage()
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
const std::string & getID() const
returns the id of the transportable
const MSEdge * getNextEdge(const MSPerson::MSPersonStage_Walking &stage) const override
return the list of internal edges if the pedestrian is on an intersection
std::map< int, const MSEdge * > transitionsEdgesMapping
void handlePedestrianLane(MSLane *pLane, hybridsim::Scenario &scenario)
void set(double x, double y)
set positions x and y
SUMOTime getCurrentTimeStep() const
Returns the current simulation step.
SUMOTime execute(SUMOTime time)
The simulated network and simulation perfomer.
std::string getString(const std::string &name) const
Returns the string-value of the named option (only for Option_String)
const std::string & getID() const
Returns the id.
A road/street connecting two junctions.
bool moveToNextEdge(MSPerson *person, SUMOTime currentTime, MSEdge *nextInternal=0)
move forward and return whether the person arrived
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
std::map< int, PState * > remoteIdPStateMapping
A point in 2D or 3D with translation and scaling methods.
const ConstMSEdgeVector & getRoute() const
StageType getCurrentStageType() const
the current stage type of the transportable
MSEventControl * getBeginOfTimestepEvents()
Returns the event control for events executed at the begin of a time step.
double y() const
Returns the y-position.
SUMOTime getWaitingTime(const MSPerson::MSPersonStage_Walking &stage, SUMOTime now) const override
return the time the person spent standing
virtual void addEvent(Command *operation, SUMOTime execTimeStep=-1)
Adds an Event.
void remove(PedestrianState *state) override
remove the specified person from the pedestrian simulation
static bool gUsingInternalLanes
Information whether the simulation regards internal lanes.
void handleShape(const PositionVector &shape, hybridsim::Scenario &scenario)
void setPosition(double x, double y)
void move2side(double amount)
move position vector to side using certain ammount
PedestrianState * add(MSPerson *person, MSPerson::MSPersonStage_Walking *stage, SUMOTime now) override
register the given person as a pedestrian
abstract base class for managing callbacks to retrieve various state information from the model ...
double getSpeed(const MSPerson::MSPersonStage_Walking &stage) const override
return the current speed of the person
Container for pedestrian state and individual position update function.
bool usingInternalLanes()
whether movements on intersections are modelled
Position positionAtOffset(double pos, double lateralOffset=0) const
Returns the position at the given length.
double xmin() const
Returns minimum x-coordinate.
Position getPosition(const MSPerson::MSPersonStage_Walking &stage, SUMOTime now) const override
return the network coordinate of the person
A storage for options typed value containers)
double ymin() const
Returns minimum y-coordinate.
std::unique_ptr< hybridsim::HybridSimulation::Stub > myHybridsimStub
std::map< const MSEdge *, std::tuple< int, int > > edgesTransitionsMapping
static const int BACKWARD
const PositionVector & getShape() const
Returns this lane's shape.
MSPerson::MSPersonStage_Walking * myStage
bool isCrossing() const
return whether this edge is a pedestrian crossing
const MSJunction * getFromJunction() const
MSEdgeControl & getEdgeControl()
Returns the edge control.
double getAngle(const MSPerson::MSPersonStage_Walking &stage, SUMOTime now) const override
return the direction in which the person faces in degrees
void add(double x, double y, double z=0)
Makes the boundary include the given coordinate.
Representation of a lane in the micro simulation.
void cleanupHelper() override
double getEdgePos(const MSPerson::MSPersonStage_Walking &stage, SUMOTime now) const override
return the offset from the start of the current edge measured in its natural direction ...
void handleWalkingArea(MSEdge *msEdge, hybridsim::Scenario &scenario)
const MSJunction * getToJunction() const
const MSEdgeVector & getEdges() const
Returns loaded edges.