Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
MSDevice_ToC.h
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/****************************************************************************/
20// The ToC Device controls the transition of control between automated and manual driving.
21//
22/****************************************************************************/
23#pragma once
24#include <config.h>
25
26#include <random>
27#include <queue>
28#include "MSVehicleDevice.h"
31
32
33// ===========================================================================
34// class declarations
35// ===========================================================================
36class SUMOVehicle;
37class MSVehicle;
38class Command_ToCTrigger;
39class Command_ToCProcess;
40class RGBColor;
41
42// ===========================================================================
43// class definitions
44// ===========================================================================
53private:
54 // All currently existing ToC device instances
55 static std::set<MSDevice_ToC*, ComparatorNumericalIdLess> myInstances;
56 // All files, that receive ToC output (TODO: check if required)
57 static std::set<std::string> createdOutputFiles;
58
62 double changeRate;
63 double maxDecel;
64 bool active;
65 OpenGapParams(double timegap, double spacing, double changeRate, double maxDecel, bool active) :
67 {};
68 };
69
70public:
74 static void insertOptions(OptionsCont& oc);
75
76
87 static void buildVehicleDevices(SUMOVehicle& v, std::vector<MSVehicleDevice*>& into);
88
91 static const std::set<MSDevice_ToC*, ComparatorNumericalIdLess>& getInstances() {
92 return myInstances;
93 };
94
97 static void cleanup();
98
99private:
100
108 enum ToCState {
112 PREPARING_TOC = 3, // this applies only to the transition AUTOMATED -> MANUAL !
113 MRM = 4,
114 RECOVERING = 5
115 };
116
119 static double getDynamicMRMProbability(const SUMOVehicle& v);
120 static OpenGapParams getOpenGapParams(const SUMOVehicle& v);
121
122 static ToCState _2ToCState(const std::string&);
123 static std::string _2string(ToCState state);
125
126
127public:
130
132 const std::string deviceName() const override {
133 return "toc";
134 }
135
138 double oldPos,
139 double newPos,
140 double newSpeed) override;
141
143 std::string getParameter(const std::string& key) const override;
144
146 void setParameter(const std::string& key, const std::string& value) override;
147
148
151
154
157
160
163
166
168 void writeOutput();
169
172 return myOutputFile != nullptr;
173 }
174
176 return &myResponseTimeRNG;
177 }
178private:
196 MSDevice_ToC(SUMOVehicle& holder, const std::string& id, const std::string& outputFilename,
197 const std::string& manualType, const std::string& automatedType, SUMOTime responseTime, double recoveryRate,
198 double lcAbstinence, double initialAwareness, double mrmDecel,
199 double dynamicToCThreshold, double dynamicMRMProbability, double maxPreparationAccel,
200 bool mrmKeepRight, const std::string& mrmSafeSpot, SUMOTime mrmSafeSpotDuration, bool useColorScheme, OpenGapParams ogp);
201
206 void initColorScheme();
207
209 void setAwareness(double value);
210
212 void setState(ToCState state);
213
214 // @brief Sets the device holder's color corresponding to the current state
215 void setVehicleColor();
216
226 void requestToC(SUMOTime timeTillMRM, SUMOTime responseTime = -1000);
227
230 void requestMRM();
231
233 void switchHolderType(const std::string& targetTypeID);
234
236 void descheduleMRM();
238 void descheduleToC();
242 void descheduleRecovery();
243
245 void resetDeliberateLCs();
248
250 bool isManuallyDriven();
252 bool isAutomated();
253
257 bool checkDynamicToC();
258
259private:
262
264 std::string myManualTypeID;
266 std::string myAutomatedTypeID;
267
268
277
280
283
285 std::map<ToCState, RGBColor> myColorScheme;
286
289
292
294
297
307
310
312 std::queue<std::pair<SUMOTime, std::string> > myEvents;
313
315 std::queue<std::pair<std::string, double> > myEventLanes;
316
318 std::queue<std::pair<double, double>> myEventXY;
319
322
324 static int LCModeMRM;
325
328
333 // (Note that these MRMs will not induce full stops in most cases)
341
344
346 std::string myMRMSafeSpot;
347
350
354
357
359 static std::vector<double> lookupResponseTimeMRMProbs;
360 static std::vector<double> lookupResponseTimeLeadTimes;
362 static double responseTimeMean(double leadTime) {
363 return MIN2(2 * sqrt(leadTime), 0.7 * leadTime);
364 };
368 static std::vector<std::vector<double> > lookupResponseTimeVariances;
369
372
375 double sampleResponseTime(double leadTime) const;
376
379 static double interpolateVariance(double leadTime, double pMRM);
380
381private:
384
387
388
389};
long long int SUMOTime
Definition GUI.h:36
T MIN2(T a, T b)
Definition StdDefs.h:76
The ToC Device controls transition of control between automated and manual driving.
SUMOTime MRMExecutionStep(SUMOTime t)
Continue the MRM for one time step.
std::string myAutomatedTypeID
vehicle type ID for automated driving
void requestMRM()
Request an MRM to be initiated immediately. No downward ToC will be scheduled.
static double getDynamicMRMProbability(const SUMOVehicle &v)
std::string myManualTypeID
vehicle type ID for manual driving
static void cleanup()
Closes root tags of output files.
double myRecoveryRate
Recovery rate for the driver's awareness after a ToC.
bool myDynamicToCActive
Switch for considering dynamic ToCs,.
double myMRMDecel
Deceleration rate applied during MRM.
WrappingCommand< MSDevice_ToC > * myTriggerToCCommand
static double interpolateVariance(double leadTime, double pMRM)
Two-dimensional interpolation of variance from lookup table assumes pMRM >= 0, leadTime >= 0.
static int LCModeMRM
LC mode operational during an MRM.
double myInitialAwareness
Average awareness the driver has initially after a ToC.
bool myUseColorScheme
Whether a coloring scheme shall by applied to indicate the different toc stages,.
OpenGapParams myOpenGapParams
Parameters for the openGap mechanism applied during ToC preparation phase.
static std::vector< std::vector< double > > lookupResponseTimeVariances
Variances of the response time distribution. Given the lead time and the MRM probability the variance...
bool notifyMove(SUMOTrafficObject &veh, double oldPos, double newPos, double newSpeed) override
Return value indicates whether the device still wants to be notified about the vehicle movement.
SUMOTime myMRMSafeSpotDuration
duration at stop vehicle tries to reach during MRM
void resetDeliberateLCs()
Resets the holder's LC mode to the last differing to LCModeMRM.
double myOriginalMaxAccel
Storage for original maximal acceleration of vehicle.
MSDevice_ToC & operator=(const MSDevice_ToC &)
Invalidated assignment operator.
const std::string deviceName() const override
return the name for this type of device
static std::vector< double > lookupResponseTimeLeadTimes
WrappingCommand< MSDevice_ToC > * myExecuteMRMCommand
static std::set< std::string > createdOutputFiles
SUMOTime ToCPreparationStep(SUMOTime t)
Continue the ToC preparation for one time step.
~MSDevice_ToC()
Destructor.
bool myIssuedDynamicToC
Flag to indicate that a dynamically triggered ToC is in preparation.
double myMRMProbability
Probability of an MRM to occur after a dynamically triggered ToC.
static std::set< MSDevice_ToC *, ComparatorNumericalIdLess > myInstances
void descheduleRecovery()
Remove ongoing awareness recovery process from the event-queue.
int myPreviousLCMode
LC mode overridden during MRM, stored for restoration.
void requestToC(SUMOTime timeTillMRM, SUMOTime responseTime=-1000)
Request a ToC. If the device is in AUTOMATED or MRM state, a driver response time is sampled and the ...
double sampleResponseTime(double leadTime) const
Samples a random driver response time from a truncated Gaussian with parameters according to the look...
std::queue< std::pair< std::string, double > > myEventLanes
Storage for events to be written to the output.
static void insertOptions(OptionsCont &oc)
Inserts MSDevice_ToC-options.
bool myMRMKeepRight
Whether vehicle tries to change to the right during an MRM.
bool isManuallyDriven()
Whether the current operation mode is manual.
static void buildVehicleDevices(SUMOVehicle &v, std::vector< MSVehicleDevice * > &into)
Build devices for the given vehicle, if needed.
void setVehicleColor()
ToCState myState
Current state of the device.
double myMaxPreparationAccel
Maximal acceleration that may be applied during the ToC preparation phase TODO: Make effective.
static ToCState _2ToCState(const std::string &)
int myDynamicToCLane
Lane, on which the ongoing dynamic ToC was issued. It can only be aborted if the lane was changed.
bool isAutomated()
Whether the current operation mode is automated.
std::map< ToCState, RGBColor > myColorScheme
Coloring scheme,.
static std::string _2string(ToCState state)
static SumoRNG myResponseTimeRNG
Random generator for ToC devices.
void setState(ToCState state)
Set the ToC device's state.
SUMOTime myResponseTime
Average response time needed by the driver to take back control.
void setParameter(const std::string &key, const std::string &value) override
try to set the given parameter for this device. Throw exception for unsupported key
bool generatesOutput()
Whether this device requested to write output.
double myLCAbstinence
Level of the awareness below which no lane-changes are performed.
SUMOTime triggerDownwardToC(SUMOTime t)
Trigger execution of a ToC X-->MANUAL ("downwards")
static SumoRNG * getResponseTimeRNG()
void initColorScheme()
Initialize vehicle colors for different states.
MSVehicle * myHolderMS
The holder vehicle casted to MSVehicle*.
WrappingCommand< MSDevice_ToC > * myPrepareToCCommand
std::string getParameter(const std::string &key) const override
try to retrieve the given parameter from this device. Throw exception for unsupported key
void descheduleMRM()
Break MRM Process or remove MRM-Trigger command from the event-queue.
static double responseTimeMean(double leadTime)
Mean of the response time distribution. (Only depends on given lead time)
void descheduleToC()
Remove scheduled ToC-Trigger command from the event-queue.
static const std::set< MSDevice_ToC *, ComparatorNumericalIdLess > & getInstances()
returns all currently existing ToC devices
void descheduleToCPreparation()
Remove ongoing ToC-Preparation process from the event-queue.
MSDevice_ToC(const MSDevice_ToC &)
Invalidated copy constructor.
void deactivateDeliberateLCs()
Resets the holder's LC mode to the operational LC-mode of the ToC Device (.
WrappingCommand< MSDevice_ToC > * myRecoverAwarenessCommand
void setAwareness(double value)
Set the awareness to the given value.
WrappingCommand< MSDevice_ToC > * myTriggerMRMCommand
double myDynamicToCThreshold
Duration in s. for which the vehicle needs to be able to follow its route without a lane change to co...
bool checkDynamicToC()
Check if the vehicle should induce a ToC due to internal reasons. That is, if the route cannot be fol...
ToCState
Enum describing the different regimes for the device,.
void writeOutput()
Write output to file given by option device.toc.file.
std::queue< std::pair< double, double > > myEventXY
Storage for events to be written to the output.
OutputDevice * myOutputFile
The file the devices output goes to.
double myCurrentAwareness
Current awareness-level of the driver in [0,1].
SUMOTime triggerMRM(SUMOTime t)
Trigger execution of an MRM.
SUMOTime triggerUpwardToC(SUMOTime t)
Trigger execution of a ToC X-->AUTOMATED ("upwards")
std::queue< std::pair< SUMOTime, std::string > > myEvents
Storage for events to be written to the output.
SUMOTime awarenessRecoveryStep(SUMOTime t)
Continue the awareness recovery for one time step.
std::string myMRMSafeSpot
stop vehicle tries to reach during MRM
static OpenGapParams getOpenGapParams(const SUMOVehicle &v)
static std::vector< double > lookupResponseTimeMRMProbs
Grid of the response time distribution.
void switchHolderType(const std::string &targetTypeID)
Switch the device holder's vehicle type.
Abstract in-vehicle device.
Representation of a vehicle in the micro simulation.
Definition MSVehicle.h:77
A storage for options typed value containers)
Definition OptionsCont.h:89
Static storage of an output device and its base (abstract) implementation.
Representation of a vehicle, person, or container.
Representation of a vehicle.
Definition SUMOVehicle.h:62
A wrapper for a Command function.
OpenGapParams(double timegap, double spacing, double changeRate, double maxDecel, bool active)