Line data Source code
1 : /****************************************************************************/
2 : // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3 : // Copyright (C) 2012-2026 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 : /****************************************************************************/
14 : /// @file Vehicle.h
15 : /// @author Michael Behrisch
16 : /// @author Jakob Erdmann
17 : /// @date 15.03.2017
18 : ///
19 : // C++ Vehicle API
20 : /****************************************************************************/
21 : #pragma once
22 : #include <limits>
23 : #include <vector>
24 : #include <libsumo/TraCIDefs.h>
25 : #include <libsumo/VehicleType.h>
26 : #include <libsumo/TraCIConstants.h>
27 :
28 :
29 : // ===========================================================================
30 : // class declarations
31 : // ===========================================================================
32 : #ifndef LIBTRACI
33 : class PositionVector;
34 : class SUMOVehicle;
35 : #endif
36 :
37 :
38 : // ===========================================================================
39 : // class definitions
40 : // ===========================================================================
41 : /**
42 : * @class Vehicle
43 : * @brief C++ TraCI client API implementation
44 : */
45 : namespace LIBSUMO_NAMESPACE {
46 : class Vehicle {
47 : public:
48 : /// @name Value retrieval
49 : /// @{
50 : static double getSpeed(const std::string& vehID);
51 : static double getLateralSpeed(const std::string& vehID);
52 : static double getAcceleration(const std::string& vehID);
53 : static double getSpeedWithoutTraCI(const std::string& vehID);
54 : static libsumo::TraCIPosition getPosition(const std::string& vehID, const bool includeZ = false);
55 : static libsumo::TraCIPosition getPosition3D(const std::string& vehID);
56 : static double getAngle(const std::string& vehID);
57 : static double getSlope(const std::string& vehID);
58 : static std::string getRoadID(const std::string& vehID);
59 : static std::string getLaneID(const std::string& vehID);
60 : static int getLaneIndex(const std::string& vehID);
61 : static std::string getSegmentID(const std::string& vehID);
62 : static int getSegmentIndex(const std::string& vehID);
63 : static std::string getTypeID(const std::string& vehID);
64 : static std::string getRouteID(const std::string& vehID);
65 : static double getDeparture(const std::string& vehID);
66 : static double getDepartDelay(const std::string& vehID);
67 : static int getRouteIndex(const std::string& vehID);
68 : static double getLanePosition(const std::string& vehID);
69 : static double getLateralLanePosition(const std::string& vehID);
70 : static double getCO2Emission(const std::string& vehID);
71 : static double getCOEmission(const std::string& vehID);
72 : static double getHCEmission(const std::string& vehID);
73 : static double getPMxEmission(const std::string& vehID);
74 : static double getNOxEmission(const std::string& vehID);
75 : static double getFuelConsumption(const std::string& vehID);
76 : static double getNoiseEmission(const std::string& vehID);
77 : static double getElectricityConsumption(const std::string& vehID);
78 : static int getPersonNumber(const std::string& vehID);
79 : static std::vector<std::string> getPersonIDList(const std::string& vehID);
80 : static std::pair<std::string, double> getLeader(const std::string& vehID, double dist = 100.);
81 : static std::pair<std::string, double> getFollower(const std::string& vehID, double dist = 0.);
82 : static std::vector<libsumo::TraCIJunctionFoe> getJunctionFoes(const std::string& vehID, double dist = 0.);
83 : static double getWaitingTime(const std::string& vehID);
84 : static double getAccumulatedWaitingTime(const std::string& vehID);
85 : static double getAdaptedTraveltime(const std::string& vehID, double time, const std::string& edgeID);
86 : static double getEffort(const std::string& vehID, double time, const std::string& edgeID);
87 : static bool isRouteValid(const std::string& vehID);
88 : static std::vector<std::string> getRoute(const std::string& vehID);
89 : static int getSignals(const std::string& vehID);
90 : static std::vector<libsumo::TraCIBestLanesData> getBestLanes(const std::string& vehID);
91 : static std::vector<libsumo::TraCINextTLSData> getNextTLS(const std::string& vehID);
92 : static std::vector<libsumo::TraCINextStopData> getNextStops(const std::string& vehID);
93 : static std::vector<libsumo::TraCIConnection> getNextLinks(const std::string& vehID);
94 : static std::vector<libsumo::TraCINextStopData> getStops(const std::string& vehID, int limit = 0);
95 : static int getStopState(const std::string& vehID);
96 : static std::string getStopParameter(const std::string& vehID, int nextStopIndex, const std::string& param, bool customParam = false);
97 :
98 : static double getDistance(const std::string& vehID);
99 : static double getDrivingDistance(const std::string& vehID, const std::string& edgeID, double pos, int laneIndex = 0);
100 : static double getDrivingDistance2D(const std::string& vehID, double x, double y);
101 : static double getReferenceDistance(const std::string& vehID);
102 : static double getAllowedSpeed(const std::string& vehID);
103 : static int getSpeedMode(const std::string& vehID);
104 : static int getLaneChangeMode(const std::string& vehID);
105 : static int getRoutingMode(const std::string& vehID);
106 : static std::string getLine(const std::string& vehID);
107 : static std::vector<std::string> getVia(const std::string& vehID);
108 : static std::pair<int, int> getLaneChangeState(const std::string& vehID, int direction);
109 : static double getLastActionTime(const std::string& vehID);
110 : static std::vector<std::pair<std::string, double> > getNeighbors(const std::string& vehID, const int mode);
111 : static double getFollowSpeed(const std::string& vehID, double speed, double gap, double leaderSpeed, double leaderMaxDecel, const std::string& leaderID = "");
112 : static double getSecureGap(const std::string& vehID, double speed, double leaderSpeed, double leaderMaxDecel, const std::string& leaderID = "");
113 : static double getStopSpeed(const std::string& vehID, double speed, double gap);
114 : static double getStopDelay(const std::string& vehID);
115 : static double getStopArrivalDelay(const std::string& vehID);
116 : static double getTimeLoss(const std::string& vehID);
117 : static std::vector<std::string> getTaxiFleet(int taxiState = 0);
118 :
119 : static std::vector<std::string> getLoadedIDList();
120 : static std::vector<std::string> getTeleportingIDList();
121 : /// @}
122 :
123 : LIBSUMO_ID_PARAMETER_API
124 : LIBSUMO_VEHICLE_TYPE_GETTER
125 :
126 : /// @name State Changing
127 : /// @{
128 :
129 : static void setStop(const std::string& vehID,
130 : const std::string& edgeID,
131 : double pos = 1.,
132 : int laneIndex = 0,
133 : double duration = libsumo::INVALID_DOUBLE_VALUE,
134 : int flags = libsumo::STOP_DEFAULT,
135 : double startPos = libsumo::INVALID_DOUBLE_VALUE,
136 : double until = libsumo::INVALID_DOUBLE_VALUE);
137 :
138 : static void replaceStop(const std::string& vehID,
139 : int nextStopIndex,
140 : const std::string& edgeID,
141 : double pos = 1.,
142 : int laneIndex = 0,
143 : double duration = libsumo::INVALID_DOUBLE_VALUE,
144 : int flags = libsumo::STOP_DEFAULT,
145 : double startPos = libsumo::INVALID_DOUBLE_VALUE,
146 : double until = libsumo::INVALID_DOUBLE_VALUE,
147 : int teleport = 0);
148 :
149 : static void insertStop(const std::string& vehID,
150 : int nextStopIndex,
151 : const std::string& edgeID,
152 : double pos = 1.,
153 : int laneIndex = 0,
154 : double duration = libsumo::INVALID_DOUBLE_VALUE,
155 : int flags = libsumo::STOP_DEFAULT,
156 : double startPos = libsumo::INVALID_DOUBLE_VALUE,
157 : double until = libsumo::INVALID_DOUBLE_VALUE,
158 : int teleport = 0);
159 :
160 : static void setStopParameter(const std::string& vehID, int nextStopIndex,
161 : const std::string& param, const std::string& value,
162 : bool customParam = false);
163 :
164 : static void rerouteParkingArea(const std::string& vehID,
165 : const std::string& parkingAreaID);
166 :
167 : static void resume(const std::string& vehID);
168 :
169 : static void add(const std::string& vehID,
170 : const std::string& routeID,
171 : const std::string& typeID = "DEFAULT_VEHTYPE",
172 : const std::string& depart = "now",
173 : const std::string& departLane = "first",
174 : const std::string& departPos = "base",
175 : const std::string& departSpeed = "0",
176 : const std::string& arrivalLane = "current",
177 : const std::string& arrivalPos = "max",
178 : const std::string& arrivalSpeed = "current",
179 : const std::string& fromTaz = "",
180 : const std::string& toTaz = "",
181 : const std::string& line = "",
182 : int personCapacity = 4,
183 : int personNumber = 0);
184 :
185 : static void changeTarget(const std::string& vehID, const std::string& edgeID);
186 : static void changeLane(const std::string& vehID, int laneIndex, double duration);
187 : static void changeLaneRelative(const std::string& vehID, int indexOffset, double duration);
188 : static void changeSublane(const std::string& vehID, double latDist);
189 :
190 : static void slowDown(const std::string& vehID, double speed, double duration);
191 : static void openGap(const std::string& vehID, double newTimeHeadway, double newSpaceHeadway, double duration, double changeRate, double maxDecel = -1, const std::string& referenceVehID = "");
192 : static void deactivateGapControl(const std::string& vehID);
193 : static void requestToC(const std::string& vehID, double leadTime);
194 : static void setSpeed(const std::string& vehID, double speed);
195 : static void setAcceleration(const std::string& vehID, double acceleration, double duration);
196 : static void setPreviousSpeed(const std::string& vehID, double prevSpeed, double prevAcceleration = libsumo::INVALID_DOUBLE_VALUE);
197 : static void setSpeedMode(const std::string& vehID, int speedMode);
198 : static void setLaneChangeMode(const std::string& vehID, int laneChangeMode);
199 : static void setRoutingMode(const std::string& vehID, int routingMode);
200 : static void setType(const std::string& vehID, const std::string& typeID);
201 : static void setRouteID(const std::string& vehID, const std::string& routeID);
202 : static void setRoute(const std::string& vehID, const std::string& edgeID);
203 : static void setRoute(const std::string& vehID, const std::vector<std::string>& edgeIDs);
204 : static void setLateralLanePosition(const std::string& vehID, double posLat);
205 : static void updateBestLanes(const std::string& vehID);
206 : static void setAdaptedTraveltime(const std::string& vehID, const std::string& edgeID,
207 : double time = libsumo::INVALID_DOUBLE_VALUE, double begSeconds = 0, double endSeconds = std::numeric_limits<double>::max());
208 : static void setEffort(const std::string& vehID, const std::string& edgeID,
209 : double effort = libsumo::INVALID_DOUBLE_VALUE, double begSeconds = 0, double endSeconds = std::numeric_limits<double>::max());
210 : static void rerouteTraveltime(const std::string& vehID, const bool currentTravelTimes = true);
211 : static void rerouteEffort(const std::string& vehID);
212 : static void setSignals(const std::string& vehID, int signals);
213 : static void moveTo(const std::string& vehID, const std::string& laneID, double pos, int reason = libsumo::MOVE_AUTOMATIC);
214 : static void moveToXY(const std::string& vehID, const std::string& edgeID, const int laneIndex, const double x, const double y, double angle = libsumo::INVALID_DOUBLE_VALUE, const int keepRoute = 1, double matchThreshold = 100);
215 : static void remove(const std::string& vehID, char reason = libsumo::REMOVE_VAPORIZED);
216 : static void setLine(const std::string& vehID, const std::string& line);
217 : static void setVia(const std::string& vehID, const std::vector<std::string>& edgeList);
218 : static void highlight(const std::string& vehID, const libsumo::TraCIColor& col = libsumo::TraCIColor(255, 0, 0, 255), double size = -1, const int alphaMax = -1, const double duration = -1, const int type = 0);
219 : static void dispatchTaxi(const std::string& vehID, const std::vector<std::string>& reservations);
220 : /// @}
221 :
222 : LIBSUMO_VEHICLE_TYPE_SETTER
223 :
224 3 : LIBSUMO_SUBSCRIPTION_API
225 :
226 : static void subscribeLeader(const std::string& vehID, double dist = 0., double begin = libsumo::INVALID_DOUBLE_VALUE, double end = libsumo::INVALID_DOUBLE_VALUE);
227 :
228 : static void addSubscriptionFilterLanes(const std::vector<int>& lanes, bool noOpposite = false, double downstreamDist = libsumo::INVALID_DOUBLE_VALUE, double upstreamDist = libsumo::INVALID_DOUBLE_VALUE);
229 :
230 : static void addSubscriptionFilterNoOpposite();
231 :
232 : static void addSubscriptionFilterDownstreamDistance(double dist);
233 :
234 : static void addSubscriptionFilterUpstreamDistance(double dist);
235 :
236 : static void addSubscriptionFilterCFManeuver(double downstreamDist = libsumo::INVALID_DOUBLE_VALUE, double upstreamDist = libsumo::INVALID_DOUBLE_VALUE);
237 :
238 : static void addSubscriptionFilterLCManeuver(int direction = libsumo::INVALID_INT_VALUE, bool noOpposite = false, double downstreamDist = libsumo::INVALID_DOUBLE_VALUE, double upstreamDist = libsumo::INVALID_DOUBLE_VALUE);
239 :
240 : static void addSubscriptionFilterLeadFollow(const std::vector<int>& lanes);
241 :
242 : static void addSubscriptionFilterTurn(double downstreamDist = libsumo::INVALID_DOUBLE_VALUE, double foeDistToJunction = libsumo::INVALID_DOUBLE_VALUE);
243 :
244 : static void addSubscriptionFilterVClass(const std::vector<std::string>& vClasses);
245 :
246 : static void addSubscriptionFilterVType(const std::vector<std::string>& vTypes);
247 :
248 : static void addSubscriptionFilterFieldOfVision(double openingAngle);
249 :
250 : static void addSubscriptionFilterLateralDistance(double lateralDist, double downstreamDist = libsumo::INVALID_DOUBLE_VALUE, double upstreamDist = libsumo::INVALID_DOUBLE_VALUE);
251 :
252 : #ifndef LIBTRACI
253 : #ifndef SWIG
254 : /** @brief Saves the shape of the requested object in the given container
255 : * @param id The id of the poi to retrieve
256 : * @param shape The container to fill
257 : */
258 : static void storeShape(const std::string& id, PositionVector& shape);
259 :
260 : static std::shared_ptr<VariableWrapper> makeWrapper();
261 :
262 : static bool handleVariable(const std::string& objID, const int variable, VariableWrapper* wrapper, tcpip::Storage* paramData);
263 :
264 :
265 : private:
266 : static bool isVisible(const SUMOVehicle* veh);
267 :
268 : static bool isOnInit(const std::string& vehID);
269 :
270 : private:
271 : static SubscriptionResults mySubscriptionResults;
272 : static ContextSubscriptionResults myContextSubscriptionResults;
273 : #endif
274 : #endif
275 :
276 : /// @brief invalidated standard constructor
277 : Vehicle() = delete;
278 : };
279 :
280 :
281 : }
|