Eclipse SUMO - Simulation of Urban MObility
TraCIServerAPI_Simulation.cpp
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2001-2022 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials are made available under the
5 // terms of the Eclipse Public License 2.0 which is available at
6 // https://www.eclipse.org/legal/epl-2.0/
7 // This Source Code may also be made available under the following Secondary
8 // Licenses when the conditions for such availability set forth in the Eclipse
9 // Public License 2.0 are satisfied: GNU General Public License, version 2
10 // or later which is available at
11 // https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
12 // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
13 /****************************************************************************/
21 // APIs for getting/setting simulation values via TraCI
22 /****************************************************************************/
23 #include <config.h>
24 
25 #include <utils/common/StdDefs.h>
27 #include <microsim/MSNet.h>
28 #include <microsim/MSEdgeControl.h>
30 #include <microsim/MSEdge.h>
31 #include <microsim/MSLane.h>
32 #include <microsim/MSVehicle.h>
36 #include <libsumo/Helper.h>
37 #include <libsumo/Simulation.h>
38 #include <libsumo/TraCIConstants.h>
39 #include <libsumo/StorageHelper.h>
41 
42 
43 // ===========================================================================
44 // method definitions
45 // ===========================================================================
46 bool
48  tcpip::Storage& outputStorage) {
49  const int variable = inputStorage.readUnsignedByte();
50  const std::string id = inputStorage.readString();
51  server.initWrapper(libsumo::RESPONSE_GET_SIM_VARIABLE, variable, id);
52  try {
53  // unlike the other domains we cannot check here first whether libsumo::Simulation can handle it because the implementations for the state variables differ
54  switch (variable) {
57  break;
60  break;
63  break;
66  break;
69  break;
72  break;
75  break;
78  break;
81  break;
84  break;
87  break;
90  break;
93  break;
96  break;
99  break;
102  break;
105  break;
108  break;
111  break;
114  break;
117  break;
120  break;
123  break;
126  break;
129  break;
132  break;
135  break;
138  break;
140  std::vector<libsumo::TraCICollision> collisions = libsumo::Simulation::getCollisions();
142  const int cnt = 1 + (int)collisions.size() * 4;
143  server.getWrapperStorage().writeInt(cnt);
145  server.getWrapperStorage().writeInt((int)collisions.size());
146  for (const auto& c : collisions) {
148  server.getWrapperStorage().writeString(c.collider);
150  server.getWrapperStorage().writeString(c.victim);
152  server.getWrapperStorage().writeString(c.colliderType);
154  server.getWrapperStorage().writeString(c.victimType);
156  server.getWrapperStorage().writeDouble(c.colliderSpeed);
158  server.getWrapperStorage().writeDouble(c.victimSpeed);
160  server.getWrapperStorage().writeString(c.type);
162  server.getWrapperStorage().writeString(c.lane);
164  server.getWrapperStorage().writeDouble(c.pos);
165  }
166  break;
167  }
170  libsumo::TraCIPositionVector tb = libsumo::Simulation::getNetBoundary();
171  server.getWrapperStorage().writeByte(2);
172  server.getWrapperStorage().writeDouble(tb.value[0].x);
173  server.getWrapperStorage().writeDouble(tb.value[0].y);
174  server.getWrapperStorage().writeDouble(tb.value[1].x);
175  server.getWrapperStorage().writeDouble(tb.value[1].y);
176  break;
177  }
179  if (inputStorage.readUnsignedByte() != libsumo::TYPE_COMPOUND) {
180  return server.writeErrorStatusCmd(libsumo::CMD_GET_SIM_VARIABLE, "Position conversion requires a compound object.", outputStorage);
181  }
182  const int compoundSize = inputStorage.readInt();
183  if (compoundSize < 2 || compoundSize > 3) {
184  return server.writeErrorStatusCmd(libsumo::CMD_GET_SIM_VARIABLE, "Position conversion requires a source position and a position type as parameter.", outputStorage);
185  }
186  if (!commandPositionConversion(server, inputStorage, compoundSize, server.getWrapperStorage(), libsumo::CMD_GET_SIM_VARIABLE)) {
187  return false;
188  }
189  break;
190  }
192  if (inputStorage.readUnsignedByte() != libsumo::TYPE_COMPOUND) {
193  return server.writeErrorStatusCmd(libsumo::CMD_GET_SIM_VARIABLE, "Retrieval of distance requires a compound object.", outputStorage);
194  }
195  if (inputStorage.readInt() != 3) {
196  return server.writeErrorStatusCmd(libsumo::CMD_GET_SIM_VARIABLE, "Retrieval of distance requires two positions and a distance type as parameter.", outputStorage);
197  }
198  if (!commandDistanceRequest(server, inputStorage, server.getWrapperStorage(), libsumo::CMD_GET_SIM_VARIABLE)) {
199  return false;
200  }
201  break;
202  case libsumo::FIND_ROUTE: {
203  if (inputStorage.readUnsignedByte() != libsumo::TYPE_COMPOUND) {
204  return server.writeErrorStatusCmd(libsumo::CMD_GET_SIM_VARIABLE, "Retrieval of a route requires a compound object.", outputStorage);
205  }
206  if (inputStorage.readInt() != 5) {
207  return server.writeErrorStatusCmd(libsumo::CMD_GET_SIM_VARIABLE, "Retrieval of a route requires five parameter.", outputStorage);
208  }
209  std::string from, to, vtype;
210  double depart;
211  int routingMode;
212  if (!server.readTypeCheckingString(inputStorage, from)) {
213  return server.writeErrorStatusCmd(libsumo::CMD_GET_SIM_VARIABLE, "Retrieval of a route requires a string as first parameter.", outputStorage);
214  }
215  if (!server.readTypeCheckingString(inputStorage, to)) {
216  return server.writeErrorStatusCmd(libsumo::CMD_GET_SIM_VARIABLE, "Retrieval of a route requires a string as second parameter.", outputStorage);
217  }
218  if (!server.readTypeCheckingString(inputStorage, vtype)) {
219  return server.writeErrorStatusCmd(libsumo::CMD_GET_SIM_VARIABLE, "Retrieval of a route requires a string as third parameter.", outputStorage);
220  }
221  if (!server.readTypeCheckingDouble(inputStorage, depart)) {
222  return server.writeErrorStatusCmd(libsumo::CMD_GET_SIM_VARIABLE, "Retrieval of a route requires a double as fourth parameter.", outputStorage);
223  }
224  if (!server.readTypeCheckingInt(inputStorage, routingMode)) {
225  return server.writeErrorStatusCmd(libsumo::CMD_GET_SIM_VARIABLE, "Retrieval of a route requires an integer as fifth parameter.", outputStorage);
226  }
227  writeStage(server.getWrapperStorage(), libsumo::Simulation::findRoute(from, to, vtype, depart, routingMode));
228  break;
229  }
231  if (inputStorage.readUnsignedByte() != libsumo::TYPE_COMPOUND) {
232  return server.writeErrorStatusCmd(libsumo::CMD_GET_SIM_VARIABLE, "Retrieval of an intermodal route requires a compound object.", outputStorage);
233  }
234  if (inputStorage.readInt() != 13) {
235  return server.writeErrorStatusCmd(libsumo::CMD_GET_SIM_VARIABLE, "Retrieval of an intermodal route requires thirteen parameters.", outputStorage);
236  }
237  std::string from, to, modes, ptype, vtype, destStop;
238  double depart, speed, walkFactor, departPos, arrivalPos, departPosLat;
239  int routingMode;
240  if (!server.readTypeCheckingString(inputStorage, from)) {
241  return server.writeErrorStatusCmd(libsumo::CMD_GET_SIM_VARIABLE, "Retrieval of a route requires a string as first parameter.", outputStorage);
242  }
243  if (!server.readTypeCheckingString(inputStorage, to)) {
244  return server.writeErrorStatusCmd(libsumo::CMD_GET_SIM_VARIABLE, "Retrieval of a route requires a string as second parameter.", outputStorage);
245  }
246  if (!server.readTypeCheckingString(inputStorage, modes)) {
247  return server.writeErrorStatusCmd(libsumo::CMD_GET_SIM_VARIABLE, "Retrieval of a route requires a string as third parameter.", outputStorage);
248  }
249  if (!server.readTypeCheckingDouble(inputStorage, depart)) {
250  return server.writeErrorStatusCmd(libsumo::CMD_GET_SIM_VARIABLE, "Retrieval of a route requires a double as fourth parameter.", outputStorage);
251  }
252  if (!server.readTypeCheckingInt(inputStorage, routingMode)) {
253  return server.writeErrorStatusCmd(libsumo::CMD_GET_SIM_VARIABLE, "Retrieval of a route requires an integer as fifth parameter.", outputStorage);
254  }
255  if (!server.readTypeCheckingDouble(inputStorage, speed)) {
256  return server.writeErrorStatusCmd(libsumo::CMD_GET_SIM_VARIABLE, "Retrieval of a route requires a double as sixth parameter.", outputStorage);
257  }
258  if (!server.readTypeCheckingDouble(inputStorage, walkFactor)) {
259  return server.writeErrorStatusCmd(libsumo::CMD_GET_SIM_VARIABLE, "Retrieval of a route requires a double as seventh parameter.", outputStorage);
260  }
261  if (!server.readTypeCheckingDouble(inputStorage, departPos)) {
262  return server.writeErrorStatusCmd(libsumo::CMD_GET_SIM_VARIABLE, "Retrieval of a route requires a double as eigth parameter.", outputStorage);
263  }
264  if (!server.readTypeCheckingDouble(inputStorage, arrivalPos)) {
265  return server.writeErrorStatusCmd(libsumo::CMD_GET_SIM_VARIABLE, "Retrieval of a route requires a double as nineth parameter.", outputStorage);
266  }
267  if (!server.readTypeCheckingDouble(inputStorage, departPosLat)) {
268  return server.writeErrorStatusCmd(libsumo::CMD_GET_SIM_VARIABLE, "Retrieval of a route requires a double as tenth parameter.", outputStorage);
269  }
270  if (!server.readTypeCheckingString(inputStorage, ptype)) {
271  return server.writeErrorStatusCmd(libsumo::CMD_GET_SIM_VARIABLE, "Retrieval of a route requires a string as eleventh parameter.", outputStorage);
272  }
273  if (!server.readTypeCheckingString(inputStorage, vtype)) {
274  return server.writeErrorStatusCmd(libsumo::CMD_GET_SIM_VARIABLE, "Retrieval of a route requires a string as twelvth parameter.", outputStorage);
275  }
276  if (!server.readTypeCheckingString(inputStorage, destStop)) {
277  return server.writeErrorStatusCmd(libsumo::CMD_GET_SIM_VARIABLE, "Retrieval of a route requires a string as thirteenth parameter.", outputStorage);
278  }
279  const std::vector<libsumo::TraCIStage>& result = libsumo::Simulation::findIntermodalRoute(from, to, modes, depart, routingMode, speed, walkFactor, departPos, arrivalPos, departPosLat, ptype, vtype, destStop);
281  server.getWrapperStorage().writeInt((int)result.size());
282  for (const libsumo::TraCIStage& s : result) {
283  writeStage(server.getWrapperStorage(), s);
284  }
285  break;
286  }
287  default:
288  if (!libsumo::Simulation::handleVariable(id, variable, &server, &inputStorage)) {
289  return server.writeErrorStatusCmd(libsumo::CMD_GET_SIM_VARIABLE, "Get Simulation Variable: unsupported variable " + toHex(variable, 2) + " specified", outputStorage);
290  }
291  }
292  } catch (libsumo::TraCIException& e) {
293  return server.writeErrorStatusCmd(libsumo::CMD_GET_SIM_VARIABLE, e.what(), outputStorage);
294  }
296  server.writeResponseWithLength(outputStorage, server.getWrapperStorage());
297  return true;
298 }
299 
300 
301 bool
303  tcpip::Storage& outputStorage) {
304  std::string warning = ""; // additional description for response
305  // variable
306  int variable = inputStorage.readUnsignedByte();
308  && variable != libsumo::CMD_SAVE_SIMSTATE
309  && variable != libsumo::CMD_LOAD_SIMSTATE
310  && variable != libsumo::VAR_PARAMETER
311  && variable != libsumo::CMD_MESSAGE
312  ) {
313  return server.writeErrorStatusCmd(libsumo::CMD_SET_SIM_VARIABLE, "Set Simulation Variable: unsupported variable " + toHex(variable, 2) + " specified", outputStorage);
314  }
315  // id
316  std::string id = inputStorage.readString();
317  // process
318  try {
319  switch (variable) {
321  //clear any pending vehicle insertions
322  std::string route;
323  if (!server.readTypeCheckingString(inputStorage, route)) {
324  return server.writeErrorStatusCmd(libsumo::CMD_SET_SIM_VARIABLE, "A string is needed for clearing pending vehicles.", outputStorage);
325  }
326  libsumo::Simulation::clearPending(route);
327  }
328  break;
330  //save current simulation state
331  std::string file;
332  if (!server.readTypeCheckingString(inputStorage, file)) {
333  return server.writeErrorStatusCmd(libsumo::CMD_SET_SIM_VARIABLE, "A string is needed for saving simulation state.", outputStorage);
334  }
335  libsumo::Simulation::saveState(file);
336  }
337  break;
339  //quick-load simulation state
340  std::string file;
341  if (!server.readTypeCheckingString(inputStorage, file)) {
342  return server.writeErrorStatusCmd(libsumo::CMD_SET_SIM_VARIABLE, "A string is needed for loading simulation state.", outputStorage);
343  }
344  double time = libsumo::Simulation::loadState(file);
346  }
347  break;
348  case libsumo::VAR_PARAMETER: {
349  StoHelp::readCompound(inputStorage, 2, "A compound object of size 2 is needed for setting a parameter.");
350  const std::string name = StoHelp::readTypedString(inputStorage, "The name of the parameter must be given as a string.");
351  const std::string value = StoHelp::readTypedString(inputStorage, "The value of the parameter must be given as a string.");
352  libsumo::Simulation::setParameter(id, name, value);
353  break;
354  }
355  case libsumo::CMD_MESSAGE: {
356  std::string msg;
357  if (!server.readTypeCheckingString(inputStorage, msg)) {
358  return server.writeErrorStatusCmd(libsumo::CMD_SET_SIM_VARIABLE, "A string is needed for adding a log message.", outputStorage);
359  }
360  libsumo::Simulation::writeMessage(msg);
361  }
362  break;
363  default:
364  break;
365  }
366  } catch (libsumo::TraCIException& e) {
367  return server.writeErrorStatusCmd(libsumo::CMD_SET_SIM_VARIABLE, e.what(), outputStorage);
368  }
369  server.writeStatusCmd(libsumo::CMD_SET_SIM_VARIABLE, libsumo::RTYPE_OK, warning, outputStorage);
370  return true;
371 }
372 
373 
374 void
376  const std::vector<std::string>& ids = server.getVehicleStateChanges().find(state)->second;
378  outputStorage.writeInt((int) ids.size());
379 }
380 
381 
382 void
384  const std::vector<std::string>& ids = server.getVehicleStateChanges().find(state)->second;
386  outputStorage.writeStringList(ids);
387 }
388 
389 
390 void
392  const std::vector<std::string>& ids = server.getTransportableStateChanges().find(state)->second;
394  outputStorage.writeInt((int)ids.size());
395 }
396 
397 
398 void
400  const std::vector<std::string>& ids = server.getTransportableStateChanges().find(state)->second;
402  outputStorage.writeStringList(ids);
403 }
404 
405 
406 void
409  outputStorage.writeInt(13);
411  outputStorage.writeInt(stage.type);
413  outputStorage.writeString(stage.vType);
415  outputStorage.writeString(stage.line);
417  outputStorage.writeString(stage.destStop);
419  outputStorage.writeStringList(stage.edges);
421  outputStorage.writeDouble(stage.travelTime);
423  outputStorage.writeDouble(stage.cost);
425  outputStorage.writeDouble(stage.length);
427  outputStorage.writeString(stage.intended);
429  outputStorage.writeDouble(stage.depart);
431  outputStorage.writeDouble(stage.departPos);
433  outputStorage.writeDouble(stage.arrivalPos);
435  outputStorage.writeString(stage.description);
436 }
437 
440  auto* stage = new libsumo::TraCIStage();
441  server.readTypeCheckingInt(inputStorage, stage->type);
442  server.readTypeCheckingString(inputStorage, stage->vType);
443  server.readTypeCheckingString(inputStorage, stage->line);
444  server.readTypeCheckingString(inputStorage, stage->destStop);
445  server.readTypeCheckingStringList(inputStorage, stage->edges);
446  server.readTypeCheckingDouble(inputStorage, stage->travelTime);
447  server.readTypeCheckingDouble(inputStorage, stage->cost);
448  server.readTypeCheckingDouble(inputStorage, stage->length);
449  server.readTypeCheckingString(inputStorage, stage->intended);
450  server.readTypeCheckingDouble(inputStorage, stage->depart);
451  server.readTypeCheckingDouble(inputStorage, stage->departPos);
452  server.readTypeCheckingDouble(inputStorage, stage->arrivalPos);
453  server.readTypeCheckingString(inputStorage, stage->description);
454  return stage;
455 }
456 
457 bool
459  const int compoundSize, tcpip::Storage& outputStorage,
460  const int commandId) {
461  std::pair<MSLane*, double> roadPos;
462  Position cartesianPos;
463  Position geoPos;
464  double z = 0;
465 
466  // actual position type that will be converted
467  int srcPosType = inputStorage.readUnsignedByte();
468 
469  switch (srcPosType) {
474  const double x = inputStorage.readDouble();
475  const double y = inputStorage.readDouble();
476  if (srcPosType != libsumo::POSITION_2D && srcPosType != libsumo::POSITION_LON_LAT) {
477  z = inputStorage.readDouble();
478  }
479  geoPos.set(x, y);
480  cartesianPos.set(x, y);
481  if (srcPosType == libsumo::POSITION_LON_LAT || srcPosType == libsumo::POSITION_LON_LAT_ALT) {
483  } else {
485  }
486  }
487  break;
489  const std::string roadID = inputStorage.readString();
490  const double pos = inputStorage.readDouble();
491  const int laneIdx = inputStorage.readUnsignedByte();
492  try {
493  // convert edge,offset,laneIdx to cartesian position
494  cartesianPos = geoPos = libsumo::Helper::getLaneChecking(roadID, laneIdx, pos)->geometryPositionAtOffset(pos);
495  z = cartesianPos.z();
497  } catch (libsumo::TraCIException& e) {
498  server.writeStatusCmd(commandId, libsumo::RTYPE_ERR, e.what());
499  return false;
500  }
501  }
502  break;
503  default:
504  server.writeStatusCmd(commandId, libsumo::RTYPE_ERR, "Source position type not supported");
505  return false;
506  }
507 
508  int destPosType = 0;
509  if (!server.readTypeCheckingUnsignedByte(inputStorage, destPosType)) {
510  server.writeStatusCmd(commandId, libsumo::RTYPE_ERR, "Destination position type must be of type ubyte.");
511  return false;
512  }
513 
515  if (compoundSize == 3) {
516  inputStorage.readUnsignedByte();
517  const std::string& vClassString = inputStorage.readString();
518  if (!SumoVehicleClassStrings.hasString(vClassString)) {
519  server.writeStatusCmd(commandId, libsumo::RTYPE_ERR, "Unknown vehicle class '" + vClassString + "'.");
520  return false;
521  }
522  vClass = SumoVehicleClassStrings.get(vClassString);
523  }
524 
525  switch (destPosType) {
527  // convert cartesion position to edge,offset,lane_index
528  roadPos = libsumo::Helper::convertCartesianToRoadMap(cartesianPos, vClass);
529  if (roadPos.first == nullptr) {
530  server.writeStatusCmd(commandId, libsumo::RTYPE_ERR, "No matching lane found.");
531  return false;
532  }
533  // write result that is added to response msg
535  outputStorage.writeString(roadPos.first->getEdge().getID());
536  outputStorage.writeDouble(roadPos.second);
537  outputStorage.writeUnsignedByte(roadPos.first->getIndex());
538  }
539  break;
544  outputStorage.writeUnsignedByte(destPosType);
545  if (destPosType == libsumo::POSITION_LON_LAT || destPosType == libsumo::POSITION_LON_LAT_ALT) {
546  outputStorage.writeDouble(geoPos.x());
547  outputStorage.writeDouble(geoPos.y());
548  } else {
549  outputStorage.writeDouble(cartesianPos.x());
550  outputStorage.writeDouble(cartesianPos.y());
551  }
552  if (destPosType != libsumo::POSITION_2D && destPosType != libsumo::POSITION_LON_LAT) {
553  outputStorage.writeDouble(z);
554  }
555  break;
556  default:
557  server.writeStatusCmd(commandId, libsumo::RTYPE_ERR, "Destination position type not supported");
558  return false;
559  }
560  return true;
561 }
562 
563 
564 bool
566  tcpip::Storage& outputStorage, int commandId) {
567  Position pos1;
568  Position pos2;
569  std::pair<const MSLane*, double> roadPos1;
570  std::pair<const MSLane*, double> roadPos2;
571 
572  // read position 1
573  int posType = inputStorage.readUnsignedByte();
574  switch (posType) {
576  try {
577  std::string roadID = inputStorage.readString();
578  roadPos1.second = inputStorage.readDouble();
579  roadPos1.first = libsumo::Helper::getLaneChecking(roadID, inputStorage.readUnsignedByte(), roadPos1.second);
580  pos1 = roadPos1.first->geometryPositionAtOffset(roadPos1.second);
581  } catch (libsumo::TraCIException& e) {
582  server.writeStatusCmd(commandId, libsumo::RTYPE_ERR, e.what());
583  return false;
584  }
585  break;
587  case libsumo::POSITION_3D: {
588  double p1x = inputStorage.readDouble();
589  double p1y = inputStorage.readDouble();
590  pos1.set(p1x, p1y);
591  }
592  if (posType == libsumo::POSITION_3D) {
593  inputStorage.readDouble();// z value is ignored
594  }
596  break;
597  default:
598  server.writeStatusCmd(commandId, libsumo::RTYPE_ERR, "Unknown position format used for distance request");
599  return false;
600  }
601 
602  // read position 2
603  posType = inputStorage.readUnsignedByte();
604  switch (posType) {
606  try {
607  std::string roadID = inputStorage.readString();
608  roadPos2.second = inputStorage.readDouble();
609  roadPos2.first = libsumo::Helper::getLaneChecking(roadID, inputStorage.readUnsignedByte(), roadPos2.second);
610  pos2 = roadPos2.first->geometryPositionAtOffset(roadPos2.second);
611  } catch (libsumo::TraCIException& e) {
612  server.writeStatusCmd(commandId, libsumo::RTYPE_ERR, e.what());
613  return false;
614  }
615  break;
617  case libsumo::POSITION_3D: {
618  double p2x = inputStorage.readDouble();
619  double p2y = inputStorage.readDouble();
620  pos2.set(p2x, p2y);
621  }
622  if (posType == libsumo::POSITION_3D) {
623  inputStorage.readDouble();// z value is ignored
624  }
626  break;
627  default:
628  server.writeStatusCmd(commandId, libsumo::RTYPE_ERR, "Unknown position format used for distance request");
629  return false;
630  }
631 
632  // read distance type
633  const int distType = inputStorage.readUnsignedByte();
634 
635  double distance = 0.0;
636  if (distType == libsumo::REQUEST_DRIVINGDIST) {
637  distance = libsumo::Helper::getDrivingDistance(roadPos1, roadPos2);
638  } else {
639  // compute air distance (default)
640  distance = pos1.distanceTo(pos2);
641  }
642  // write response command
644  outputStorage.writeDouble(distance);
645  return true;
646 }
647 
648 
649 /****************************************************************************/
#define TIME2STEPS(x)
Definition: SUMOTime.h:55
StringBijection< SUMOVehicleClass > SumoVehicleClassStrings(sumoVehicleClassStringInitializer, SVC_CUSTOM2, false)
SUMOVehicleClass
Definition of vehicle classes to differ between different lane usage and authority types.
@ SVC_IGNORING
vehicles ignoring classes
std::string toHex(const T i, std::streamsize numDigits=0)
Definition: ToString.h:56
void cartesian2geo(Position &cartesian) const
Converts the given cartesian (shifted) position to its geo (lat/long) representation.
static const GeoConvHelper & getFinal()
the coordinate transformation for writing the location element and for tracking the original coordina...
bool x2cartesian_const(Position &from) const
Converts the given coordinate into a cartesian using the previous initialisation.
const Position geometryPositionAtOffset(double offset, double lateralOffset=0) const
Definition: MSLane.h:505
VehicleState
Definition of a vehicle state.
Definition: MSNet.h:594
@ ENDING_PARKING
The vehicle ends to park.
@ STARTING_STOP
The vehicles starts to stop.
@ BUILT
The vehicle was built, but has not yet departed.
@ STARTING_PARKING
The vehicles starts to park.
@ STARTING_TELEPORT
The vehicle started to teleport.
@ ENDING_STOP
The vehicle ends to stop.
@ ENDING_TELEPORT
The vehicle ended being teleported.
@ ARRIVED
The vehicle arrived at his destination (is deleted)
@ DEPARTED
The vehicle has departed (was inserted into the network)
@ COLLISION
The vehicle is involved in a collision.
@ EMERGENCYSTOP
The vehicle had to brake harder than permitted.
@ MANEUVERING
Vehicle maneuvering either entering or exiting a parking space.
TransportableState
Definition of a transportable state.
Definition: MSNet.h:671
@ PERSON_DEPARTED
The transportable person has departed (was inserted into the network)
@ PERSON_ARRIVED
The transportable person arrived at his destination (is deleted)
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:37
void set(double x, double y)
set positions x and y
Definition: Position.h:85
double distanceTo(const Position &p2) const
returns the euclidean distance in 3 dimension
Definition: Position.h:242
double x() const
Returns the x-position.
Definition: Position.h:55
double z() const
Returns the z-position.
Definition: Position.h:65
double y() const
Returns the y-position.
Definition: Position.h:60
static libsumo::TraCIStage * readStage(TraCIServer &server, tcpip::Storage &inputStorage)
static bool commandPositionConversion(TraCIServer &server, tcpip::Storage &inputStorage, const int compoundSize, tcpip::Storage &outputStorage, const int commandId)
static bool commandDistanceRequest(TraCIServer &server, tcpip::Storage &inputStorage, tcpip::Storage &outputStorage, int commandId)
static void writeTransportableStateIDs(TraCIServer &server, tcpip::Storage &outputStorage, MSNet::TransportableState state)
static void writeTransportableStateNumber(TraCIServer &server, tcpip::Storage &outputStorage, MSNet::TransportableState state)
static bool processSet(TraCIServer &server, tcpip::Storage &inputStorage, tcpip::Storage &outputStorage)
Processes a set value command (Command 0xcb: Set Simulation Variable)
static void writeVehicleStateIDs(TraCIServer &server, tcpip::Storage &outputStorage, MSNet::VehicleState state)
static void writeVehicleStateNumber(TraCIServer &server, tcpip::Storage &outputStorage, MSNet::VehicleState state)
static void writeStage(tcpip::Storage &outputStorage, const libsumo::TraCIStage &stage)
static bool processGet(TraCIServer &server, tcpip::Storage &inputStorage, tcpip::Storage &outputStorage)
Processes a get value command (Command 0xab: Get Simulation Variable)
TraCI server used to control sumo by a remote TraCI client.
Definition: TraCIServer.h:59
void writeStatusCmd(int commandId, int status, const std::string &description, tcpip::Storage &outputStorage)
Writes a status command to the given storage.
bool readTypeCheckingString(tcpip::Storage &inputStorage, std::string &into)
Reads the value type and a string, verifying the type.
void stateLoaded(SUMOTime targetTime)
updates myTargetTime and resets vehicle state changes after loading a simulation state
tcpip::Storage & getWrapperStorage()
bool readTypeCheckingUnsignedByte(tcpip::Storage &inputStorage, int &into)
Reads the value type and an unsigned byte, verifying the type.
void initWrapper(const int domainID, const int variable, const std::string &objID)
bool writeErrorStatusCmd(int commandId, const std::string &description, tcpip::Storage &outputStorage)
Writes a status command to the given storage with status = RTYPE_ERR.
const std::map< MSNet::TransportableState, std::vector< std::string > > & getTransportableStateChanges() const
Definition: TraCIServer.h:145
bool readTypeCheckingInt(tcpip::Storage &inputStorage, int &into)
Reads the value type and an int, verifying the type.
static TraCIServer * getInstance()
Definition: TraCIServer.h:68
bool readTypeCheckingStringList(tcpip::Storage &inputStorage, std::vector< std::string > &into)
Reads the value type and a string list, verifying the type.
bool readTypeCheckingDouble(tcpip::Storage &inputStorage, double &into)
Reads the value type and a double, verifying the type.
void writeResponseWithLength(tcpip::Storage &outputStorage, tcpip::Storage &tempMsg)
const std::map< MSNet::VehicleState, std::vector< std::string > > & getVehicleStateChanges() const
Definition: TraCIServer.h:135
static double getDrivingDistance(std::pair< const MSLane *, double > &roadPos1, std::pair< const MSLane *, double > &roadPos2)
Definition: Helper.cpp:453
static std::pair< MSLane *, double > convertCartesianToRoadMap(const Position &pos, const SUMOVehicleClass vClass)
Definition: Helper.cpp:421
static const MSLane * getLaneChecking(const std::string &edgeID, int laneIndex, double pos)
Definition: Helper.cpp:404
static int readCompound(tcpip::Storage &ret, int expectedSize=-1, const std::string &error="")
Definition: StorageHelper.h:85
static std::string readTypedString(tcpip::Storage &ret, const std::string &error="")
Definition: StorageHelper.h:71
An error which allows to continue.
Definition: TraCIDefs.h:130
std::string intended
id of the intended vehicle for public transport ride
Definition: TraCIDefs.h:523
int type
The type of stage (walking, driving, ...)
Definition: TraCIDefs.h:507
std::string destStop
The id of the destination stop.
Definition: TraCIDefs.h:513
double length
length in m
Definition: TraCIDefs.h:521
double travelTime
duration of the stage in seconds
Definition: TraCIDefs.h:517
double departPos
position on the lane when starting the stage
Definition: TraCIDefs.h:527
std::string description
arbitrary description string
Definition: TraCIDefs.h:531
std::string line
The line or the id of the vehicle type.
Definition: TraCIDefs.h:511
double cost
effort needed
Definition: TraCIDefs.h:519
double depart
intended depart time for public transport ride or INVALID_DOUBLE_VALUE
Definition: TraCIDefs.h:525
std::vector< std::string > edges
The sequence of edges to travel.
Definition: TraCIDefs.h:515
double arrivalPos
position on the lane when ending the stage
Definition: TraCIDefs.h:529
std::string vType
The vehicle type when using a private car or bike.
Definition: TraCIDefs.h:509
virtual std::string readString()
Definition: storage.cpp:180
virtual void writeString(const std::string &s)
Definition: storage.cpp:197
virtual void writeInt(int)
Definition: storage.cpp:321
virtual void writeDouble(double)
Definition: storage.cpp:354
virtual int readUnsignedByte()
Definition: storage.cpp:155
virtual void writeStringList(const std::vector< std::string > &s)
Definition: storage.cpp:247
virtual void writeUnsignedByte(int)
Definition: storage.cpp:165
virtual void writeByte(int)
Definition: storage.cpp:140
virtual double readDouble()
Definition: storage.cpp:362
virtual int readInt()
Definition: storage.cpp:311
TRACI_CONST int CMD_SAVE_SIMSTATE
TRACI_CONST int VAR_STOP_ENDING_VEHICLES_IDS
TRACI_CONST int POSITION_3D
TRACI_CONST int POSITION_ROADMAP
TRACI_CONST int VAR_ARRIVED_VEHICLES_NUMBER
TRACI_CONST int VAR_STOP_STARTING_VEHICLES_NUMBER
TRACI_CONST int VAR_DEPARTED_VEHICLES_NUMBER
TRACI_CONST int CMD_LOAD_SIMSTATE
TRACI_CONST int VAR_COLLIDING_VEHICLES_NUMBER
TRACI_CONST int VAR_COLLISIONS
TRACI_CONST int CMD_CLEAR_PENDING_VEHICLES
TRACI_CONST int VAR_PARKING_ENDING_VEHICLES_IDS
TRACI_CONST int VAR_PARKING_STARTING_VEHICLES_IDS
TRACI_CONST int TYPE_COMPOUND
TRACI_CONST int VAR_PARKING_MANEUVERING_VEHICLES_IDS
TRACI_CONST int FIND_INTERMODAL_ROUTE
TRACI_CONST int VAR_DEPARTED_PERSONS_NUMBER
TRACI_CONST int VAR_PARKING_MANEUVERING_VEHICLES_NUMBER
TRACI_CONST int POSITION_2D
TRACI_CONST int VAR_ARRIVED_PERSONS_IDS
TRACI_CONST int TYPE_POLYGON
TRACI_CONST int VAR_NET_BOUNDING_BOX
TRACI_CONST int TYPE_STRINGLIST
TRACI_CONST int CMD_SET_SIM_VARIABLE
TRACI_CONST int TYPE_INTEGER
TRACI_CONST int POSITION_LON_LAT
TRACI_CONST int VAR_EMERGENCYSTOPPING_VEHICLES_IDS
TRACI_CONST int VAR_PARAMETER
TRACI_CONST int VAR_DEPARTED_VEHICLES_IDS
TRACI_CONST int VAR_TELEPORT_ENDING_VEHICLES_NUMBER
TRACI_CONST int CMD_GET_SIM_VARIABLE
TRACI_CONST int CMD_MESSAGE
TRACI_CONST int VAR_PARKING_ENDING_VEHICLES_NUMBER
TRACI_CONST int VAR_LOADED_VEHICLES_IDS
TRACI_CONST int REQUEST_DRIVINGDIST
TRACI_CONST int VAR_DEPARTED_PERSONS_IDS
TRACI_CONST int VAR_ARRIVED_PERSONS_NUMBER
TRACI_CONST int RESPONSE_GET_SIM_VARIABLE
TRACI_CONST int VAR_STOP_STARTING_VEHICLES_IDS
TRACI_CONST int FIND_ROUTE
TRACI_CONST int VAR_STOP_ENDING_VEHICLES_NUMBER
TRACI_CONST int POSITION_CONVERSION
TRACI_CONST int TYPE_DOUBLE
TRACI_CONST int DISTANCE_REQUEST
TRACI_CONST int VAR_LOADED_VEHICLES_NUMBER
TRACI_CONST int VAR_TELEPORT_ENDING_VEHICLES_IDS
TRACI_CONST int VAR_COLLIDING_VEHICLES_IDS
TRACI_CONST int VAR_TELEPORT_STARTING_VEHICLES_NUMBER
TRACI_CONST int VAR_TELEPORT_STARTING_VEHICLES_IDS
TRACI_CONST int RTYPE_ERR
TRACI_CONST int VAR_ARRIVED_VEHICLES_IDS
TRACI_CONST int RTYPE_OK
TRACI_CONST int VAR_PARKING_STARTING_VEHICLES_NUMBER
TRACI_CONST int POSITION_LON_LAT_ALT
TRACI_CONST int VAR_EMERGENCYSTOPPING_VEHICLES_NUMBER
TRACI_CONST int TYPE_STRING
A list of positions.
Definition: TraCIDefs.h:207
std::vector< TraCIPosition > value
Definition: TraCIDefs.h:217