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 "MSDevice.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 // ===========================================================================
55 class MSDevice_ToC : public MSDevice {
56 public:
60  static void insertOptions(OptionsCont& oc);
61 
62 
73  static void buildVehicleDevices(SUMOVehicle& v, std::vector<MSDevice*>& into);
74 
75 private:
76 
84  enum ToCState {
85  UNDEFINED = 0,
86  MANUAL = 1,
87  AUTOMATED = 2,
88  PREPARING_TOC = 3, // this applies only to the transition AUTOMATED -> MANUAL !
89  MRM = 4,
91  };
92 
95  static std::string getManualType(const SUMOVehicle& v, const OptionsCont& oc);
96  static std::string getAutomatedType(const SUMOVehicle& v, const OptionsCont& oc);
97  static double getResponseTime(const SUMOVehicle& v, const OptionsCont& oc);
98  static double getRecoveryRate(const SUMOVehicle& v, const OptionsCont& oc);
99  static double getInitialAwareness(const SUMOVehicle& v, const OptionsCont& oc);
100  static double getMRMDecel(const SUMOVehicle& v, const OptionsCont& oc);
101  static bool useColorScheme(const SUMOVehicle& v, const OptionsCont& oc);
102 
103  static ToCState _2ToCState(const std::string&);
104  static std::string _2string(ToCState state);
106 
107 
108 public:
110  ~MSDevice_ToC();
111 
113  const std::string deviceName() const {
114  return "toc";
115  }
116 
118  std::string getParameter(const std::string& key) const;
119 
121  void setParameter(const std::string& key, const std::string& value);
122 
123 
126 
129 
132 
135 
138 
141 
144 
145 private:
151  MSDevice_ToC(SUMOVehicle& holder, const std::string& id,
152  std::string manualType, std::string automatedType,
153  SUMOTime responseTime, double recoveryRate, double initialAwareness,
154  double mrmDecel, bool useColorScheme);
155 
160  void initColorScheme();
161 
163  void setAwareness(double value);
164 
166  void setState(ToCState state);
167 
168  // @brief Sets the device holder's color corresponding to the current state
169  void setVehicleColor();
170 
177  void requestToC(SUMOTime timeTillMRM);
178 
181  void requestMRM();
182 
184  void switchHolderType(const std::string& targetTypeID);
185 
187  void descheduleMRM();
189  void descheduleToC();
193  void descheduleRecovery();
194 
195 
196 
197 private:
200 
202  std::string myManualTypeID;
204  std::string myAutomatedTypeID;
205 
206  // @brief Average response time needed by the driver to take back control
208  // @brief Recovery rate for the driver's awareness after a ToC
210  // @brief Average awareness the driver has initially after a ToC
212 
214  double myMRMDecel;
215 
216  // @brief Current awareness-level of the driver in [0,1]
218 
220  std::map<ToCState, RGBColor> myColorScheme;
221 
224 
227 
229 
232 
242 
243 
244 private:
246  MSDevice_ToC(const MSDevice_ToC&);
247 
250 
251 
252 };
253 
254 
255 #endif
256 
257 /****************************************************************************/
258 
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:226
static void insertOptions(OptionsCont &oc)
Inserts MSDevice_ToC-options.
static double getRecoveryRate(const SUMOVehicle &v, const OptionsCont &oc)
SUMOTime MRMExecutionStep(SUMOTime t)
Continue the MRM for one time step.
void descheduleToCPreparation()
Remove ongoing ToC-Preparation process from the event-queue.
static ToCState _2ToCState(const std::string &)
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")
MSDevice_ToC & operator=(const MSDevice_ToC &)
Invalidated assignment operator.
WrappingCommand< MSDevice_ToC > * myExecuteMRMCommand
Definition: MSDevice_ToC.h:239
static double getResponseTime(const SUMOVehicle &v, const OptionsCont &oc)
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:204
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.
WrappingCommand< MSDevice_ToC > * myTriggerMRMCommand
Definition: MSDevice_ToC.h:236
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:223
MSDevice_ToC(SUMOVehicle &holder, const std::string &id, std::string manualType, std::string automatedType, SUMOTime responseTime, double recoveryRate, double initialAwareness, double mrmDecel, bool useColorScheme)
Constructor.
Representation of a vehicle.
Definition: SUMOVehicle.h:60
ToCState
Enum describing the different regimes for the device,.
Definition: MSDevice_ToC.h:84
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:231
SUMOTime myResponseTime
Definition: MSDevice_ToC.h:207
static double getMRMDecel(const SUMOVehicle &v, const OptionsCont &oc)
std::string myManualTypeID
vehicle type ID for manual driving
Definition: MSDevice_ToC.h:202
double myCurrentAwareness
Definition: MSDevice_ToC.h:217
static double getInitialAwareness(const SUMOVehicle &v, const OptionsCont &oc)
SUMOTime ToCPreparationStep(SUMOTime t)
Continue the ToC preparation for one time step.
Abstract in-vehicle device.
Definition: MSDevice.h:65
void setVehicleColor()
A storage for options typed value containers)
Definition: OptionsCont.h:92
static void buildVehicleDevices(SUMOVehicle &v, std::vector< MSDevice *> &into)
Build devices for the given vehicle, if needed.
void setState(ToCState state)
Set the ToC device&#39;s state.
void descheduleToC()
Remove scheduled ToC-Trigger command from the event-queue.
double myRecoveryRate
Definition: MSDevice_ToC.h:209
WrappingCommand< MSDevice_ToC > * myRecoverAwarenessCommand
Definition: MSDevice_ToC.h:238
SUMOTime awarenessRecoveryStep(SUMOTime t)
Continue the awareness recovery for one time step.
~MSDevice_ToC()
Destructor.
WrappingCommand< MSDevice_ToC > * myTriggerToCCommand
Definition: MSDevice_ToC.h:237
const std::string deviceName() const
return the name for this type of device
Definition: MSDevice_ToC.h:113
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 ...
SUMOTime triggerMRM(SUMOTime t)
Trigger execution of an MRM.
WrappingCommand< MSDevice_ToC > * myPrepareToCCommand
Definition: MSDevice_ToC.h:240
std::map< ToCState, RGBColor > myColorScheme
Coloring scheme,.
Definition: MSDevice_ToC.h:220
The ToC Device controls transition of control between automated and manual driving.
Definition: MSDevice_ToC.h:55
double myMRMDecel
Deceleration rate applied during MRM.
Definition: MSDevice_ToC.h:214
double myInitialAwareness
Definition: MSDevice_ToC.h:211
static std::string getAutomatedType(const SUMOVehicle &v, const OptionsCont &oc)