22 #include <grpc++/grpc++.h> 27 #include "hybridsim.grpc.pb.h" 32 using grpc::ClientContext;
37 const std::string address = oc.
getString(
"pedestrian.remote.address");
38 myHybridsimStub = hybridsim::HybridSimulation::NewStub(grpc::CreateChannel(
39 address, grpc::InsecureChannelCredentials()));
61 double offset = departureOffsetAlongLane == 0 ? 0.4 : -0.4;
62 departureOffsetAlongLane += offset;
65 hybridsim::Coordinate* departureCoordinate = req.mutable_enterlocation();
66 departureCoordinate->set_x(departurePos.
x());
67 departureCoordinate->set_y(departurePos.
y());
72 hybridsim::Coordinate* arrivalCoordinate = req.mutable_leavelocation();
73 arrivalCoordinate->set_x(arrivalPos.
x());
74 arrivalCoordinate->set_y(arrivalPos.
y());
78 for (ConstMSEdgeVector::const_iterator it = stage->
getRoute().begin(); it != stage->
getRoute().end(); it++) {
83 const MSEdge* nxt = *(it + 1);
98 int frId = dir ==
FORWARD ? std::get<0>(transitions) : std::get<1>(transitions);
99 int toId = dir ==
FORWARD ? std::get<1>(transitions) : std::get<0>(transitions);
100 hybridsim::Destination* destFr = req.add_dests();
101 destFr->set_id(frId);
102 hybridsim::Destination* destTo = req.add_dests();
103 destTo->set_id(toId);
107 hybridsim::Boolean rpl;
108 ClientContext context;
111 ProcessError(
"Person: " + person->
getID() +
" could not be transferred to remote simulation");
115 ProcessError(
"Remote simulation declined to accept person: " + person->
getID() +
".");
123 hybridsim::Empty req;
124 hybridsim::Empty rpl;
125 ClientContext context1;
136 hybridsim::LeftClosedRightOpenTimeInterval interval;
137 interval.set_fromtimeincluding(time /
DELTA_T);
142 hybridsim::Empty rpl;
143 ClientContext context1;
144 Status st =
myHybridsimStub->simulatedTimeInerval(&context1, interval, &rpl);
150 hybridsim::Empty req2;
151 hybridsim::Trajectories trajectories;
152 ClientContext context2;
153 Status st2 =
myHybridsimStub->receiveTrajectories(&context2, req2, &trajectories);
155 ProcessError(
"Could not receive trajectories from remote simulation");
157 for (hybridsim::Trajectory trajectory : trajectories.trajectories()) {
160 pState->
setPosition(trajectory.x(), trajectory.y());
161 pState->
setPhi(trajectory.phi());
166 if (nextTargetEdge == nextStageEdge) {
168 std::cout <<
"next edge" << std::endl;
178 hybridsim::Empty req3;
179 hybridsim::Agents agents;
180 ClientContext context3;
181 Status st3 =
myHybridsimStub->queryRetrievableAgents(&context3, req3, &agents);
186 for (hybridsim::Agent agent : agents.agents()) {
197 hybridsim::Empty rpl2;
198 ClientContext context4;
199 Status st4 =
myHybridsimStub->confirmRetrievedAgents(&context4, agents, &rpl2);
224 hybridsim::Scenario req;
228 if (e->isInternal()) {
231 if (e->isWalkingArea()) {
235 for (
MSLane* l : e->getLanes()) {
243 hybridsim::Edge* edge = req.add_edges();
248 edge->set_type(hybridsim::Edge_Type_OBSTACLE);
250 edge = req.add_edges();
255 edge->set_type(hybridsim::Edge_Type_OBSTACLE);
257 edge = req.add_edges();
262 edge->set_type(hybridsim::Edge_Type_OBSTACLE);
264 edge = req.add_edges();
269 edge->set_type(hybridsim::Edge_Type_OBSTACLE);
272 hybridsim::Empty rpl;
273 ClientContext context;
276 ProcessError(
"Remote side could not initialize scenario!");
284 if (shape.size() < 2) {
294 hybridsim::Edge* edge = scenario.add_edges();
295 edge->mutable_c0()->set_x(frst.
x());
296 edge->mutable_c0()->set_y(frst.
y());
297 edge->mutable_c1()->set_x(scnd.
x());
298 edge->mutable_c1()->set_y(scnd.
y());
299 edge->set_type(hybridsim::Edge_Type_OBSTACLE);
306 if (centerLine.size() < 2) {
317 hybridsim::Edge_Type edgeType;
319 edgeType = hybridsim::Edge_Type_TRANSITION_HOLDOVER;
321 edgeType = hybridsim::Edge_Type_TRANSITION_INTERNAL;
323 edgeType = hybridsim::Edge_Type_TRANSITION;
327 Position frst = *centerLine.begin();
328 Position scnd = *(centerLine.begin() + 1);
330 Position thrd = *(centerLine.end() - 1);
331 Position frth = *(centerLine.end() - 2);
342 hybridsim::Edge_Type type,
int id) {
344 double dx = scnd.
x() - frst.
x();
345 double dy = scnd.
y() - frst.
y();
346 double length = sqrt(dx * dx + dy * dy);
349 double x0 = frst.
x() - dy * width / 2.;
350 double y0 = frst.
y() + dx * width / 2.;
351 double x1 = frst.
x() + dy * width / 2.;
352 double y1 = frst.
y() - dx * width / 2.;
353 hybridsim::Edge* edge = scenario.add_edges();
354 edge->mutable_c0()->set_x(x0);
355 edge->mutable_c0()->set_y(y0);
356 edge->mutable_c1()->set_x(x1);
357 edge->mutable_c1()->set_y(y1);
358 edge->set_type(type);
363 PositionVector::const_iterator it = shape.begin();
368 for (; it != shape.end(); it++) {
369 hybridsim::Edge* edge = scenario.add_edges();
370 edge->mutable_c0()->set_x(frst.
x());
371 edge->mutable_c0()->set_y(frst.
y());
372 edge->mutable_c1()->set_x((*it).x());
373 edge->mutable_c1()->set_y((*it).y());
374 edge->set_type(hybridsim::Edge_Type_OBSTACLE);
386 : 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 getSpeed(const MSPerson::MSPersonStage_Walking &stage) const override
return the current speed of the person
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.
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)
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 ...
MSPerson::MSPersonStage_Walking * getStage()
const std::string & getID() const
returns the id of the transportable
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.
double getAngle(const MSPerson::MSPersonStage_Walking &stage, SUMOTime now) const override
return the direction in which the person faces in degrees
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.
virtual void addEvent(Command *operation, SUMOTime execTimeStep=-1)
Adds an Event.
void remove(PedestrianState *state) override
remove the specified person from the pedestrian simulation
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 ...
const MSEdge * getNextEdge(const MSPerson::MSPersonStage_Walking &stage) const override
return the list of internal edges if the pedestrian is on an intersection
Container for pedestrian state and individual position update function.
SUMOTime getWaitingTime(const MSPerson::MSPersonStage_Walking &stage, SUMOTime now) const override
return the time the person spent standing
Position positionAtOffset(double pos, double lateralOffset=0) const
Returns the position at the given length.
double xmin() const
Returns minimum x-coordinate.
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.
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
void handleWalkingArea(MSEdge *msEdge, hybridsim::Scenario &scenario)
const MSJunction * getToJunction() const
const MSEdgeVector & getEdges() const
Returns loaded edges.
Position getPosition(const MSPerson::MSPersonStage_Walking &stage, SUMOTime now) const override
return the network coordinate of the person