Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
MSDevice_ToC.h
Go to the documentation of this file.
1/****************************************************************************/
2// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3// Copyright (C) 2013-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/****************************************************************************/
20// The ToC Device controls the transition of control between automated and manual driving.
21//
22/****************************************************************************/
23#pragma once
24#include <config.h>
25
26#include <random>
27#include <queue>
28#include "MSVehicleDevice.h"
31
32
33// ===========================================================================
34// class declarations
35// ===========================================================================
36class SUMOVehicle;
37class MSVehicle;
38class Command_ToCTrigger;
39class Command_ToCProcess;
40class RGBColor;
41
42// ===========================================================================
43// class definitions
44// ===========================================================================
53private:
54 // All currently existing ToC device instances
55 static std::set<MSDevice_ToC*, ComparatorNumericalIdLess> myInstances;
56 // All files, that receive ToC output (TODO: check if required)
57 static std::set<std::string> createdOutputFiles;
58
62 double changeRate;
63 double maxDecel;
64 bool active;
65 OpenGapParams(double timegap, double spacing, double changeRate, double maxDecel, bool active) :
67 {};
68 };
69
70public:
74 static void insertOptions(OptionsCont& oc);
75
76
87 static void buildVehicleDevices(SUMOVehicle& v, std::vector<MSVehicleDevice*>& into);
88
91 static const std::set<MSDevice_ToC*, ComparatorNumericalIdLess>& getInstances() {
92 return myInstances;
93 };
94
97 static void cleanup();
98
99private:
100
108 enum ToCState {
112 PREPARING_TOC = 3, // this applies only to the transition AUTOMATED -> MANUAL !
113 MRM = 4,
114 RECOVERING = 5
115 };
116
119 static double getDynamicMRMProbability(const SUMOVehicle& v, const OptionsCont& oc);
120 static std::string getOutputFilename(const SUMOVehicle& v, const OptionsCont& oc);
121 static OpenGapParams getOpenGapParams(const SUMOVehicle& v, const OptionsCont& oc);
122
123 static ToCState _2ToCState(const std::string&);
124 static std::string _2string(ToCState state);
126
127
128public:
131
133 const std::string deviceName() const override {
134 return "toc";
135 }
136
139 double oldPos,
140 double newPos,
141 double newSpeed) override;
142
144 std::string getParameter(const std::string& key) const override;
145
147 void setParameter(const std::string& key, const std::string& value) override;
148
149
152
155
158
161
164
167
169 void writeOutput();
170
173 return myOutputFile != nullptr;
174 }
175
177 return &myResponseTimeRNG;
178 }
179private:
197 MSDevice_ToC(SUMOVehicle& holder, const std::string& id, const std::string& outputFilename,
198 const std::string& manualType, const std::string& automatedType, SUMOTime responseTime, double recoveryRate,
199 double lcAbstinence, double initialAwareness, double mrmDecel,
200 double dynamicToCThreshold, double dynamicMRMProbability, double maxPreparationAccel,
201 bool mrmKeepRight, const std::string& mrmSafeSpot, SUMOTime mrmSafeSpotDuration, bool useColorScheme, OpenGapParams ogp);
202
207 void initColorScheme();
208
210 void setAwareness(double value);
211
213 void setState(ToCState state);
214
215 // @brief Sets the device holder's color corresponding to the current state
216 void setVehicleColor();
217
227 void requestToC(SUMOTime timeTillMRM, SUMOTime responseTime = -1000);
228
231 void requestMRM();
232
234 void switchHolderType(const std::string& targetTypeID);
235
237 void descheduleMRM();
239 void descheduleToC();
243 void descheduleRecovery();
244
246 void resetDeliberateLCs();
249
251 bool isManuallyDriven();
253 bool isAutomated();
254
258 bool checkDynamicToC();
259
260private:
263
265 std::string myManualTypeID;
267 std::string myAutomatedTypeID;
268
269
278
281
284
286 std::map<ToCState, RGBColor> myColorScheme;
287
290
293
295
298
308
311
313 std::queue<std::pair<SUMOTime, std::string> > myEvents;
314
316 std::queue<std::pair<std::string, double> > myEventLanes;
317
319 std::queue<std::pair<double, double>> myEventXY;
320
323
325 static int LCModeMRM;
326
329
334 // (Note that these MRMs will not induce full stops in most cases)
342
345
347 std::string myMRMSafeSpot;
348
351
355
358
360 static std::vector<double> lookupResponseTimeMRMProbs;
361 static std::vector<double> lookupResponseTimeLeadTimes;
363 static double responseTimeMean(double leadTime) {
364 return MIN2(2 * sqrt(leadTime), 0.7 * leadTime);
365 };
369 static std::vector<std::vector<double> > lookupResponseTimeVariances;
370
373
376 double sampleResponseTime(double leadTime) const;
377
380 static double interpolateVariance(double leadTime, double pMRM);
381
382private:
385
388
389
390};
long long int SUMOTime
Definition GUI.h:36
T MIN2(T a, T b)
Definition StdDefs.h:76
The ToC Device controls transition of control between automated and manual driving.
SUMOTime MRMExecutionStep(SUMOTime t)
Continue the MRM for one time step.
std::string myAutomatedTypeID
vehicle type ID for automated driving
void requestMRM()
Request an MRM to be initiated immediately. No downward ToC will be scheduled.
std::string myManualTypeID
vehicle type ID for manual driving
static void cleanup()
Closes root tags of output files.
double myRecoveryRate
Recovery rate for the driver's awareness after a ToC.
bool myDynamicToCActive
Switch for considering dynamic ToCs,.
double myMRMDecel
Deceleration rate applied during MRM.
WrappingCommand< MSDevice_ToC > * myTriggerToCCommand
static double interpolateVariance(double leadTime, double pMRM)
Two-dimensional interpolation of variance from lookup table assumes pMRM >= 0, leadTime >= 0.
static int LCModeMRM
LC mode operational during an MRM.
double myInitialAwareness
Average awareness the driver has initially after a ToC.
bool myUseColorScheme
Whether a coloring scheme shall by applied to indicate the different toc stages,.
OpenGapParams myOpenGapParams
Parameters for the openGap mechanism applied during ToC preparation phase.
static std::vector< std::vector< double > > lookupResponseTimeVariances
Variances of the response time distribution. Given the lead time and the MRM probability the variance...
bool notifyMove(SUMOTrafficObject &veh, double oldPos, double newPos, double newSpeed) override
Return value indicates whether the device still wants to be notified about the vehicle movement.
SUMOTime myMRMSafeSpotDuration
duration at stop vehicle tries to reach during MRM
void resetDeliberateLCs()
Resets the holder's LC mode to the last differing to LCModeMRM.
double myOriginalMaxAccel
Storage for original maximal acceleration of vehicle.
MSDevice_ToC & operator=(const MSDevice_ToC &)
Invalidated assignment operator.
const std::string deviceName() const override
return the name for this type of device
static std::vector< double > lookupResponseTimeLeadTimes
WrappingCommand< MSDevice_ToC > * myExecuteMRMCommand
static std::set< std::string > createdOutputFiles
SUMOTime ToCPreparationStep(SUMOTime t)
Continue the ToC preparation for one time step.
~MSDevice_ToC()
Destructor.
bool myIssuedDynamicToC
Flag to indicate that a dynamically triggered ToC is in preparation.
double myMRMProbability
Probability of an MRM to occur after a dynamically triggered ToC.
static std::set< MSDevice_ToC *, ComparatorNumericalIdLess > myInstances
void descheduleRecovery()
Remove ongoing awareness recovery process from the event-queue.
int myPreviousLCMode
LC mode overridden during MRM, stored for restoration.
void requestToC(SUMOTime timeTillMRM, SUMOTime responseTime=-1000)
Request a ToC. If the device is in AUTOMATED or MRM state, a driver response time is sampled and the ...
double sampleResponseTime(double leadTime) const
Samples a random driver response time from a truncated Gaussian with parameters according to the look...
static OpenGapParams getOpenGapParams(const SUMOVehicle &v, const OptionsCont &oc)
std::queue< std::pair< std::string, double > > myEventLanes
Storage for events to be written to the output.
static void insertOptions(OptionsCont &oc)
Inserts MSDevice_ToC-options.
bool myMRMKeepRight
Whether vehicle tries to change to the right during an MRM.
bool isManuallyDriven()
Whether the current operation mode is manual.
static void buildVehicleDevices(SUMOVehicle &v, std::vector< MSVehicleDevice * > &into)
Build devices for the given vehicle, if needed.
void setVehicleColor()
ToCState myState
Current state of the device.
double myMaxPreparationAccel
Maximal acceleration that may be applied during the ToC preparation phase TODO: Make effective.
static ToCState _2ToCState(const std::string &)
static std::string getOutputFilename(const SUMOVehicle &v, const OptionsCont &oc)
int myDynamicToCLane
Lane, on which the ongoing dynamic ToC was issued. It can only be aborted if the lane was changed.
bool isAutomated()
Whether the current operation mode is automated.
std::map< ToCState, RGBColor > myColorScheme
Coloring scheme,.
static std::string _2string(ToCState state)
static SumoRNG myResponseTimeRNG
Random generator for ToC devices.
void setState(ToCState state)
Set the ToC device's state.
SUMOTime myResponseTime
Average response time needed by the driver to take back control.
void setParameter(const std::string &key, const std::string &value) override
try to set the given parameter for this device. Throw exception for unsupported key
bool generatesOutput()
Whether this device requested to write output.
double myLCAbstinence
Level of the awareness below which no lane-changes are performed.
SUMOTime triggerDownwardToC(SUMOTime t)
Trigger execution of a ToC X-->MANUAL ("downwards")
static SumoRNG * getResponseTimeRNG()
void initColorScheme()
Initialize vehicle colors for different states.
MSVehicle * myHolderMS
The holder vehicle casted to MSVehicle*.
WrappingCommand< MSDevice_ToC > * myPrepareToCCommand
std::string getParameter(const std::string &key) const override
try to retrieve the given parameter from this device. Throw exception for unsupported key
void descheduleMRM()
Break MRM Process or remove MRM-Trigger command from the event-queue.
static double responseTimeMean(double leadTime)
Mean of the response time distribution. (Only depends on given lead time)
void descheduleToC()
Remove scheduled ToC-Trigger command from the event-queue.
static const std::set< MSDevice_ToC *, ComparatorNumericalIdLess > & getInstances()
returns all currently existing ToC devices
void descheduleToCPreparation()
Remove ongoing ToC-Preparation process from the event-queue.
MSDevice_ToC(const MSDevice_ToC &)
Invalidated copy constructor.
void deactivateDeliberateLCs()
Resets the holder's LC mode to the operational LC-mode of the ToC Device (.
WrappingCommand< MSDevice_ToC > * myRecoverAwarenessCommand
void setAwareness(double value)
Set the awareness to the given value.
WrappingCommand< MSDevice_ToC > * myTriggerMRMCommand
double myDynamicToCThreshold
Duration in s. for which the vehicle needs to be able to follow its route without a lane change to co...
bool checkDynamicToC()
Check if the vehicle should induce a ToC due to internal reasons. That is, if the route cannot be fol...
ToCState
Enum describing the different regimes for the device,.
static double getDynamicMRMProbability(const SUMOVehicle &v, const OptionsCont &oc)
void writeOutput()
Write output to file given by option device.toc.file.
std::queue< std::pair< double, double > > myEventXY
Storage for events to be written to the output.
OutputDevice * myOutputFile
The file the devices output goes to.
double myCurrentAwareness
Current awareness-level of the driver in [0,1].
SUMOTime triggerMRM(SUMOTime t)
Trigger execution of an MRM.
SUMOTime triggerUpwardToC(SUMOTime t)
Trigger execution of a ToC X-->AUTOMATED ("upwards")
std::queue< std::pair< SUMOTime, std::string > > myEvents
Storage for events to be written to the output.
SUMOTime awarenessRecoveryStep(SUMOTime t)
Continue the awareness recovery for one time step.
std::string myMRMSafeSpot
stop vehicle tries to reach during MRM
static std::vector< double > lookupResponseTimeMRMProbs
Grid of the response time distribution.
void switchHolderType(const std::string &targetTypeID)
Switch the device holder's vehicle type.
Abstract in-vehicle device.
Representation of a vehicle in the micro simulation.
Definition MSVehicle.h:77
A storage for options typed value containers)
Definition OptionsCont.h:89
Static storage of an output device and its base (abstract) implementation.
Representation of a vehicle, person, or container.
Representation of a vehicle.
Definition SUMOVehicle.h:62
A wrapper for a Command function.
OpenGapParams(double timegap, double spacing, double changeRate, double maxDecel, bool active)