Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
MSDevice_DriverState.cpp
Go to the documentation of this file.
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/****************************************************************************/
24/****************************************************************************/
25#include <config.h>
26
32#include <microsim/MSNet.h>
33#include <microsim/MSVehicle.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// ---------------------------------------------------------------------------
54void
56 oc.addOptionSubTopic("Driver State Device");
57 insertDefaultAssignmentOptions("driverstate", "Driver State Device", oc);
58 oc.doRegister("device.driverstate.initialAwareness", new Option_Float(DriverStateDefaults::initialAwareness));
59 oc.addDescription("device.driverstate.initialAwareness", "Driver State Device", TL("Initial value assigned to the driver's awareness."));
60 oc.doRegister("device.driverstate.errorTimeScaleCoefficient", new Option_Float(DriverStateDefaults::errorTimeScaleCoefficient));
61 oc.addDescription("device.driverstate.errorTimeScaleCoefficient", "Driver State Device", TL("Time scale for the error process."));
62 oc.doRegister("device.driverstate.errorNoiseIntensityCoefficient", new Option_Float(DriverStateDefaults::errorNoiseIntensityCoefficient));
63 oc.addDescription("device.driverstate.errorNoiseIntensityCoefficient", "Driver State Device", TL("Noise intensity driving the error process."));
64 oc.doRegister("device.driverstate.speedDifferenceErrorCoefficient", new Option_Float(DriverStateDefaults::speedDifferenceErrorCoefficient));
65 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 oc.doRegister("device.driverstate.headwayErrorCoefficient", new Option_Float(DriverStateDefaults::headwayErrorCoefficient));
67 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 oc.doRegister("device.driverstate.freeSpeedErrorCoefficient", new Option_Float(DriverStateDefaults::freeSpeedErrorCoefficient));
69 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 oc.doRegister("device.driverstate.speedDifferenceChangePerceptionThreshold", new Option_Float(DriverStateDefaults::speedDifferenceChangePerceptionThreshold));
71 oc.addDescription("device.driverstate.speedDifferenceChangePerceptionThreshold", "Driver State Device", TL("Base threshold for recognizing changes in the speed difference (threshold also scales with distance)."));
72 oc.doRegister("device.driverstate.headwayChangePerceptionThreshold", new Option_Float(DriverStateDefaults::headwayChangePerceptionThreshold));
73 oc.addDescription("device.driverstate.headwayChangePerceptionThreshold", "Driver State Device", TL("Base threshold for recognizing changes in the headway (threshold also scales with distance)."));
74 oc.doRegister("device.driverstate.minAwareness", new Option_Float(DriverStateDefaults::minAwareness));
75 oc.addDescription("device.driverstate.minAwareness", "Driver State Device", TL("Minimal admissible value for the driver's awareness."));
76 oc.doRegister("device.driverstate.maximalReactionTime", new Option_Float(-1.0));
77 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}
79
80
81void
82MSDevice_DriverState::buildVehicleDevices(SUMOVehicle& v, std::vector<MSVehicleDevice*>& into) {
84 // ToC device implies driverstate
85 if (equippedByDefaultAssignmentOptions(oc, "driverstate", v, false) || equippedByDefaultAssignmentOptions(oc, "toc", v, false)) {
86 // build the device
87 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 v.getFloatParam("device.driverstate.maximalReactionTime"));
98 into.push_back(device);
99 }
100}
101
102
103// ---------------------------------------------------------------------------
104// MSDevice_DriverState-methods
105// ---------------------------------------------------------------------------
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 double maximalReactionTime) :
117 MSVehicleDevice(holder, id),
118 myMinAwareness(minAwareness),
119 myInitialAwareness(initialAwareness),
120 myErrorTimeScaleCoefficient(errorTimeScaleCoefficient),
121 myErrorNoiseIntensityCoefficient(errorNoiseIntensityCoefficient),
122 mySpeedDifferenceErrorCoefficient(speedDifferenceErrorCoefficient),
123 mySpeedDifferenceChangePerceptionThreshold(speedDifferenceChangePerceptionThreshold),
124 myHeadwayChangePerceptionThreshold(headwayChangePerceptionThreshold),
125 myHeadwayErrorCoefficient(headwayErrorCoefficient),
126 myFreeSpeedErrorCoefficient(freeSpeedErrorCoefficient),
127 myMaximalReactionTime(maximalReactionTime) {
128 // Take care! Holder is currently being constructed. Cast occurs before completion.
129 myHolderMS = static_cast<MSVehicle*>(&holder);
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}
147
148void
150 myDriverState = std::make_shared<MSSimpleDriverState>(myHolderMS);
151 myDriverState->setMinAwareness(myMinAwareness);
152 myDriverState->setInitialAwareness(myInitialAwareness);
153 myDriverState->setErrorTimeScaleCoefficient(myErrorTimeScaleCoefficient);
154 myDriverState->setErrorNoiseIntensityCoefficient(myErrorNoiseIntensityCoefficient);
155 myDriverState->setSpeedDifferenceErrorCoefficient(mySpeedDifferenceErrorCoefficient);
156 myDriverState->setHeadwayErrorCoefficient(myHeadwayErrorCoefficient);
157 myDriverState->setFreeSpeedErrorCoefficient(myFreeSpeedErrorCoefficient);
158 myDriverState->setSpeedDifferenceChangePerceptionThreshold(mySpeedDifferenceChangePerceptionThreshold);
159 myDriverState->setHeadwayChangePerceptionThreshold(myHeadwayChangePerceptionThreshold);
160 myDriverState->setAwareness(myInitialAwareness);
161 if (myMaximalReactionTime > 0) {
162 myDriverState->setMaximalReactionTime(myMaximalReactionTime);
163 }
164}
165
166void
170
171std::string
172MSDevice_DriverState::getParameter(const std::string& key) const {
173#ifdef DEBUG_DSDEVICE
174 std::cout << "MSDevice_DriverState::getParameter(key=" << key << ")" << std::endl;
175#endif
176 if (key == "awareness") {
177 return toString(myDriverState->getAwareness());
178 } else if (key == "errorState") {
179 return toString(myDriverState->getErrorState());
180 } else if (key == "errorTimeScale") {
181 return toString(myDriverState->getErrorTimeScale());
182 } else if (key == "errorNoiseIntensity") {
183 return toString(myDriverState->getErrorNoiseIntensity());
184 } else if (key == "minAwareness") {
185 return toString(myDriverState->getMinAwareness());
186 } else if (key == "initialAwareness") {
187 return toString(myDriverState->getInitialAwareness());
188 } else if (key == "errorTimeScaleCoefficient") {
189 return toString(myDriverState->getErrorTimeScaleCoefficient());
190 } else if (key == "errorNoiseIntensityCoefficient") {
191 return toString(myDriverState->getErrorNoiseIntensityCoefficient());
192 } else if (key == "speedDifferenceErrorCoefficient") {
193 return toString(myDriverState->getSpeedDifferenceErrorCoefficient());
194 } else if (key == "headwayErrorCoefficient") {
195 return toString(myDriverState->getHeadwayErrorCoefficient());
196 } else if (key == "speedDifferenceChangePerceptionThreshold") {
197 return toString(myDriverState->getSpeedDifferenceChangePerceptionThreshold());
198 } else if (key == "headwayChangePerceptionThreshold") {
199 return toString(myDriverState->getHeadwayChangePerceptionThreshold());
200 } else if (key == "maximalReactionTime") {
201 return toString(myDriverState->getMaximalReactionTime());
202 } else if (key == "originalReactionTime") {
203 return toString(myDriverState->getOriginalReactionTime());
204 } else if (key == "actionStepLength") {
205 return toString(myDriverState->getActionStepLength());
206 }
207 throw InvalidArgument("Parameter '" + key + "' is not supported for device of type '" + deviceName() + "'");
208}
209
210
211void
212MSDevice_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 if (key == "awareness") {
217 myDriverState->setAwareness(StringUtils::toDouble(value));
218 } else if (key == "errorState") {
219 myDriverState->setErrorState(StringUtils::toDouble(value));
220 } else if (key == "errorTimeScale") {
221 myDriverState->setErrorTimeScale(StringUtils::toDouble(value));
222 } else if (key == "errorNoiseIntensity") {
223 myDriverState->setErrorNoiseIntensity(StringUtils::toDouble(value));
224 } else if (key == "minAwareness") {
225 myDriverState->setMinAwareness(StringUtils::toDouble(value));
226 } else if (key == "initialAwareness") {
227 myDriverState->setInitialAwareness(StringUtils::toDouble(value));
228 } else if (key == "errorTimeScaleCoefficient") {
229 myDriverState->setErrorTimeScaleCoefficient(StringUtils::toDouble(value));
230 } else if (key == "errorNoiseIntensityCoefficient") {
231 myDriverState->setErrorNoiseIntensityCoefficient(StringUtils::toDouble(value));
232 } else if (key == "speedDifferenceErrorCoefficient") {
233 myDriverState->setSpeedDifferenceErrorCoefficient(StringUtils::toDouble(value));
234 } else if (key == "headwayErrorCoefficient") {
235 myDriverState->setHeadwayErrorCoefficient(StringUtils::toDouble(value));
236 } else if (key == "freeSpeedErrorCoefficient") {
237 myDriverState->setFreeSpeedErrorCoefficient(StringUtils::toDouble(value));
238 } else if (key == "speedDifferenceChangePerceptionThreshold") {
239 myDriverState->setSpeedDifferenceChangePerceptionThreshold(StringUtils::toDouble(value));
240 } else if (key == "headwayChangePerceptionThreshold") {
241 myDriverState->setHeadwayChangePerceptionThreshold(StringUtils::toDouble(value));
242 } else if (key == "maximalReactionTime") {
243 myDriverState->setMaximalReactionTime(StringUtils::toDouble(value));
244 } else if (key == "originalReactionTime") {
245 myDriverState->setOriginalReactionTime(StringUtils::toDouble(value));
246 } else {
247 throw InvalidArgument("Parameter '" + key + "' is not supported for device of type '" + deviceName() + "'");
248 }
249}
250
251
252/****************************************************************************/
#define TL(string)
Definition MsgHandler.h:315
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition ToString.h:46
The ToC Device controls transition of control between automated and manual driving.
static void buildVehicleDevices(SUMOVehicle &v, std::vector< MSVehicleDevice * > &into)
Build devices for the given vehicle, if needed.
MSVehicle * myHolderMS
The holder vehicle casted to MSVehicle*.
static void insertOptions(OptionsCont &oc)
Inserts MSDevice_DriverState-options.
MSDevice_DriverState(SUMOVehicle &holder, const std::string &id, double minAwareness, double initialAwareness, double errorTimeScaleCoefficient, double errorNoiseIntensityCoefficient, double speedDifferenceErrorCoefficient, double speedDifferenceChangePerceptionThreshold, double headwayChangePerceptionThreshold, double headwayErrorCoefficient, double freeSpeedErrorCoefficient, double maximalReactionTime)
Constructor.
void setParameter(const std::string &key, const std::string &value)
try to set the given parameter for this device. Throw exception for unsupported key
const std::string deviceName() const
return the name for this type of device
void initDriverState()
Initialises the driver state parameters.
double mySpeedDifferenceChangePerceptionThreshold
std::shared_ptr< MSSimpleDriverState > myDriverState
The driver state of the holder.
std::string getParameter(const std::string &key) const
try to retrieve the given parameter from this device. Throw exception for unsupported key
void update()
update internal state
static void insertDefaultAssignmentOptions(const std::string &deviceName, const std::string &optionsTopic, OptionsCont &oc, const bool isPerson=false)
Adds common command options that allow to assign devices to vehicles.
Definition MSDevice.cpp:155
static bool equippedByDefaultAssignmentOptions(const OptionsCont &oc, const std::string &deviceName, DEVICEHOLDER &v, bool outputOptionSet, const bool isPerson=false)
Determines whether a vehicle should get a certain device.
Definition MSDevice.h:195
Abstract in-vehicle device.
Representation of a vehicle in the micro simulation.
Definition MSVehicle.h:77
const std::string & getID() const
Returns the id.
Definition Named.h:74
A storage for options typed value containers)
Definition OptionsCont.h:89
void addDescription(const std::string &name, const std::string &subtopic, const std::string &description)
Adds a description for an option.
void doRegister(const std::string &name, Option *o)
Adds an option under the given name.
void addOptionSubTopic(const std::string &topic)
Adds an option subtopic.
static OptionsCont & getOptions()
Retrieves the options.
double getFloatParam(const std::string &paramName, const bool required=false, const double deflt=INVALID_DOUBLE) const
Retrieve a floating point parameter for the traffic object.
Representation of a vehicle.
Definition SUMOVehicle.h:62
static double toDouble(const std::string &sData)
converts a string into the double value described by it by calling the char-type converter
static double speedDifferenceChangePerceptionThreshold
static double headwayChangePerceptionThreshold
static double initialAwareness
static double minAwareness
static double freeSpeedErrorCoefficient
static double headwayErrorCoefficient
static double errorTimeScaleCoefficient
static double errorNoiseIntensityCoefficient
static double speedDifferenceErrorCoefficient