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