SUMO - Simulation of Urban MObility
MSDevice_ToC.h
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2013-2018 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials
5 // are made available under the terms of the Eclipse Public License v2.0
6 // which accompanies this distribution, and is available at
7 // http://www.eclipse.org/legal/epl-v20.html
8 // SPDX-License-Identifier: EPL-2.0
9 /****************************************************************************/
17 // The ToC Device controls the transition of control between automated and manual driving.
18 //
19 /****************************************************************************/
20 #ifndef MSDevice_ToC_h
21 #define MSDevice_ToC_h
22 
23 
24 // ===========================================================================
25 // included modules
26 // ===========================================================================
27 #include <config.h>
28 
29 #include "MSVehicleDevice.h"
30 #include <utils/common/SUMOTime.h>
32 
33 
34 // ===========================================================================
35 // class declarations
36 // ===========================================================================
37 class SUMOVehicle;
38 class MSVehicle;
39 class Command_ToCTrigger;
40 class Command_ToCProcess;
41 class RGBColor;
42 
43 // ===========================================================================
44 // class definitions
45 // ===========================================================================
53 class MSDevice_ToC : public MSVehicleDevice {
54 private:
55  // All currently existing ToC device instances
56  static std::set<MSDevice_ToC*> instances;
57  // All files, that receive ToC output (TODO: check if required)
58  static std::set<std::string> createdOutputFiles;
59 
60  struct OpenGapParams {
63  double changeRate;
64  double maxDecel;
65  bool active;
66  OpenGapParams(double timegap, double spacing, double changeRate, double maxDecel, bool active) :
67  newTimeHeadway(timegap), newSpaceHeadway(spacing), changeRate(changeRate), maxDecel(maxDecel), active(active)
68  {};
69  };
70 
71 public:
75  static void insertOptions(OptionsCont& oc);
76 
77 
88  static void buildVehicleDevices(SUMOVehicle& v, std::vector<MSVehicleDevice*>& into);
89 
92  static const std::set<MSDevice_ToC*>& getInstances() {
93  return instances;
94  };
95 
98  static void cleanup();
99 
100 private:
101 
109  enum ToCState {
111  MANUAL = 1,
113  PREPARING_TOC = 3, // this applies only to the transition AUTOMATED -> MANUAL !
114  MRM = 4,
116  };
117 
120  static std::string getManualType(const SUMOVehicle& v, const OptionsCont& oc);
121  static std::string getAutomatedType(const SUMOVehicle& v, const OptionsCont& oc);
122  static double getResponseTime(const SUMOVehicle& v, const OptionsCont& oc);
123  static double getRecoveryRate(const SUMOVehicle& v, const OptionsCont& oc);
124  static double getLCAbstinence(const SUMOVehicle& v, const OptionsCont& oc);
125  static double getInitialAwareness(const SUMOVehicle& v, const OptionsCont& oc);
126  static double getMRMDecel(const SUMOVehicle& v, const OptionsCont& oc);
127  static bool useColorScheme(const SUMOVehicle& v, const OptionsCont& oc);
128  static std::string getOutputFilename(const SUMOVehicle& v, const OptionsCont& oc);
129  static OpenGapParams getOpenGapParams(const SUMOVehicle& v, const OptionsCont& oc);
130 
131  static ToCState _2ToCState(const std::string&);
132  static std::string _2string(ToCState state);
134 
135 
136 public:
138  ~MSDevice_ToC();
139 
141  const std::string deviceName() const {
142  return "toc";
143  }
144 
146  std::string getParameter(const std::string& key) const;
147 
149  void setParameter(const std::string& key, const std::string& value);
150 
151 
154 
157 
160 
163 
166 
169 
172 
174  void writeOutput();
175 
178  return myOutputFile != nullptr;
179  }
180 
181 private:
197  MSDevice_ToC(SUMOVehicle& holder, const std::string& id, const std::string& outputFilename,
198  std::string manualType, std::string automatedType, SUMOTime responseTime, double recoveryRate,
199  double lcAbstinence, double initialAwareness, double mrmDecel, bool useColorScheme, OpenGapParams ogp);
200 
205  void initColorScheme();
206 
208  void setAwareness(double value);
209 
211  void setState(ToCState state);
212 
213  // @brief Sets the device holder's color corresponding to the current state
214  void setVehicleColor();
215 
222  void requestToC(SUMOTime timeTillMRM);
223 
226  void requestMRM();
227 
229  void switchHolderType(const std::string& targetTypeID);
230 
232  void descheduleMRM();
234  void descheduleToC();
238  void descheduleRecovery();
239 
241  void resetDeliberateLCs();
244 
246  bool isManuallyDriven();
248  bool isAutomated();
249 
250 private:
253 
255  std::string myManualTypeID;
257  std::string myAutomatedTypeID;
258 
267 
269  double myMRMDecel;
270 
273 
275  std::map<ToCState, RGBColor> myColorScheme;
276 
279 
282 
284 
287 
297 
300 
302  std::queue<std::pair<SUMOTime, std::string> > myEvents;
303 
306 
308  static int LCModeMRM;
309 
312 
313 private:
315  MSDevice_ToC(const MSDevice_ToC&);
316 
319 
320 
321 };
322 
323 
324 #endif
325 
326 /****************************************************************************/
327 
int myPreviousLCMode
LC mode overridden during MRM, stored for restoration.
Definition: MSDevice_ToC.h:305
static int LCModeMRM
LC mode operational during an MRM.
Definition: MSDevice_ToC.h:308
static std::string getManualType(const SUMOVehicle &v, const OptionsCont &oc)
Representation of a vehicle in the micro simulation.
Definition: MSVehicle.h:79
long long int SUMOTime
Definition: SUMOTime.h:36
void descheduleRecovery()
Remove ongoing awareness recovery process from the event-queue.
ToCState myState
Current state of the device.
Definition: MSDevice_ToC.h:281
std::queue< std::pair< SUMOTime, std::string > > myEvents
Storage for events to be written to the output.
Definition: MSDevice_ToC.h:302
bool isAutomated()
Whether the current operation mode is automated.
static void insertOptions(OptionsCont &oc)
Inserts MSDevice_ToC-options.
static double getLCAbstinence(const SUMOVehicle &v, const OptionsCont &oc)
static double getRecoveryRate(const SUMOVehicle &v, const OptionsCont &oc)
SUMOTime MRMExecutionStep(SUMOTime t)
Continue the MRM for one time step.
bool isManuallyDriven()
Whether the current operation mode is manual.
void descheduleToCPreparation()
Remove ongoing ToC-Preparation process from the event-queue.
static ToCState _2ToCState(const std::string &)
static std::set< MSDevice_ToC * > instances
Definition: MSDevice_ToC.h:56
void descheduleMRM()
Break MRM Process or remove MRM-Trigger command from the event-queue.
SUMOTime triggerUpwardToC(SUMOTime t)
Trigger execution of a ToC X–>AUTOMATED ("upwards")
static OpenGapParams getOpenGapParams(const SUMOVehicle &v, const OptionsCont &oc)
MSDevice_ToC & operator=(const MSDevice_ToC &)
Invalidated assignment operator.
WrappingCommand< MSDevice_ToC > * myExecuteMRMCommand
Definition: MSDevice_ToC.h:294
static double getResponseTime(const SUMOVehicle &v, const OptionsCont &oc)
static std::set< std::string > createdOutputFiles
Definition: MSDevice_ToC.h:58
void initColorScheme()
Initialize vehicle colors for different states.
static std::string _2string(ToCState state)
SUMOTime triggerDownwardToC(SUMOTime t)
Trigger execution of a ToC X–>MANUAL ("downwards")
static bool useColorScheme(const SUMOVehicle &v, const OptionsCont &oc)
std::string myAutomatedTypeID
vehicle type ID for automated driving
Definition: MSDevice_ToC.h:257
void requestToC(SUMOTime timeTillMRM)
Request a ToC. If the device is in AUTOMATED or MRM state, a driver response time is sampled and the ...
void requestMRM()
Request an MRM to be initiated immediately. No downward ToC will be scheduled.
void deactivateDeliberateLCs()
Resets the holder&#39;s LC mode to the operational LC-mode of the ToC Device (.
MSDevice_ToC(SUMOVehicle &holder, const std::string &id, const std::string &outputFilename, std::string manualType, std::string automatedType, SUMOTime responseTime, double recoveryRate, double lcAbstinence, double initialAwareness, double mrmDecel, bool useColorScheme, OpenGapParams ogp)
Constructor.
static void buildVehicleDevices(SUMOVehicle &v, std::vector< MSVehicleDevice *> &into)
Build devices for the given vehicle, if needed.
WrappingCommand< MSDevice_ToC > * myTriggerMRMCommand
Definition: MSDevice_ToC.h:291
static void cleanup()
Closes root tags of output files.
static std::string getOutputFilename(const SUMOVehicle &v, const OptionsCont &oc)
void setAwareness(double value)
Set the awareness to the given value.
SUMOTime ensureDriverStateExistence(SUMOTime)
Ensure existence of DriverState for equipped vehicles.
bool myUseColorScheme
Whether a coloring scheme shall by applied to indicate the different toc stages,. ...
Definition: MSDevice_ToC.h:278
Representation of a vehicle.
Definition: SUMOVehicle.h:60
OutputDevice * myOutputFile
The file the devices output goes to.
Definition: MSDevice_ToC.h:299
double myLCAbstinence
Level of the awareness below which no lane-changes are performed.
Definition: MSDevice_ToC.h:264
ToCState
Enum describing the different regimes for the device,.
Definition: MSDevice_ToC.h:109
std::string getParameter(const std::string &key) const
try to retrieve the given parameter from this device. Throw exception for unsupported key ...
MSVehicle * myHolderMS
The holder vehicle casted to MSVehicle*.
Definition: MSDevice_ToC.h:286
SUMOTime myResponseTime
Average response time needed by the driver to take back control.
Definition: MSDevice_ToC.h:260
static double getMRMDecel(const SUMOVehicle &v, const OptionsCont &oc)
static const std::set< MSDevice_ToC * > & getInstances()
returns all currently existing ToC devices
Definition: MSDevice_ToC.h:92
std::string myManualTypeID
vehicle type ID for manual driving
Definition: MSDevice_ToC.h:255
double myCurrentAwareness
Current awareness-level of the driver in [0,1].
Definition: MSDevice_ToC.h:272
static double getInitialAwareness(const SUMOVehicle &v, const OptionsCont &oc)
SUMOTime ToCPreparationStep(SUMOTime t)
Continue the ToC preparation for one time step.
OpenGapParams(double timegap, double spacing, double changeRate, double maxDecel, bool active)
Definition: MSDevice_ToC.h:66
void setVehicleColor()
A storage for options typed value containers)
Definition: OptionsCont.h:92
Abstract in-vehicle device.
void setState(ToCState state)
Set the ToC device&#39;s state.
void descheduleToC()
Remove scheduled ToC-Trigger command from the event-queue.
double myRecoveryRate
Recovery rate for the driver&#39;s awareness after a ToC.
Definition: MSDevice_ToC.h:262
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:64
WrappingCommand< MSDevice_ToC > * myRecoverAwarenessCommand
Definition: MSDevice_ToC.h:293
SUMOTime awarenessRecoveryStep(SUMOTime t)
Continue the awareness recovery for one time step.
~MSDevice_ToC()
Destructor.
void resetDeliberateLCs()
Resets the holder&#39;s LC mode to the last differing to LCModeMRM.
WrappingCommand< MSDevice_ToC > * myTriggerToCCommand
Definition: MSDevice_ToC.h:292
const std::string deviceName() const
return the name for this type of device
Definition: MSDevice_ToC.h:141
void switchHolderType(const std::string &targetTypeID)
Switch the device holder&#39;s vehicle type.
void setParameter(const std::string &key, const std::string &value)
try to set the given parameter for this device. Throw exception for unsupported key ...
OpenGapParams myOpenGapParams
Parameters for the openGap mechanism applied during ToC preparation phase.
Definition: MSDevice_ToC.h:311
SUMOTime triggerMRM(SUMOTime t)
Trigger execution of an MRM.
WrappingCommand< MSDevice_ToC > * myPrepareToCCommand
Definition: MSDevice_ToC.h:295
std::map< ToCState, RGBColor > myColorScheme
Coloring scheme,.
Definition: MSDevice_ToC.h:275
bool generatesOutput()
Whether this device requested to write output.
Definition: MSDevice_ToC.h:177
The ToC Device controls transition of control between automated and manual driving.
Definition: MSDevice_ToC.h:53
void writeOutput()
Write output to file given by option device.toc.file.
double myMRMDecel
Deceleration rate applied during MRM.
Definition: MSDevice_ToC.h:269
double myInitialAwareness
Average awareness the driver has initially after a ToC.
Definition: MSDevice_ToC.h:266
static std::string getAutomatedType(const SUMOVehicle &v, const OptionsCont &oc)