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.cpp
15 : /// @author Leonhard Luecken
16 : /// @author Daniel Krajzewicz
17 : /// @author Michael Behrisch
18 : /// @author Jakob Erdmann
19 : /// @date 15.06.2018
20 : ///
21 : /// The Driver State Device mainly provides a configuration and interaction interface for the vehicle's driver state.
22 : /// @see microsim/MSDriverState.h
23 : ///
24 : /****************************************************************************/
25 : #include <config.h>
26 :
27 : #include <utils/common/StringUtils.h>
28 : #include <utils/options/OptionsCont.h>
29 : #include <utils/vehicle/SUMOVehicle.h>
30 : #include <utils/common/WrappingCommand.h>
31 : #include <utils/common/RGBColor.h>
32 : #include <microsim/MSNet.h>
33 : #include <microsim/MSVehicle.h>
34 : #include <microsim/MSRouteHandler.h>
35 : #include <microsim/MSVehicleControl.h>
36 : #include <microsim/MSEventControl.h>
37 : #include <microsim/MSDriverState.h>
38 : #include "MSDevice_DriverState.h"
39 :
40 :
41 : // ===========================================================================
42 : // debug constants
43 : // ===========================================================================
44 : //#define DEBUG_DSDEVICE
45 : //#define DEBUG_COND (myHolder.isSelected())
46 :
47 :
48 : // ===========================================================================
49 : // method definitions
50 : // ===========================================================================
51 : // ---------------------------------------------------------------------------
52 : // static initialisation methods
53 : // ---------------------------------------------------------------------------
54 : void
55 43644 : MSDevice_DriverState::insertOptions(OptionsCont& oc) {
56 43644 : oc.addOptionSubTopic("Driver State Device");
57 87288 : insertDefaultAssignmentOptions("driverstate", "Driver State Device", oc);
58 43644 : oc.doRegister("device.driverstate.initialAwareness", new Option_Float(DriverStateDefaults::initialAwareness));
59 87288 : oc.addDescription("device.driverstate.initialAwareness", "Driver State Device", TL("Initial value assigned to the driver's awareness."));
60 43644 : oc.doRegister("device.driverstate.errorTimeScaleCoefficient", new Option_Float(DriverStateDefaults::errorTimeScaleCoefficient));
61 87288 : oc.addDescription("device.driverstate.errorTimeScaleCoefficient", "Driver State Device", TL("Time scale for the error process."));
62 43644 : oc.doRegister("device.driverstate.errorNoiseIntensityCoefficient", new Option_Float(DriverStateDefaults::errorNoiseIntensityCoefficient));
63 87288 : oc.addDescription("device.driverstate.errorNoiseIntensityCoefficient", "Driver State Device", TL("Noise intensity driving the error process."));
64 43644 : oc.doRegister("device.driverstate.speedDifferenceErrorCoefficient", new Option_Float(DriverStateDefaults::speedDifferenceErrorCoefficient));
65 87288 : oc.addDescription("device.driverstate.speedDifferenceErrorCoefficient", "Driver State Device", TL("General scaling coefficient for applying the error to the perceived speed difference (error also scales with distance)."));
66 43644 : oc.doRegister("device.driverstate.headwayErrorCoefficient", new Option_Float(DriverStateDefaults::headwayErrorCoefficient));
67 87288 : oc.addDescription("device.driverstate.headwayErrorCoefficient", "Driver State Device", TL("General scaling coefficient for applying the error to the perceived distance (error also scales with distance)."));
68 43644 : oc.doRegister("device.driverstate.freeSpeedErrorCoefficient", new Option_Float(DriverStateDefaults::freeSpeedErrorCoefficient));
69 87288 : oc.addDescription("device.driverstate.freeSpeedErrorCoefficient", "Driver State Device", TL("General scaling coefficient for applying the error to the vehicle's own speed when driving without a leader (error also scales with own speed)."));
70 43644 : oc.doRegister("device.driverstate.speedDifferenceChangePerceptionThreshold", new Option_Float(DriverStateDefaults::speedDifferenceChangePerceptionThreshold));
71 87288 : oc.addDescription("device.driverstate.speedDifferenceChangePerceptionThreshold", "Driver State Device", TL("Base threshold for recognizing changes in the speed difference (threshold also scales with distance)."));
72 43644 : oc.doRegister("device.driverstate.headwayChangePerceptionThreshold", new Option_Float(DriverStateDefaults::headwayChangePerceptionThreshold));
73 87288 : oc.addDescription("device.driverstate.headwayChangePerceptionThreshold", "Driver State Device", TL("Base threshold for recognizing changes in the headway (threshold also scales with distance)."));
74 43644 : oc.doRegister("device.driverstate.minAwareness", new Option_Float(DriverStateDefaults::minAwareness));
75 87288 : oc.addDescription("device.driverstate.minAwareness", "Driver State Device", TL("Minimal admissible value for the driver's awareness."));
76 43644 : oc.doRegister("device.driverstate.maximalReactionTime", new Option_Float(-1.0));
77 87288 : oc.addDescription("device.driverstate.maximalReactionTime", "Driver State Device", TL("Maximal reaction time (~action step length) induced by decreased awareness level (reached for awareness=minAwareness)."));
78 43644 : }
79 :
80 :
81 : void
82 5104369 : MSDevice_DriverState::buildVehicleDevices(SUMOVehicle& v, std::vector<MSVehicleDevice*>& into) {
83 5104369 : OptionsCont& oc = OptionsCont::getOptions();
84 : // ToC device implies driverstate
85 10208584 : if (equippedByDefaultAssignmentOptions(oc, "driverstate", v, false) || equippedByDefaultAssignmentOptions(oc, "toc", v, false)) {
86 : // build the device
87 388 : MSDevice_DriverState* device = new MSDevice_DriverState(v, "driverstate" + v.getID(),
88 : v.getFloatParam("device.driverstate.minAwareness"),
89 : v.getFloatParam("device.driverstate.initialAwareness"),
90 : v.getFloatParam("device.driverstate.errorTimeScaleCoefficient"),
91 : v.getFloatParam("device.driverstate.errorNoiseIntensityCoefficient"),
92 : v.getFloatParam("device.driverstate.speedDifferenceErrorCoefficient"),
93 : v.getFloatParam("device.driverstate.speedDifferenceChangePerceptionThreshold"),
94 : v.getFloatParam("device.driverstate.headwayChangePerceptionThreshold"),
95 : v.getFloatParam("device.driverstate.headwayErrorCoefficient"),
96 : v.getFloatParam("device.driverstate.freeSpeedErrorCoefficient"),
97 582 : v.getFloatParam("device.driverstate.maximalReactionTime"));
98 194 : into.push_back(device);
99 : }
100 5104369 : }
101 :
102 :
103 : // ---------------------------------------------------------------------------
104 : // MSDevice_DriverState-methods
105 : // ---------------------------------------------------------------------------
106 194 : MSDevice_DriverState::MSDevice_DriverState(SUMOVehicle& holder, const std::string& id,
107 : double minAwareness,
108 : double initialAwareness,
109 : double errorTimeScaleCoefficient,
110 : double errorNoiseIntensityCoefficient,
111 : double speedDifferenceErrorCoefficient,
112 : double speedDifferenceChangePerceptionThreshold,
113 : double headwayChangePerceptionThreshold,
114 : double headwayErrorCoefficient,
115 : double freeSpeedErrorCoefficient,
116 194 : double maximalReactionTime) :
117 : MSVehicleDevice(holder, id),
118 194 : myMinAwareness(minAwareness),
119 194 : myInitialAwareness(initialAwareness),
120 194 : myErrorTimeScaleCoefficient(errorTimeScaleCoefficient),
121 194 : myErrorNoiseIntensityCoefficient(errorNoiseIntensityCoefficient),
122 194 : mySpeedDifferenceErrorCoefficient(speedDifferenceErrorCoefficient),
123 194 : mySpeedDifferenceChangePerceptionThreshold(speedDifferenceChangePerceptionThreshold),
124 194 : myHeadwayChangePerceptionThreshold(headwayChangePerceptionThreshold),
125 194 : myHeadwayErrorCoefficient(headwayErrorCoefficient),
126 194 : myFreeSpeedErrorCoefficient(freeSpeedErrorCoefficient),
127 194 : myMaximalReactionTime(maximalReactionTime) {
128 : // Take care! Holder is currently being constructed. Cast occurs before completion.
129 194 : myHolderMS = static_cast<MSVehicle*>(&holder);
130 194 : initDriverState();
131 :
132 :
133 : #ifdef DEBUG_DSDEVICE
134 : std::cout << "initialized device '" << id << "' with "
135 : << "myMinAwareness=" << myMinAwareness << ", "
136 : << "myInitialAwareness=" << myInitialAwareness << ", "
137 : << "myErrorTimeScaleCoefficient=" << myErrorTimeScaleCoefficient << ", "
138 : << "myErrorNoiseIntensityCoefficient=" << myErrorNoiseIntensityCoefficient << ", "
139 : << "mySpeedDifferenceErrorCoefficient=" << mySpeedDifferenceErrorCoefficient << ", "
140 : << "mySpeedDifferenceChangePerceptionThreshold=" << mySpeedDifferenceChangePerceptionThreshold << ", "
141 : << "myHeadwayChangePerceptionThreshold=" << myHeadwayChangePerceptionThreshold << ", "
142 : << "myHeadwayErrorCoefficient=" << myHeadwayErrorCoefficient << std::endl;
143 : << "myFreeSpeedErrorCoefficient=" << myFreeSpeedErrorCoefficient << std::endl;
144 : #endif
145 :
146 194 : }
147 :
148 : void
149 194 : MSDevice_DriverState::initDriverState() {
150 388 : myDriverState = std::make_shared<MSSimpleDriverState>(myHolderMS);
151 194 : myDriverState->setMinAwareness(myMinAwareness);
152 194 : myDriverState->setInitialAwareness(myInitialAwareness);
153 194 : myDriverState->setErrorTimeScaleCoefficient(myErrorTimeScaleCoefficient);
154 194 : myDriverState->setErrorNoiseIntensityCoefficient(myErrorNoiseIntensityCoefficient);
155 194 : myDriverState->setSpeedDifferenceErrorCoefficient(mySpeedDifferenceErrorCoefficient);
156 194 : myDriverState->setHeadwayErrorCoefficient(myHeadwayErrorCoefficient);
157 194 : myDriverState->setFreeSpeedErrorCoefficient(myFreeSpeedErrorCoefficient);
158 194 : myDriverState->setSpeedDifferenceChangePerceptionThreshold(mySpeedDifferenceChangePerceptionThreshold);
159 194 : myDriverState->setHeadwayChangePerceptionThreshold(myHeadwayChangePerceptionThreshold);
160 194 : myDriverState->setAwareness(myInitialAwareness);
161 194 : if (myMaximalReactionTime > 0) {
162 : myDriverState->setMaximalReactionTime(myMaximalReactionTime);
163 : }
164 194 : }
165 :
166 : void
167 256641 : MSDevice_DriverState::update() {
168 256641 : myDriverState->update();
169 256641 : }
170 :
171 : std::string
172 302 : MSDevice_DriverState::getParameter(const std::string& key) const {
173 : #ifdef DEBUG_DSDEVICE
174 : std::cout << "MSDevice_DriverState::getParameter(key=" << key << ")" << std::endl;
175 : #endif
176 302 : if (key == "awareness") {
177 126 : return toString(myDriverState->getAwareness());
178 176 : } else if (key == "errorState") {
179 126 : return toString(myDriverState->getErrorState());
180 50 : } else if (key == "errorTimeScale") {
181 4 : return toString(myDriverState->getErrorTimeScale());
182 46 : } else if (key == "errorNoiseIntensity") {
183 4 : return toString(myDriverState->getErrorNoiseIntensity());
184 42 : } else if (key == "minAwareness") {
185 4 : return toString(myDriverState->getMinAwareness());
186 38 : } else if (key == "initialAwareness") {
187 4 : return toString(myDriverState->getInitialAwareness());
188 34 : } else if (key == "errorTimeScaleCoefficient") {
189 4 : return toString(myDriverState->getErrorTimeScaleCoefficient());
190 30 : } else if (key == "errorNoiseIntensityCoefficient") {
191 4 : return toString(myDriverState->getErrorNoiseIntensityCoefficient());
192 26 : } else if (key == "speedDifferenceErrorCoefficient") {
193 4 : return toString(myDriverState->getSpeedDifferenceErrorCoefficient());
194 22 : } else if (key == "headwayErrorCoefficient") {
195 4 : return toString(myDriverState->getHeadwayErrorCoefficient());
196 18 : } else if (key == "speedDifferenceChangePerceptionThreshold") {
197 4 : return toString(myDriverState->getSpeedDifferenceChangePerceptionThreshold());
198 14 : } else if (key == "headwayChangePerceptionThreshold") {
199 4 : return toString(myDriverState->getHeadwayChangePerceptionThreshold());
200 10 : } else if (key == "maximalReactionTime") {
201 3 : return toString(myDriverState->getMaximalReactionTime());
202 7 : } else if (key == "originalReactionTime") {
203 3 : return toString(myDriverState->getOriginalReactionTime());
204 4 : } else if (key == "actionStepLength") {
205 4 : return toString(myDriverState->getActionStepLength());
206 : }
207 0 : throw InvalidArgument("Parameter '" + key + "' is not supported for device of type '" + deviceName() + "'");
208 : }
209 :
210 :
211 : void
212 14 : MSDevice_DriverState::setParameter(const std::string& key, const std::string& value) {
213 : #ifdef DEBUG_DSDEVICE
214 : std::cout << "MSDevice_DriverState::setParameter(key=" << key << ", value=" << value << ")" << std::endl;
215 : #endif
216 14 : if (key == "awareness") {
217 1 : myDriverState->setAwareness(StringUtils::toDouble(value));
218 13 : } else if (key == "errorState") {
219 1 : myDriverState->setErrorState(StringUtils::toDouble(value));
220 12 : } else if (key == "errorTimeScale") {
221 1 : myDriverState->setErrorTimeScale(StringUtils::toDouble(value));
222 11 : } else if (key == "errorNoiseIntensity") {
223 1 : myDriverState->setErrorNoiseIntensity(StringUtils::toDouble(value));
224 10 : } else if (key == "minAwareness") {
225 1 : myDriverState->setMinAwareness(StringUtils::toDouble(value));
226 9 : } else if (key == "initialAwareness") {
227 1 : myDriverState->setInitialAwareness(StringUtils::toDouble(value));
228 8 : } else if (key == "errorTimeScaleCoefficient") {
229 1 : myDriverState->setErrorTimeScaleCoefficient(StringUtils::toDouble(value));
230 7 : } else if (key == "errorNoiseIntensityCoefficient") {
231 1 : myDriverState->setErrorNoiseIntensityCoefficient(StringUtils::toDouble(value));
232 6 : } else if (key == "speedDifferenceErrorCoefficient") {
233 1 : myDriverState->setSpeedDifferenceErrorCoefficient(StringUtils::toDouble(value));
234 5 : } else if (key == "headwayErrorCoefficient") {
235 1 : myDriverState->setHeadwayErrorCoefficient(StringUtils::toDouble(value));
236 4 : } else if (key == "freeSpeedErrorCoefficient") {
237 0 : myDriverState->setFreeSpeedErrorCoefficient(StringUtils::toDouble(value));
238 4 : } else if (key == "speedDifferenceChangePerceptionThreshold") {
239 1 : myDriverState->setSpeedDifferenceChangePerceptionThreshold(StringUtils::toDouble(value));
240 3 : } else if (key == "headwayChangePerceptionThreshold") {
241 1 : myDriverState->setHeadwayChangePerceptionThreshold(StringUtils::toDouble(value));
242 2 : } else if (key == "maximalReactionTime") {
243 1 : myDriverState->setMaximalReactionTime(StringUtils::toDouble(value));
244 1 : } else if (key == "originalReactionTime") {
245 1 : myDriverState->setOriginalReactionTime(StringUtils::toDouble(value));
246 : } else {
247 0 : throw InvalidArgument("Parameter '" + key + "' is not supported for device of type '" + deviceName() + "'");
248 : }
249 14 : }
250 :
251 :
252 : /****************************************************************************/
|