Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
TraCIServerAPI_Simulation.cpp
Go to the documentation of this file.
1/****************************************************************************/
2// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3// Copyright (C) 2001-2024 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
27#include <microsim/MSNet.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>
41
42
43// ===========================================================================
44// method definitions
45// ===========================================================================
46bool
48 tcpip::Storage& outputStorage) {
49 const int variable = inputStorage.readUnsignedByte();
50 const std::string id = inputStorage.readString();
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 libsumo::StorageHelper::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) {
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
301bool
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::VAR_SCALE
312 && variable != libsumo::CMD_MESSAGE
313 ) {
314 return server.writeErrorStatusCmd(libsumo::CMD_SET_SIM_VARIABLE, "Set Simulation Variable: unsupported variable " + toHex(variable, 2) + " specified", outputStorage);
315 }
316 // id
317 std::string id = inputStorage.readString();
318 // process
319 try {
320 switch (variable) {
321 case libsumo::VAR_SCALE: {
322 double value;
323 if (!server.readTypeCheckingDouble(inputStorage, value)) {
324 return server.writeErrorStatusCmd(libsumo::CMD_SET_SIM_VARIABLE, "A double is needed for setting traffic scale.", outputStorage);
325 }
326 if (value < 0.0) {
327 return server.writeErrorStatusCmd(libsumo::CMD_SET_SIM_VARIABLE, "Traffic scale may not be negative.", outputStorage);
328 }
329 libsumo::Simulation::setScale(value);
330 }
331 break;
333 //clear any pending vehicle insertions
334 std::string route;
335 if (!server.readTypeCheckingString(inputStorage, route)) {
336 return server.writeErrorStatusCmd(libsumo::CMD_SET_SIM_VARIABLE, "A string is needed for clearing pending vehicles.", outputStorage);
337 }
338 libsumo::Simulation::clearPending(route);
339 }
340 break;
342 //save current simulation state
343 std::string file;
344 if (!server.readTypeCheckingString(inputStorage, file)) {
345 return server.writeErrorStatusCmd(libsumo::CMD_SET_SIM_VARIABLE, "A string is needed for saving simulation state.", outputStorage);
346 }
347 libsumo::Simulation::saveState(file);
348 }
349 break;
351 //quick-load simulation state
352 std::string file;
353 if (!server.readTypeCheckingString(inputStorage, file)) {
354 return server.writeErrorStatusCmd(libsumo::CMD_SET_SIM_VARIABLE, "A string is needed for loading simulation state.", outputStorage);
355 }
356 double time = libsumo::Simulation::loadState(file);
358 }
359 break;
361 StoHelp::readCompound(inputStorage, 2, "A compound object of size 2 is needed for setting a parameter.");
362 const std::string name = StoHelp::readTypedString(inputStorage, "The name of the parameter must be given as a string.");
363 const std::string value = StoHelp::readTypedString(inputStorage, "The value of the parameter must be given as a string.");
364 libsumo::Simulation::setParameter(id, name, value);
365 break;
366 }
368 std::string msg;
369 if (!server.readTypeCheckingString(inputStorage, msg)) {
370 return server.writeErrorStatusCmd(libsumo::CMD_SET_SIM_VARIABLE, "A string is needed for adding a log message.", outputStorage);
371 }
372 libsumo::Simulation::writeMessage(msg);
373 }
374 break;
375 default:
376 break;
377 }
378 } catch (libsumo::TraCIException& e) {
379 return server.writeErrorStatusCmd(libsumo::CMD_SET_SIM_VARIABLE, e.what(), outputStorage);
380 }
381 server.writeStatusCmd(libsumo::CMD_SET_SIM_VARIABLE, libsumo::RTYPE_OK, warning, outputStorage);
382 return true;
383}
384
385
386void
388 const std::vector<std::string>& ids = server.getVehicleStateChanges().find(state)->second;
390 outputStorage.writeInt((int) ids.size());
391}
392
393
394void
396 const std::vector<std::string>& ids = server.getVehicleStateChanges().find(state)->second;
398 outputStorage.writeStringList(ids);
399}
400
401
402void
404 const std::vector<std::string>& ids = server.getTransportableStateChanges().find(state)->second;
406 outputStorage.writeInt((int)ids.size());
407}
408
409
410void
412 const std::vector<std::string>& ids = server.getTransportableStateChanges().find(state)->second;
414 outputStorage.writeStringList(ids);
415}
416
417
418bool
420 const int compoundSize, tcpip::Storage& outputStorage,
421 const int commandId) {
422 std::pair<MSLane*, double> roadPos;
423 Position cartesianPos;
424 Position geoPos;
425 double z = 0;
426
427 // actual position type that will be converted
428 int srcPosType = inputStorage.readUnsignedByte();
429
430 switch (srcPosType) {
435 const double x = inputStorage.readDouble();
436 const double y = inputStorage.readDouble();
437 if (srcPosType != libsumo::POSITION_2D && srcPosType != libsumo::POSITION_LON_LAT) {
438 z = inputStorage.readDouble();
439 }
440 geoPos.set(x, y);
441 cartesianPos.set(x, y);
442 if (srcPosType == libsumo::POSITION_LON_LAT || srcPosType == libsumo::POSITION_LON_LAT_ALT) {
444 } else {
446 }
447 }
448 break;
450 const std::string roadID = inputStorage.readString();
451 const double pos = inputStorage.readDouble();
452 const int laneIdx = inputStorage.readUnsignedByte();
453 try {
454 // convert edge,offset,laneIdx to cartesian position
455 cartesianPos = geoPos = libsumo::Helper::getLaneChecking(roadID, laneIdx, pos)->geometryPositionAtOffset(pos);
456 z = cartesianPos.z();
458 } catch (libsumo::TraCIException& e) {
459 server.writeStatusCmd(commandId, libsumo::RTYPE_ERR, e.what());
460 return false;
461 }
462 }
463 break;
464 default:
465 server.writeStatusCmd(commandId, libsumo::RTYPE_ERR, "Source position type not supported");
466 return false;
467 }
468
469 int destPosType = 0;
470 if (!server.readTypeCheckingUnsignedByte(inputStorage, destPosType)) {
471 server.writeStatusCmd(commandId, libsumo::RTYPE_ERR, "Destination position type must be of type ubyte.");
472 return false;
473 }
474
476 if (compoundSize == 3) {
477 inputStorage.readUnsignedByte();
478 const std::string& vClassString = inputStorage.readString();
479 if (!SumoVehicleClassStrings.hasString(vClassString)) {
480 server.writeStatusCmd(commandId, libsumo::RTYPE_ERR, "Unknown vehicle class '" + vClassString + "'.");
481 return false;
482 }
483 vClass = SumoVehicleClassStrings.get(vClassString);
484 }
485
486 switch (destPosType) {
488 // convert cartesion position to edge,offset,lane_index
489 roadPos = libsumo::Helper::convertCartesianToRoadMap(cartesianPos, vClass);
490 if (roadPos.first == nullptr) {
491 server.writeStatusCmd(commandId, libsumo::RTYPE_ERR, "No matching lane found.");
492 return false;
493 }
494 // write result that is added to response msg
496 outputStorage.writeString(roadPos.first->getEdge().getID());
497 outputStorage.writeDouble(roadPos.second);
498 outputStorage.writeUnsignedByte(roadPos.first->getIndex());
499 }
500 break;
505 outputStorage.writeUnsignedByte(destPosType);
506 if (destPosType == libsumo::POSITION_LON_LAT || destPosType == libsumo::POSITION_LON_LAT_ALT) {
507 outputStorage.writeDouble(geoPos.x());
508 outputStorage.writeDouble(geoPos.y());
509 } else {
510 outputStorage.writeDouble(cartesianPos.x());
511 outputStorage.writeDouble(cartesianPos.y());
512 }
513 if (destPosType != libsumo::POSITION_2D && destPosType != libsumo::POSITION_LON_LAT) {
514 outputStorage.writeDouble(z);
515 }
516 break;
517 default:
518 server.writeStatusCmd(commandId, libsumo::RTYPE_ERR, "Destination position type not supported");
519 return false;
520 }
521 return true;
522}
523
524
525bool
527 tcpip::Storage& outputStorage, int commandId) {
528 Position pos1;
529 Position pos2;
530 std::pair<const MSLane*, double> roadPos1;
531 std::pair<const MSLane*, double> roadPos2;
532
533 // read position 1
534 int posType = inputStorage.readUnsignedByte();
535 switch (posType) {
537 try {
538 std::string roadID = inputStorage.readString();
539 roadPos1.second = inputStorage.readDouble();
540 roadPos1.first = libsumo::Helper::getLaneChecking(roadID, inputStorage.readUnsignedByte(), roadPos1.second);
541 pos1 = roadPos1.first->geometryPositionAtOffset(roadPos1.second);
542 } catch (libsumo::TraCIException& e) {
543 server.writeStatusCmd(commandId, libsumo::RTYPE_ERR, e.what());
544 return false;
545 }
546 break;
549 double p1x = inputStorage.readDouble();
550 double p1y = inputStorage.readDouble();
551 pos1.set(p1x, p1y);
552 }
553 if (posType == libsumo::POSITION_3D) {
554 inputStorage.readDouble();// z value is ignored
555 }
557 break;
560 double p1x = inputStorage.readDouble();
561 double p1y = inputStorage.readDouble();
562 pos1.set(p1x, p1y);
564 }
565 if (posType == libsumo::POSITION_LON_LAT_ALT) {
566 inputStorage.readDouble();// altitude value is ignored
567 }
569 break;
570 default:
571 server.writeStatusCmd(commandId, libsumo::RTYPE_ERR, "Unknown position format used for distance request");
572 return false;
573 }
574
575 // read position 2
576 posType = inputStorage.readUnsignedByte();
577 switch (posType) {
579 try {
580 std::string roadID = inputStorage.readString();
581 roadPos2.second = inputStorage.readDouble();
582 roadPos2.first = libsumo::Helper::getLaneChecking(roadID, inputStorage.readUnsignedByte(), roadPos2.second);
583 pos2 = roadPos2.first->geometryPositionAtOffset(roadPos2.second);
584 } catch (libsumo::TraCIException& e) {
585 server.writeStatusCmd(commandId, libsumo::RTYPE_ERR, e.what());
586 return false;
587 }
588 break;
591 double p2x = inputStorage.readDouble();
592 double p2y = inputStorage.readDouble();
593 pos2.set(p2x, p2y);
594 }
595 if (posType == libsumo::POSITION_3D) {
596 inputStorage.readDouble();// z value is ignored
597 }
599 break;
602 double p2x = inputStorage.readDouble();
603 double p2y = inputStorage.readDouble();
604 pos2.set(p2x, p2y);
606 }
607 if (posType == libsumo::POSITION_LON_LAT_ALT) {
608 inputStorage.readDouble();// altitude value is ignored
609 }
611 break;
612 default:
613 server.writeStatusCmd(commandId, libsumo::RTYPE_ERR, "Unknown position format used for distance request");
614 return false;
615 }
616
617 // read distance type
618 const int distType = inputStorage.readUnsignedByte();
619
620 double distance = 0.0;
621 if (distType == libsumo::REQUEST_DRIVINGDIST) {
622 distance = libsumo::Helper::getDrivingDistance(roadPos1, roadPos2);
623 } else {
624 // compute air distance (default)
625 distance = pos1.distanceTo(pos2);
626 }
627 // write response command
629 outputStorage.writeDouble(distance);
630 return true;
631}
632
633
634/****************************************************************************/
#define TIME2STEPS(x)
Definition SUMOTime.h:57
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
static const GeoConvHelper & getFinal()
the coordinate transformation for writing the location element and for tracking the original coordina...
void cartesian2geo(Position &cartesian) const
Converts the given cartesian (shifted) position to its geo (lat/long) representation.
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:560
VehicleState
Definition of a vehicle state.
Definition MSNet.h:608
@ 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:685
@ 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 dimensions
Definition Position.h:266
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 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 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.
static TraCIServer * getInstance()
Definition TraCIServer.h:68
bool readTypeCheckingInt(tcpip::Storage &inputStorage, int &into)
Reads the value type and an int, 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
const std::map< MSNet::TransportableState, std::vector< std::string > > & getTransportableStateChanges() const
static double getDrivingDistance(std::pair< const MSLane *, double > &roadPos1, std::pair< const MSLane *, double > &roadPos2)
Definition Helper.cpp:455
static std::pair< MSLane *, double > convertCartesianToRoadMap(const Position &pos, const SUMOVehicleClass vClass)
Definition Helper.cpp:420
static const MSLane * getLaneChecking(const std::string &edgeID, int laneIndex, double pos)
Definition Helper.cpp:403
static int readCompound(tcpip::Storage &ret, int expectedSize=-1, const std::string &error="")
static std::string readTypedString(tcpip::Storage &ret, const std::string &error="")
static void writeStage(tcpip::Storage &outputStorage, const libsumo::TraCIStage &stage)
An error which allows to continue.
Definition TraCIDefs.h:144
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_SCALE
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:234
std::vector< TraCIPosition > value
Definition TraCIDefs.h:244