Eclipse SUMO - Simulation of Urban MObility
MSVTypeProbe.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-2023 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// Writes positions of vehicles that have a certain (named) type
22/****************************************************************************/
23#include <config.h>
24
25#include <string>
27#include <microsim/MSNet.h>
28#include <microsim/MSVehicle.h>
31#include <microsim/MSLane.h>
34
35#include "MSVTypeProbe.h"
36
37
38// ===========================================================================
39// method definitions
40// ===========================================================================
41MSVTypeProbe::MSVTypeProbe(const std::string& id,
42 const std::string& vType,
43 OutputDevice& od, SUMOTime frequency)
44 : Named(id), myVType(vType), myOutputDevice(od), myFrequency(frequency) {
46 myOutputDevice.writeXMLHeader("vehicle-type-probes", "vtypeprobe_file.xsd");
47}
48
49
51}
52
53
61 for (MSVehicleControl::constVehIt it = vc.loadedVehBegin(); it != vc.loadedVehEnd(); ++it) {
62 const SUMOVehicle* veh = it->second;
63 const MSVehicle* microVeh = dynamic_cast<const MSVehicle*>(veh);
64 if (myVType == "" || myVType == veh->getVehicleType().getID()) {
65 if (veh->isOnRoad()) {
66 Position pos = veh->getPosition();
69 if (microVeh != nullptr) {
71 }
77 }
84 }
87 }
88 }
89 }
91 return myFrequency;
92}
93
94
95/****************************************************************************/
long long int SUMOTime
Definition: GUI.h:36
std::string time2string(SUMOTime t, bool humanReadable)
convert SUMOTime to string (independently of global format setting)
Definition: SUMOTime.cpp:69
@ SUMO_TAG_TIMESTEP
@ SUMO_TAG_VEHICLE
description of a vehicle
@ SUMO_ATTR_LANE
@ SUMO_ATTR_LON
@ SUMO_ATTR_SPEED
@ SUMO_ATTR_Y
@ SUMO_ATTR_Z
@ SUMO_ATTR_X
@ SUMO_ATTR_LAT
@ SUMO_ATTR_ID
@ SUMO_ATTR_POSITION
@ SUMO_ATTR_TIME
trigger: the time of the step
int gPrecisionGeo
Definition: StdDefs.cpp:27
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 usingGeoProjection() const
Returns whether a transformation from geo to metric coordinates will be performed.
virtual void addEvent(Command *operation, SUMOTime execTimeStep=-1)
Adds an Event.
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
Definition: MSNet.cpp:183
MSEventControl * getEndOfTimestepEvents()
Returns the event control for events executed at the end of a time step.
Definition: MSNet.h:483
MSVehicleControl & getVehicleControl()
Returns the vehicle control.
Definition: MSNet.h:380
bool hasElevation() const
return whether the network contains elevation data
Definition: MSNet.h:788
virtual ~MSVTypeProbe()
Destructor.
SUMOTime execute(SUMOTime currentTime)
Writes values into the given stream.
std::string myVType
The id of the vehicle type vehicles must have to be reported.
Definition: MSVTypeProbe.h:87
OutputDevice & myOutputDevice
The device to write into.
Definition: MSVTypeProbe.h:90
SUMOTime myFrequency
The frequency of reporting.
Definition: MSVTypeProbe.h:93
MSVTypeProbe(const std::string &id, const std::string &vType, OutputDevice &od, SUMOTime frequency)
Constructor.
The class responsible for building and deletion of vehicles.
std::map< std::string, SUMOVehicle * >::const_iterator constVehIt
Definition of the internal vehicles map iterator.
constVehIt loadedVehBegin() const
Returns the begin of the internal vehicle map.
constVehIt loadedVehEnd() const
Returns the end of the internal vehicle map.
Representation of a vehicle in the micro simulation.
Definition: MSVehicle.h:77
const MSLane * getLane() const
Returns the lane the vehicle is on.
Definition: MSVehicle.h:584
const std::string & getID() const
Returns the name of the vehicle type.
Definition: MSVehicleType.h:91
Base class for objects which have an id.
Definition: Named.h:54
const std::string & getID() const
Returns the id.
Definition: Named.h:74
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:61
OutputDevice & writeAttr(const SumoXMLAttr attr, const T &val)
writes a named attribute
Definition: OutputDevice.h:254
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.
bool closeTag(const std::string &comment="")
Closes the most recently opened tag and optionally adds a comment.
void setPrecision(int precision=gPrecision)
Sets the precision or resets it to default.
bool writeXMLHeader(const std::string &rootElement, const std::string &schemaFile, std::map< SumoXMLAttr, std::string > attrs=std::map< SumoXMLAttr, std::string >(), bool includeConfig=true)
Writes an XML header with optional configuration.
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:37
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
virtual const MSVehicleType & getVehicleType() const =0
Returns the object's "vehicle" type.
virtual double getSpeed() const =0
Returns the object's current speed.
virtual Position getPosition(const double offset=0) const =0
Return current position (x/y, cartesian)
virtual double getPositionOnLane() const =0
Get the object's position along the lane.
Representation of a vehicle.
Definition: SUMOVehicle.h:62
virtual bool isOnRoad() const =0
Returns the information whether the vehicle is on a road (is simulated)