19 #include <grpc++/grpc++.h>
25 #include "hybridsim.grpc.pb.h"
30 using grpc::ClientContext;
35 const std::string address = oc.
getString(
"pedestrian.remote.address");
36 myHybridsimStub = hybridsim::HybridSimulation::NewStub(grpc::CreateChannel(
37 address, grpc::InsecureChannelCredentials()));
59 double offset = departureOffsetAlongLane == 0 ? 0.4 : -0.4;
60 departureOffsetAlongLane += offset;
63 hybridsim::Coordinate* departureCoordinate = req.mutable_enterlocation();
64 departureCoordinate->set_x(departurePos.
x());
65 departureCoordinate->set_y(departurePos.
y());
70 hybridsim::Coordinate* arrivalCoordinate = req.mutable_leavelocation();
71 arrivalCoordinate->set_x(arrivalPos.
x());
72 arrivalCoordinate->set_y(arrivalPos.
y());
76 for (ConstMSEdgeVector::const_iterator it = stage->
getRoute().begin(); it != stage->
getRoute().end(); it++) {
81 const MSEdge* nxt = *(it + 1);
92 throw ProcessError(
"Cannot map edge : " + edge->
getID() +
" to remote simulation");
96 int frId = dir ==
FORWARD ? std::get<0>(transitions) : std::get<1>(transitions);
97 int toId = dir ==
FORWARD ? std::get<1>(transitions) : std::get<0>(transitions);
98 hybridsim::Destination* destFr = req.add_dests();
100 hybridsim::Destination* destTo = req.add_dests();
101 destTo->set_id(toId);
105 hybridsim::Boolean rpl;
106 ClientContext context;
109 throw ProcessError(
"Person: " + person->
getID() +
" could not be transferred to remote simulation");
113 throw ProcessError(
"Remote simulation declined to accept person: " + person->
getID() +
".");
121 hybridsim::Empty req;
122 hybridsim::Empty rpl;
123 ClientContext context1;
134 hybridsim::LeftClosedRightOpenTimeInterval interval;
135 interval.set_fromtimeincluding(time /
DELTA_T);
140 hybridsim::Empty rpl;
141 ClientContext context1;
142 Status st =
myHybridsimStub->simulatedTimeInerval(&context1, interval, &rpl);
148 hybridsim::Empty req2;
149 hybridsim::Trajectories trajectories;
150 ClientContext context2;
151 Status st2 =
myHybridsimStub->receiveTrajectories(&context2, req2, &trajectories);
153 throw ProcessError(
"Could not receive trajectories from remote simulation");
155 for (hybridsim::Trajectory trajectory : trajectories.trajectories()) {
158 pState->
setPosition(trajectory.x(), trajectory.y());
159 pState->
setPhi(trajectory.phi());
164 if (nextTargetEdge == nextStageEdge) {
166 std::cout <<
"next edge" << std::endl;
176 hybridsim::Empty req3;
177 hybridsim::Agents agents;
178 ClientContext context3;
179 Status st3 =
myHybridsimStub->queryRetrievableAgents(&context3, req3, &agents);
181 throw ProcessError(
"Could not query retrievable agents");
184 for (hybridsim::Agent agent : agents.agents()) {
194 hybridsim::Empty rpl2;
195 ClientContext context4;
196 Status st4 =
myHybridsimStub->confirmRetrievedAgents(&context4, agents, &rpl2);
198 throw ProcessError(
"Could not confirm retrieved agents");
221 hybridsim::Scenario req;
225 if (e->isInternal()) {
228 if (e->isWalkingArea()) {
232 for (
MSLane* l : e->getLanes()) {
240 hybridsim::Edge* edge = req.add_edges();
245 edge->set_type(hybridsim::Edge_Type_OBSTACLE);
247 edge = req.add_edges();
252 edge->set_type(hybridsim::Edge_Type_OBSTACLE);
254 edge = req.add_edges();
259 edge->set_type(hybridsim::Edge_Type_OBSTACLE);
261 edge = req.add_edges();
266 edge->set_type(hybridsim::Edge_Type_OBSTACLE);
269 hybridsim::Empty rpl;
270 ClientContext context;
273 throw ProcessError(
"Remote side could not initialize scenario!");
281 if (shape.size() < 2) {
291 hybridsim::Edge* edge = scenario.add_edges();
292 edge->mutable_c0()->set_x(frst.
x());
293 edge->mutable_c0()->set_y(frst.
y());
294 edge->mutable_c1()->set_x(scnd.
x());
295 edge->mutable_c1()->set_y(scnd.
y());
296 edge->set_type(hybridsim::Edge_Type_OBSTACLE);
303 if (centerLine.size() < 2) {
314 hybridsim::Edge_Type edgeType;
316 edgeType = hybridsim::Edge_Type_TRANSITION_HOLDOVER;
318 edgeType = hybridsim::Edge_Type_TRANSITION_INTERNAL;
320 edgeType = hybridsim::Edge_Type_TRANSITION;
324 Position frst = *centerLine.begin();
325 Position scnd = *(centerLine.begin() + 1);
327 Position thrd = *(centerLine.end() - 1);
328 Position frth = *(centerLine.end() - 2);
339 hybridsim::Edge_Type type,
int id) {
341 double dx = scnd.
x() - frst.
x();
342 double dy = scnd.
y() - frst.
y();
343 double length = sqrt(dx * dx + dy * dy);
346 double x0 = frst.
x() - dy * width / 2.;
347 double y0 = frst.
y() + dx * width / 2.;
348 double x1 = frst.
x() + dy * width / 2.;
349 double y1 = frst.
y() - dx * width / 2.;
350 hybridsim::Edge* edge = scenario.add_edges();
351 edge->mutable_c0()->set_x(x0);
352 edge->mutable_c0()->set_y(y0);
353 edge->mutable_c1()->set_x(x1);
354 edge->mutable_c1()->set_y(y1);
355 edge->set_type(type);
360 PositionVector::const_iterator it = shape.begin();
365 for (; it != shape.end(); it++) {
366 hybridsim::Edge* edge = scenario.add_edges();
367 edge->mutable_c0()->set_x(frst.
x());
368 edge->mutable_c0()->set_y(frst.
y());
369 edge->mutable_c1()->set_x((*it).x());
370 edge->mutable_c1()->set_y((*it).y());
371 edge->set_type(hybridsim::Edge_Type_OBSTACLE);
383 : myPerson(person), myPhi(0), myPosition(0, 0), myStage(stage) {
409 myPosition.set(x, y);