52 #define DEFAULT_RESPONSE_TIME 5.0 55 #define DEFAULT_RECOVERY_RATE 0.1 57 #define DEFAULT_INITIAL_AWARENESS 0.5 59 #define DEFAULT_MRM_DECEL 1.5 61 #define DEFAULT_MANUAL_TYPE "" 62 #define DEFAULT_AUTOMATED_TYPE "" 76 oc.
addDescription(
"device.toc.manualType",
"ToC Device",
"Vehicle type for manual driving regime.");
78 oc.
addDescription(
"device.toc.automatedType",
"ToC Device",
"Vehicle type for automated driving regime.");
80 oc.
addDescription(
"device.toc.responseTime",
"ToC Device",
"Average response time needed by a driver to take back control.");
82 oc.
addDescription(
"device.toc.recoveryRate",
"ToC Device",
"Recovery rate for the driver's awareness after a ToC.");
84 oc.
addDescription(
"device.toc.initialAwareness",
"ToC Device",
"Average awareness a driver has initially after a ToC.");
86 oc.
addDescription(
"device.toc.mrmDecel",
"ToC Device",
"Deceleration rate applied during a 'minimum risk maneuver'.");
88 oc.
addDescription(
"device.toc.useColorScheme",
"ToC Device",
"Whether a coloring scheme shall by applied to indicate the different ToC stages.");
105 manualType, automatedType, responseTime, recoveryRate,
106 initialAwareness, mrmDecel, useColoring);
107 into.push_back(device);
143 return getBoolParam(v, oc,
"toc.useColorScheme",
"false",
false);
152 std::string manualType, std::string automatedType,
153 SUMOTime responseTime,
double recoveryRate,
double initialAwareness,
154 double mrmDecel,
bool useColoring) :
186 }
else if (manualVTypeIsDist && holderVTypeID.find(
myManualTypeID) == 0) {
198 +
"') must coincide with manualType ('" + manualType +
"') or automatedType ('" + automatedType
199 +
"') specified for its ToC-device (or drawn from the specified vTypeDistributions).");
203 if (
myState == ToCState::MANUAL && automatedVTypeIsDist) {
205 }
else if (
myState == ToCState::AUTOMATED && manualVTypeIsDist) {
212 std::cout <<
"initialized device '" <<
id <<
"' with " 223 assert(myInitialAwareness <= 1.0 && myInitialAwareness >= 0.0);
243 std::cout <<
SIMTIME <<
" ensureDriverStateExistence() for vehicle '" <<
myHolder.
getID() <<
"'" << std::endl;
276 if (value > 1.0 || value < 0.0) {
277 std::stringstream ss;
278 ss <<
"Truncating invalid value for awareness (" << value <<
") to lie in [0,1].";
280 value =
MAX2(0.0,
MIN2(1.0, value));
284 ds->setAwareness(value);
321 std::cout <<
SIMTIME <<
" requestToC() for vehicle '" <<
myHolder.
getID() <<
"' , timeTillMRM=" << timeTillMRM << std::endl;
337 if (responseTime > timeTillMRM) {
350 if (timeTillMRM > 0.) {
351 std::stringstream ss;
352 ss <<
"[t=" <<
SIMTIME <<
"] Positive transition time (" << timeTillMRM / 1000. <<
"s.) for upward ToC of vehicle '" <<
myHolder.
getID() <<
"' is ignored.";
382 std::cout <<
SIMTIME <<
" triggerUpwardToC() for vehicle '" <<
myHolder.
getID() <<
"'" << std::endl;
403 std::cout <<
SIMTIME <<
" triggerDownwardToC() for vehicle '" <<
myHolder.
getID() <<
"'" << std::endl;
474 std::cout <<
SIMTIME <<
" Switching type of vehicle '" <<
myHolder.
getID() <<
"' to '" << targetTypeID <<
"'" << std::endl;
477 if (targetType == 0) {
488 std::cout <<
SIMTIME <<
" ToC preparation step for vehicle '" <<
myHolder.
getID() <<
"'" << std::endl;
496 std::cout <<
SIMTIME <<
" Aborting ToC preparation for vehicle '" <<
myHolder.
getID() <<
"'" << std::endl;
508 std::cout <<
SIMTIME <<
" MRM step for vehicle '" <<
myHolder.
getID() <<
"', currentSpeed=" << currentSpeed << std::endl;
512 std::vector<std::pair<SUMOTime, double> > speedTimeLine;
514 speedTimeLine.push_back(std::make_pair(t -
DELTA_T, currentSpeed));
515 speedTimeLine.push_back(std::make_pair(t, nextSpeed));
520 std::vector<std::pair<SUMOTime, int> > laneTimeLine;
522 laneTimeLine.push_back(std::make_pair(t -
DELTA_T, currentLane));
523 laneTimeLine.push_back(std::make_pair(t, currentLane));
540 std::cout <<
SIMTIME <<
" Awareness recovery step for vehicle '" <<
myHolder.
getID() <<
"'" << std::endl;
552 if (awarenessRecoveryCompleted) {
554 std::cout <<
SIMTIME <<
" Awareness recovery completed for veh '" <<
myHolder.
getID() <<
"'" << std::endl;
567 if (key ==
"manualType") {
569 }
else if (key ==
"automatedType") {
571 }
else if (key ==
"responseTime") {
573 }
else if (key ==
"recoveryRate") {
575 }
else if (key ==
"initialAwareness") {
577 }
else if (key ==
"mrmDecel") {
579 }
else if (key ==
"currentAwareness") {
581 }
else if (key ==
"state") {
583 }
else if (key ==
"holder") {
593 std::cout <<
"MSDevice_ToC::setParameter(key=" << key <<
", value=" << value <<
")" << std::endl;
595 if (key ==
"manualType") {
601 }
else if (key ==
"automatedType") {
607 }
else if (key ==
"responseTime") {
609 }
else if (key ==
"recoveryRate") {
611 }
else if (key ==
"initialAwareness") {
613 }
else if (key ==
"currentAwareness") {
615 }
else if (key ==
"mrmDecel") {
617 }
else if (key ==
"requestToC") {
621 }
else if (key ==
"requestMRM") {
624 }
else if (key ==
"awareness") {
635 if (str ==
"UNDEFINED") {
637 }
else if (str ==
"MANUAL") {
639 }
else if (str ==
"AUTOMATED") {
641 }
else if (str ==
"PREPARING_TOC") {
643 }
else if (str ==
"MRM") {
645 }
else if (str ==
"RECOVERING") {
658 }
else if (state ==
MANUAL) {
663 return "PREPARING_TOC";
664 }
else if (state ==
MRM) {
static bool getBoolParam(const SUMOVehicle &v, const OptionsCont &oc, std::string paramName, bool deflt, bool required)
void doRegister(const std::string &name, Option *v)
Adds an option under the given name.
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.
SUMOVehicle & myHolder
The vehicle that stores the device.
static void insertOptions(OptionsCont &oc)
Inserts MSDevice_ToC-options.
static double getRecoveryRate(const SUMOVehicle &v, const OptionsCont &oc)
SUMOTime MRMExecutionStep(SUMOTime t)
Continue the MRM for one time step.
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 &)
int parametersSet
Information for the router which parameter were set, TraCI may modify this (whe changing color) ...
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")
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
static double getResponseTime(const SUMOVehicle &v, const OptionsCont &oc)
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)
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
#define WRITE_WARNING(msg)
The car-following model and parameter.
static OptionsCont & getOptions()
Retrieves the options.
static std::mt19937 * getParsingRNG()
WrappingCommand< MSDevice_ToC > * myTriggerMRMCommand
void setSpeedTimeLine(const std::vector< std::pair< SUMOTime, double > > &speedTimeLine)
Sets a new velocity timeline.
void setAwareness(double value)
Set the awareness to the given value.
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
MSDevice_ToC(SUMOVehicle &holder, const std::string &id, std::string manualType, std::string automatedType, SUMOTime responseTime, double recoveryRate, double initialAwareness, double mrmDecel, bool useColorScheme)
Constructor.
Representation of a vehicle.
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.
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)
static void insertDefaultAssignmentOptions(const std::string &deviceName, const std::string &optionsTopic, OptionsCont &oc)
Adds common command options that allow to assign devices to vehicles.
void addOptionSubTopic(const std::string &topic)
Adds an option subtopic.
static double getMRMDecel(const SUMOVehicle &v, const OptionsCont &oc)
#define DEFAULT_AUTOMATED_TYPE
std::string myManualTypeID
vehicle type ID for manual driving
double myCurrentAwareness
const int VEHPARS_COLOR_SET
#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.
Abstract in-vehicle device.
Influencer & getInfluencer()
Returns the velocity/lane influencer.
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.
virtual const SUMOVehicleParameter & getParameter() const =0
Returns the vehicle's parameter (including departure definition)
A storage for options typed value containers)
static void buildVehicleDevices(SUMOVehicle &v, std::vector< MSDevice *> &into)
Build devices for the given vehicle, if needed.
const std::string & getID() const
Returns the name of the vehicle type.
static double _2double(const E *const data)
converts a char-type array into the double value described by it
void setState(ToCState state)
Set the ToC device's state.
void descheduleToC()
Remove scheduled ToC-Trigger command from the event-queue.
static bool equippedByDefaultAssignmentOptions(const OptionsCont &oc, const std::string &deviceName, SUMOVehicle &v, bool outputOptionSet)
Determines whether a vehicle should get a certain device.
#define DEFAULT_RECOVERY_RATE
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 setLaneTimeLine(const std::vector< std::pair< SUMOTime, int > > &laneTimeLine)
Sets a new lane timeline.
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 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
std::map< ToCState, RGBColor > myColorScheme
Coloring scheme,.
#define DEFAULT_RESPONSE_TIME
The ToC Device controls transition of control between automated and manual driving.
virtual const MSVehicleType & getVehicleType() const =0
Returns the vehicle's type.
double myMRMDecel
Deceleration rate applied during MRM.
double myInitialAwareness
static std::string getAutomatedType(const SUMOVehicle &v, const OptionsCont &oc)