53 #define DEFAULT_RESPONSE_TIME 5.0 56 #define DEFAULT_RECOVERY_RATE 0.1 58 #define DEFAULT_LCABSTINENCE 0.0 60 #define DEFAULT_INITIAL_AWARENESS 0.5 62 #define DEFAULT_MRM_DECEL 1.5 65 #define DEFAULT_OPENGAP_TIMEGAP -1.0 66 #define DEFAULT_OPENGAP_SPACING 0.0 67 #define DEFAULT_OPENGAP_CHANGERATE 1.0 68 #define DEFAULT_OPENGAP_MAXDECEL 1.0 71 #define DEFAULT_MANUAL_TYPE "" 72 #define DEFAULT_AUTOMATED_TYPE "" 96 oc.
addDescription(
"device.toc.manualType",
"ToC Device",
"Vehicle type for manual driving regime.");
98 oc.
addDescription(
"device.toc.automatedType",
"ToC Device",
"Vehicle type for automated driving regime.");
100 oc.
addDescription(
"device.toc.responseTime",
"ToC Device",
"Average response time needed by a driver to take back control.");
102 oc.
addDescription(
"device.toc.recoveryRate",
"ToC Device",
"Recovery rate for the driver's awareness after a ToC.");
104 oc.
addDescription(
"device.toc.lcAbstinence",
"ToC Device",
"Attention level below which a driver restrains from performing lane changes (value in [0,1]).");
106 oc.
addDescription(
"device.toc.initialAwareness",
"ToC Device",
"Average awareness a driver has initially after a ToC (value in [0,1]).");
108 oc.
addDescription(
"device.toc.mrmDecel",
"ToC Device",
"Deceleration rate applied during a 'minimum risk maneuver'.");
110 oc.
addDescription(
"device.toc.ogNewTimeHeadway",
"ToC Device",
"Timegap for ToC preparation phase.");
112 oc.
addDescription(
"device.toc.ogNewSpaceHeadway",
"ToC Device",
"Additional spacing for ToC preparation phase.");
114 oc.
addDescription(
"device.toc.ogMaxDecel",
"ToC Device",
"Maximal deceleration applied for establishing increased gap in ToC preparation phase.");
116 oc.
addDescription(
"device.toc.ogChangeRate",
"ToC Device",
"Rate of adaptation towards the increased headway during ToC preparation.");
118 oc.
addDescription(
"device.toc.useColorScheme",
"ToC Device",
"Whether a coloring scheme shall by applied to indicate the different ToC stages.");
120 oc.
addDescription(
"device.toc.file",
"ToC Device",
"Switches on output by specifying an output filename.");
136 std::string deviceID =
"toc_" + v.
getID();
141 manualType, automatedType, responseTime, recoveryRate,
142 lcAbstinence, initialAwareness, mrmDecel, useColoring, ogp);
143 into.push_back(device);
151 std::string file =
"";
165 file = oc.
getString(
"device.toc.file") ==
"" ? file : oc.
getString(
"device.toc.file");
207 return getBoolParam(v, oc,
"toc.useColorScheme",
"false",
false);
212 double timegap =
getFloatParam(v, oc,
"toc.ogNewTimeHeadway", -1.0,
false);
213 double spacing =
getFloatParam(v, oc,
"toc.ogNewSpaceHeadway", -1.0,
false);
214 double changeRate =
getFloatParam(v, oc,
"toc.ogChangeRate", -1.0,
false);
215 double maxDecel =
getFloatParam(v, oc,
"toc.ogMaxDecel", -1.0,
false);
217 bool specifiedAny =
false;
218 if (changeRate == -1.0) {
223 if (maxDecel == -1.0) {
228 if (specifiedAny && timegap == -1 && spacing == -1) {
229 WRITE_ERROR(
"If any openGap parameters for the ToC model are specified, then at least one of ogTimeGap and ogSpacing must be defined.")
244 std::cout <<
"Parsed openGapParams: \n" 245 <<
" timegap=" << timegap
246 <<
", spacing=" << spacing
247 <<
", changeRate=" << changeRate
248 <<
", maxDecel=" << maxDecel
252 return OpenGapParams(timegap, spacing, changeRate, maxDecel, specifiedAny);
259 std::string manualType, std::string automatedType,
SUMOTime responseTime,
double recoveryRate,
260 double lcAbstinence,
double initialAwareness,
double mrmDecel,
bool useColoring,
OpenGapParams ogp) :
285 if (outputFilename !=
"") {
308 }
else if (manualVTypeIsDist && holderVTypeID.find(
myManualTypeID) == 0) {
320 +
"') must coincide with manualType ('" + manualType +
"') or automatedType ('" + automatedType
321 +
"') specified for its ToC-device (or drawn from the specified vTypeDistributions).");
325 if (
myState == ToCState::MANUAL && automatedVTypeIsDist) {
327 }
else if (
myState == ToCState::AUTOMATED && manualVTypeIsDist) {
334 std::cout <<
"initialized device '" <<
id <<
"' with " 335 <<
"outputFilename=" << outputFilename <<
", " 351 assert(myInitialAwareness <= 1.0 && myInitialAwareness >= 0.0);
371 std::cout <<
SIMTIME <<
" ensureDriverStateExistence() for vehicle '" <<
myHolder.
getID() <<
"'" << std::endl;
407 if (value > 1.0 || value < 0.0) {
408 std::stringstream ss;
409 ss <<
"Truncating invalid value for awareness (" << value <<
") to lie in [0,1].";
411 value =
MAX2(0.0,
MIN2(1.0, value));
416 }
else if (myCurrentAwareness < myLCAbstinence && value >=
myLCAbstinence) {
422 ds->setAwareness(value);
462 std::cout <<
SIMTIME <<
" requestToC() for vehicle '" <<
myHolder.
getID() <<
"' , timeTillMRM=" << timeTillMRM << std::endl;
478 if (responseTime > timeTillMRM) {
502 if (timeTillMRM > 0.) {
503 std::stringstream ss;
504 ss <<
"[t=" <<
SIMTIME <<
"] Positive transition time (" << timeTillMRM / 1000. <<
"s.) for upward ToC of vehicle '" <<
myHolder.
getID() <<
"' is ignored.";
540 std::cout <<
SIMTIME <<
" triggerUpwardToC() for vehicle '" <<
myHolder.
getID() <<
"'" << std::endl;
566 std::cout <<
SIMTIME <<
" triggerDownwardToC() for vehicle '" <<
myHolder.
getID() <<
"'" << std::endl;
642 std::cout <<
SIMTIME <<
" Switching type of vehicle '" <<
myHolder.
getID() <<
"' to '" << targetTypeID <<
"'" << std::endl;
645 if (targetType ==
nullptr) {
656 std::cout <<
SIMTIME <<
" ToC preparation step for vehicle '" <<
myHolder.
getID() <<
"'" << std::endl;
664 std::cout <<
SIMTIME <<
" Aborting ToC preparation for vehicle '" <<
myHolder.
getID() <<
"'" << std::endl;
677 std::cout <<
SIMTIME <<
" MRM step for vehicle '" <<
myHolder.
getID() <<
"', currentSpeed=" << currentSpeed << std::endl;
681 std::vector<std::pair<SUMOTime, double> > speedTimeLine;
683 speedTimeLine.push_back(std::make_pair(t -
DELTA_T, currentSpeed));
684 speedTimeLine.push_back(std::make_pair(t, nextSpeed));
702 std::cout <<
SIMTIME <<
" Awareness recovery step for vehicle '" <<
myHolder.
getID() <<
"'" << std::endl;
714 if (awarenessRecoveryCompleted) {
716 std::cout <<
SIMTIME <<
" Awareness recovery completed for veh '" <<
myHolder.
getID() <<
"'" << std::endl;
729 if (key ==
"manualType") {
731 }
else if (key ==
"automatedType") {
733 }
else if (key ==
"responseTime") {
735 }
else if (key ==
"recoveryRate") {
737 }
else if (key ==
"initialAwareness") {
739 }
else if (key ==
"mrmDecel") {
741 }
else if (key ==
"currentAwareness") {
743 }
else if (key ==
"lcAbstinence") {
745 }
else if (key ==
"state") {
747 }
else if (key ==
"holder") {
757 std::cout <<
"MSDevice_ToC::setParameter(key=" << key <<
", value=" << value <<
")" << std::endl;
759 if (key ==
"manualType") {
765 }
else if (key ==
"automatedType") {
771 }
else if (key ==
"responseTime") {
773 }
else if (key ==
"recoveryRate") {
775 }
else if (key ==
"initialAwareness") {
777 }
else if (key ==
"lcAbstinence") {
782 }
else if (key ==
"currentAwareness") {
786 WRITE_WARNING(
"Setting device.toc.currentAwareness during automated mode has no effect.")
788 }
else if (key ==
"mrmDecel") {
790 }
else if (key ==
"requestToC") {
794 }
else if (key ==
"requestMRM") {
797 }
else if (key ==
"awareness") {
808 if (str ==
"UNDEFINED") {
810 }
else if (str ==
"MANUAL") {
812 }
else if (str ==
"AUTOMATED") {
814 }
else if (str ==
"PREPARING_TOC") {
816 }
else if (str ==
"MRM") {
818 }
else if (str ==
"RECOVERING") {
831 }
else if (state ==
MANUAL) {
836 return "PREPARING_TOC";
837 }
else if (state ==
MRM) {
855 std::pair<SUMOTime, std::string>& e =
myEvents.front();
893 std::cout <<
"MSDevice_ToC::setLCModeMRM() setting LC Mode of vehicle '" <<
myHolder.
getID()
static bool getBoolParam(const SUMOVehicle &v, const OptionsCont &oc, std::string paramName, bool deflt, bool required)
int myPreviousLCMode
LC mode overridden during MRM, stored for restoration.
static int LCModeMRM
LC mode operational during an MRM.
void doRegister(const std::string &name, Option *v)
Adds an option under the given name.
OutputDevice & writeAttr(const SumoXMLAttr attr, const T &val)
writes a named attribute
RGBColor color
The vehicle's color, TraCI may change this.
static std::string getManualType(const SUMOVehicle &v, const OptionsCont &oc)
Representation of a vehicle in the micro simulation.
void descheduleRecovery()
Remove ongoing awareness recovery process from the event-queue.
ToCState myState
Current state of the device.
std::queue< std::pair< SUMOTime, std::string > > myEvents
Storage for events to be written to the output.
bool isAutomated()
Whether the current operation mode is automated.
static void insertOptions(OptionsCont &oc)
Inserts MSDevice_ToC-options.
static double getLCAbstinence(const SUMOVehicle &v, const OptionsCont &oc)
static double getRecoveryRate(const SUMOVehicle &v, const OptionsCont &oc)
SUMOTime MRMExecutionStep(SUMOTime t)
Continue the MRM for one time step.
bool isManuallyDriven()
Whether the current operation mode is manual.
void descheduleToCPreparation()
Remove ongoing ToC-Preparation process from the event-queue.
bool hasVTypeDistribution(const std::string &id) const
Asks for a vehicle type distribution.
static ToCState _2ToCState(const std::string &)
static std::set< MSDevice_ToC * > instances
int parametersSet
Information for the router which parameter were set, TraCI may modify this (whe changing color) ...
#define DEFAULT_OPENGAP_CHANGERATE
void descheduleMRM()
Break MRM Process or remove MRM-Trigger command from the event-queue.
SUMOTime triggerUpwardToC(SUMOTime t)
Trigger execution of a ToC X–>AUTOMATED ("upwards")
SUMOVehicle & myHolder
The vehicle that stores the device.
static OpenGapParams getOpenGapParams(const SUMOVehicle &v, const OptionsCont &oc)
#define DEFAULT_LCABSTINENCE
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
void createDriverState()
Create a DriverState for the vehicle.
WrappingCommand< MSDevice_ToC > * myExecuteMRMCommand
#define DEFAULT_OPENGAP_TIMEGAP
static double getResponseTime(const SUMOVehicle &v, const OptionsCont &oc)
static std::set< std::string > createdOutputFiles
#define DEFAULT_OPENGAP_MAXDECEL
void initColorScheme()
Initialize vehicle colors for different states.
static std::string _2string(ToCState state)
SUMOTime triggerDownwardToC(SUMOTime t)
Trigger execution of a ToC X–>MANUAL ("downwards")
static bool useColorScheme(const SUMOVehicle &v, const OptionsCont &oc)
int getLaneChangeMode() const
return the current lane change mode
std::string myAutomatedTypeID
vehicle type ID for automated driving
void requestToC(SUMOTime timeTillMRM)
Request a ToC. If the device is in AUTOMATED or MRM state, a driver response time is sampled and the ...
void requestMRM()
Request an MRM to be initiated immediately. No downward ToC will be scheduled.
#define DEFAULT_INITIAL_AWARENESS
void deactivateDeliberateLCs()
Resets the holder's LC mode to the operational LC-mode of the ToC Device (.
#define WRITE_WARNING(msg)
The car-following model and parameter.
MSDevice_ToC(SUMOVehicle &holder, const std::string &id, const std::string &outputFilename, std::string manualType, std::string automatedType, SUMOTime responseTime, double recoveryRate, double lcAbstinence, double initialAwareness, double mrmDecel, bool useColorScheme, OpenGapParams ogp)
Constructor.
static OptionsCont & getOptions()
Retrieves the options.
static void buildVehicleDevices(SUMOVehicle &v, std::vector< MSVehicleDevice *> &into)
Build devices for the given vehicle, if needed.
#define DEFAULT_OPENGAP_SPACING
static std::mt19937 * getParsingRNG()
WrappingCommand< MSDevice_ToC > * myTriggerMRMCommand
static void cleanup()
Closes root tags of output files.
void setSpeedTimeLine(const std::vector< std::pair< SUMOTime, double > > &speedTimeLine)
Sets a new velocity timeline.
static std::string getOutputFilename(const SUMOVehicle &v, const OptionsCont &oc)
void setAwareness(double value)
Set the awareness to the given value.
const MSCFModel & getCarFollowModel() const
Returns the vehicle's car following model definition.
bool knowsParameter(const std::string &key) const
Returns whether the parameter is known.
SUMOTime ensureDriverStateExistence(SUMOTime)
Ensure existence of DriverState for equipped vehicles.
bool myUseColorScheme
Whether a coloring scheme shall by applied to indicate the different toc stages,. ...
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
#define DEFAULT_MANUAL_TYPE
Representation of a vehicle.
OutputDevice * myOutputFile
The file the devices output goes to.
double myLCAbstinence
Level of the awareness below which no lane-changes are performed.
static double toDouble(const std::string &sData)
converts a string into the double value described by it by calling the char-type converter ...
ToCState
Enum describing the different regimes for the device,.
MSVehicleControl & getVehicleControl()
Returns the vehicle control.
MSEventControl * getBeginOfTimestepEvents()
Returns the event control for events executed at the begin of a time step.
std::string getString(const std::string &name) const
Returns the string-value of the named option (only for Option_String)
virtual void addEvent(Command *operation, SUMOTime execTimeStep=-1)
Adds an Event.
std::string getParameter(const std::string &key) const
try to retrieve the given parameter from this device. Throw exception for unsupported key ...
MSVehicle * myHolderMS
The holder vehicle casted to MSVehicle*.
static double getFloatParam(const SUMOVehicle &v, const OptionsCont &oc, std::string paramName, double deflt, bool required)
SUMOTime myResponseTime
Average response time needed by the driver to take back control.
void addOptionSubTopic(const std::string &topic)
Adds an option subtopic.
static double getMRMDecel(const SUMOVehicle &v, const OptionsCont &oc)
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.
#define DEFAULT_AUTOMATED_TYPE
std::string myManualTypeID
vehicle type ID for manual driving
double myCurrentAwareness
Current awareness-level of the driver in [0,1].
const int VEHPARS_COLOR_SET
const SUMOVTypeParameter & getParameter() const
#define DEFAULT_MRM_DECEL
const RGBColor & getColor() const
Returns this type's color.
static double getInitialAwareness(const SUMOVehicle &v, const OptionsCont &oc)
SUMOTime ToCPreparationStep(SUMOTime t)
Continue the ToC preparation for one time step.
MSVehicleType * getVType(const std::string &id=DEFAULT_VTYPE_ID, std::mt19937 *rng=0)
Returns the named vehicle type or a sample from the named distribution.
Influencer & getInfluencer()
Returns the velocity/lane influencer.
void activateGapController(double originalTau, double newTimeHeadway, double newSpaceHeadway, double duration, double changeRate, double maxDecel)
Activates the gap control with the given parameters,.
Structure representing possible vehicle parameter.
static std::string getStringParam(const SUMOVehicle &v, const OptionsCont &oc, std::string paramName, std::string deflt, bool required)
void deschedule()
Marks this Command as being descheduled.
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.
virtual double getHeadwayTime() const
Get the driver's desired headway [s].
static OutputDevice & getDevice(const std::string &name)
Returns the described OutputDevice.
virtual const SUMOVehicleParameter & getParameter() const =0
Returns the vehicle's parameter (including departure definition)
A storage for options typed value containers)
const std::string & getID() const
Returns the name of the vehicle type.
const std::string getParameter(const std::string &key, const std::string &defaultValue="") const
Returns the value for a given key.
Abstract in-vehicle device.
void setState(ToCState state)
Set the ToC device's state.
void descheduleToC()
Remove scheduled ToC-Trigger command from the event-queue.
void setLaneChangeMode(int value)
Sets lane changing behavior.
#define DEFAULT_RECOVERY_RATE
double myRecoveryRate
Recovery rate for the driver's awareness after a ToC.
Static storage of an output device and its base (abstract) implementation.
bool closeTag(const std::string &comment="")
Closes the most recently opened tag and optionally adds a comment.
WrappingCommand< MSDevice_ToC > * myRecoverAwarenessCommand
std::shared_ptr< MSSimpleDriverState > getDriverState() const
Returns the vehicle driver's state.
bool hasDevice(const std::string &deviceName) const
check whether the vehicle is equiped with a device of the given type
SUMOTime awarenessRecoveryStep(SUMOTime t)
Continue the awareness recovery for one time step.
~MSDevice_ToC()
Destructor.
void resetDeliberateLCs()
Resets the holder's LC mode to the last differing to LCModeMRM.
WrappingCommand< MSDevice_ToC > * myTriggerToCCommand
The class responsible for building and deletion of vehicles.
void addDescription(const std::string &name, const std::string &subtopic, const std::string &description)
Adds a description for an option.
double getSpeed() const
Returns the vehicle's current speed.
const std::string deviceName() const
return the name for this type of device
void switchHolderType(const std::string &targetTypeID)
Switch the device holder's vehicle type.
void setParameter(const std::string &key, const std::string &value)
try to set the given parameter for this device. Throw exception for unsupported key ...
void deactivateGapController()
Deactivates the gap control.
OpenGapParams myOpenGapParams
Parameters for the openGap mechanism applied during ToC preparation phase.
void replaceVehicleType(MSVehicleType *type)
Replaces the current vehicle type by the one given.
virtual const std::string & getID() const =0
Get the vehicle's ID.
SUMOTime triggerMRM(SUMOTime t)
Trigger execution of an MRM.
WrappingCommand< MSDevice_ToC > * myPrepareToCCommand
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.
std::map< ToCState, RGBColor > myColorScheme
Coloring scheme,.
#define DEFAULT_RESPONSE_TIME
bool generatesOutput()
Whether this device requested to write output.
The ToC Device controls transition of control between automated and manual driving.
void writeOutput()
Write output to file given by option device.toc.file.
virtual const MSVehicleType & getVehicleType() const =0
Returns the vehicle's type.
double myMRMDecel
Deceleration rate applied during MRM.
double myInitialAwareness
Average awareness the driver has initially after a ToC.
static std::string getAutomatedType(const SUMOVehicle &v, const OptionsCont &oc)