1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2013-2019 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 /****************************************************************************/
10 /// @file    MSDevice_DriverState.h
11 /// @author  Leonhard Luecken
12 /// @author  Daniel Krajzewicz
13 /// @author  Jakob Erdmann
14 /// @date    15.06.2018
15 /// @version $Id$
16 ///
17 /// The Driver State Device mainly provides a configuration and interaction interface for the vehicle's driver state.
18 /// @see microsim/MSDriverState.h
19 ///
20 /****************************************************************************/
21 #ifndef MSDevice_DriverState_h
22 #define MSDevice_DriverState_h
23 
24 
25 // ===========================================================================
26 // included modules
27 // ===========================================================================
28 #include <config.h>
29 
30 #include "MSVehicleDevice.h"
31 #include <utils/common/SUMOTime.h>
32 #include <utils/common/WrappingCommand.h>
33 
34 
35 // ===========================================================================
36 // class declarations
37 // ===========================================================================
38 class SUMOVehicle;
39 class MSVehicle;
40 class MSSimpleDriverState;
41 
42 
43 // ===========================================================================
44 // class definitions
45 // ===========================================================================
46 /**
47  * @class MSDevice_DriverState
48  *
49  * @brief The ToC Device controls transition of control between automated and manual driving.
50  * @todo: Provide logging facilities
51  * @todo: allow manual and automated type to refer to vTypeDistributions
52  *
53  * @see MSDevice
54  */
55 class MSDevice_DriverState : public MSVehicleDevice {
56 public:
57     /** @brief Inserts MSDevice_DriverState-options
58      * @param[filled] oc The options container to add the options to
59      */
60     static void insertOptions(OptionsCont& oc);
61 
62 
63     /** @brief Build devices for the given vehicle, if needed
64      *
65      * The options are read and evaluated whether a ToC-device shall be built
66      *  for the given vehicle.
67      *
68      * The built device is stored in the given vector.
69      *
70      * @param[in] v The vehicle for which a device may be built
71      * @param[filled] into The vector to store the built device in
72      */
73     static void buildVehicleDevices(SUMOVehicle& v, std::vector<MSVehicleDevice*>& into);
74 
75     /// update internal state
76     void update();
77 
78     /// return internal state
getDriverState()79     inline std::shared_ptr<MSSimpleDriverState> getDriverState() const {
80         return myDriverState;
81     }
82 
83 private:
84     /// @name Helpers for parameter parsing
85     /// @{
86     static double getMinAwareness(const SUMOVehicle& v, const OptionsCont& oc);
87     static double getInitialAwareness(const SUMOVehicle& v, const OptionsCont& oc);
88     static double getErrorTimeScaleCoefficient(const SUMOVehicle& v, const OptionsCont& oc);
89     static double getErrorNoiseIntensityCoefficient(const SUMOVehicle& v, const OptionsCont& oc);
90     static double getSpeedDifferenceErrorCoefficient(const SUMOVehicle& v, const OptionsCont& oc);
91     static double getSpeedDifferenceChangePerceptionThreshold(const SUMOVehicle& v, const OptionsCont& oc);
92     static double getHeadwayChangePerceptionThreshold(const SUMOVehicle& v, const OptionsCont& oc);
93     static double getHeadwayErrorCoefficient(const SUMOVehicle& v, const OptionsCont& oc);
94     static double getMaximalReactionTime(const SUMOVehicle& v, const OptionsCont& oc);
95     /// @}
96 
97 
98 public:
99     /// @brief Destructor.
~MSDevice_DriverState()100     ~MSDevice_DriverState() {};
101 
102     /// @brief return the name for this type of device
deviceName()103     const std::string deviceName() const {
104         return "driverstate";
105     }
106 
107     /// @brief try to retrieve the given parameter from this device. Throw exception for unsupported key
108     std::string getParameter(const std::string& key) const;
109 
110     /// @brief try to set the given parameter for this device. Throw exception for unsupported key
111     void setParameter(const std::string& key, const std::string& value);
112 
113 
114 private:
115     /** @brief Constructor
116      *
117      * @param[in] holder The vehicle that holds this device
118      * @param[in] id The ID of the device
119      */
120     MSDevice_DriverState(SUMOVehicle& holder, const std::string& id,
121                          double minAwareness,
122                          double initialAwareness,
123                          double errorTimeScaleCoefficient,
124                          double errorNoiseIntensityCoefficient,
125                          double speedDifferenceErrorCoefficient,
126                          double speedDifferenceChangePerceptionThreshold,
127                          double headwayChangePerceptionThreshold,
128                          double headwayErrorCoefficient,
129                          double maximalReactionTime);
130 
131     /// @brief Initializeses the driver state parameters
132     void initDriverState();
133 
134 private:
135     /// @brief The holder vehicle casted to MSVehicle*
136     MSVehicle* myHolderMS;
137 
138     /// @name Temporary to hold driverstate parameters until initialization.
139     /// @note Invalid after call to initDriverState().
140     /// @{
141     double myMinAwareness;
142     double myInitialAwareness;
143     double myErrorTimeScaleCoefficient;
144     double myErrorNoiseIntensityCoefficient;
145     double mySpeedDifferenceErrorCoefficient;
146     double mySpeedDifferenceChangePerceptionThreshold;
147     double myHeadwayChangePerceptionThreshold;
148     double myHeadwayErrorCoefficient;
149     double myMaximalReactionTime;
150     /// @}
151 
152     /// @brief The driver state of the holder.
153     std::shared_ptr<MSSimpleDriverState> myDriverState;
154 
155 private:
156     /// @brief Invalidated copy constructor.
157     MSDevice_DriverState(const MSDevice_DriverState&);
158 
159     /// @brief Invalidated assignment operator.
160     MSDevice_DriverState& operator=(const MSDevice_DriverState&);
161 
162 };
163 
164 
165 #endif
166 
167 /****************************************************************************/
168 
169