SUMO - Simulation of Urban MObility
MSDevice_ToC.cpp
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2013-2018 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials
5 // are made available under the terms of the Eclipse Public License v2.0
6 // which accompanies this distribution, and is available at
7 // http://www.eclipse.org/legal/epl-v20.html
8 // SPDX-License-Identifier: EPL-2.0
9 /****************************************************************************/
18 // The ToC Device controls the transition of control between automated and manual driving.
19 //
20 /****************************************************************************/
21 
22 // ===========================================================================
23 // included modules
24 // ===========================================================================
25 #include <config.h>
26 
31 #include <utils/common/RGBColor.h>
32 #include <microsim/MSNet.h>
33 #include <microsim/MSVehicle.h>
37 #include <microsim/MSDriverState.h>
38 #include "MSDevice_ToC.h"
39 
40 
41 // ===========================================================================
42 // debug constants
43 // ===========================================================================
44 //#define DEBUG_TOC
45 
46 
47 // ===========================================================================
48 // parameter defaults
49 // ===========================================================================
50 
51 // default value for the average response time, that a driver needs to take back control
52 #define DEFAULT_RESPONSE_TIME 5.0
53 // default value for the average rate at which the driver's awareness recovers to
54 // 1.0 after a ToC has been performed
55 #define DEFAULT_RECOVERY_RATE 0.1
56 // The default value for the average awareness a driver has initially after a ToC
57 #define DEFAULT_INITIAL_AWARENESS 0.5
58 // The default value for the deceleration rate applied during a 'minimum risk maneuver'
59 #define DEFAULT_MRM_DECEL 1.5
60 
61 #define DEFAULT_MANUAL_TYPE ""
62 #define DEFAULT_AUTOMATED_TYPE ""
63 
64 // ===========================================================================
65 // method definitions
66 // ===========================================================================
67 // ---------------------------------------------------------------------------
68 // static initialisation methods
69 // ---------------------------------------------------------------------------
70 void
72  oc.addOptionSubTopic("ToC Device");
73  insertDefaultAssignmentOptions("toc", "ToC Device", oc);
74 
75  oc.doRegister("device.toc.manualType", new Option_String());
76  oc.addDescription("device.toc.manualType", "ToC Device", "Vehicle type for manual driving regime.");
77  oc.doRegister("device.toc.automatedType", new Option_String());
78  oc.addDescription("device.toc.automatedType", "ToC Device", "Vehicle type for automated driving regime.");
79  oc.doRegister("device.toc.responseTime", new Option_Float(DEFAULT_RESPONSE_TIME));
80  oc.addDescription("device.toc.responseTime", "ToC Device", "Average response time needed by a driver to take back control.");
81  oc.doRegister("device.toc.recoveryRate", new Option_Float(DEFAULT_RECOVERY_RATE));
82  oc.addDescription("device.toc.recoveryRate", "ToC Device", "Recovery rate for the driver's awareness after a ToC.");
83  oc.doRegister("device.toc.initialAwareness", new Option_Float(DEFAULT_INITIAL_AWARENESS));
84  oc.addDescription("device.toc.initialAwareness", "ToC Device", "Average awareness a driver has initially after a ToC.");
85  oc.doRegister("device.toc.mrmDecel", new Option_Float(DEFAULT_MRM_DECEL));
86  oc.addDescription("device.toc.mrmDecel", "ToC Device", "Deceleration rate applied during a 'minimum risk maneuver'.");
87  oc.doRegister("device.toc.useColorScheme", new Option_Bool(true));
88  oc.addDescription("device.toc.useColorScheme", "ToC Device", "Whether a coloring scheme shall by applied to indicate the different ToC stages.");
89 }
90 
91 
92 void
93 MSDevice_ToC::buildVehicleDevices(SUMOVehicle& v, std::vector<MSDevice*>& into) {
95  if (equippedByDefaultAssignmentOptions(oc, "toc", v, false)) {
96  std::string manualType = getManualType(v, oc);
97  std::string automatedType = getAutomatedType(v, oc);
98  SUMOTime responseTime = TIME2STEPS(getResponseTime(v, oc));
99  double recoveryRate = getRecoveryRate(v, oc);
100  double initialAwareness = getInitialAwareness(v, oc);
101  double mrmDecel = getMRMDecel(v, oc);
102  bool useColoring = useColorScheme(v, oc);
103  // build the device
104  MSDevice_ToC* device = new MSDevice_ToC(v, "toc_" + v.getID(),
105  manualType, automatedType, responseTime, recoveryRate,
106  initialAwareness, mrmDecel, useColoring);
107  into.push_back(device);
108  }
109 }
110 
111 std::string
113  return getStringParam(v, oc, "toc.manualType", DEFAULT_MANUAL_TYPE, true);
114 }
115 
116 std::string
118  return getStringParam(v, oc, "toc.automatedType", DEFAULT_AUTOMATED_TYPE, true);
119 }
120 
121 double
123  return getFloatParam(v, oc, "toc.responseTime", DEFAULT_RESPONSE_TIME, false);
124 }
125 
126 double
128  return getFloatParam(v, oc, "toc.recoveryRate", DEFAULT_RECOVERY_RATE, false);
129 }
130 
131 double
133  return getFloatParam(v, oc, "toc.initialAwareness", DEFAULT_INITIAL_AWARENESS, false);
134 }
135 
136 double
138  return getFloatParam(v, oc, "toc.mrmDecel", DEFAULT_MRM_DECEL, false);
139 }
140 
141 bool
143  return getBoolParam(v, oc, "toc.useColorScheme", "false", false);
144 }
145 
146 
147 
148 // ---------------------------------------------------------------------------
149 // MSDevice_ToC-methods
150 // ---------------------------------------------------------------------------
151 MSDevice_ToC::MSDevice_ToC(SUMOVehicle& holder, const std::string& id,
152  std::string manualType, std::string automatedType,
153  SUMOTime responseTime, double recoveryRate, double initialAwareness,
154  double mrmDecel, bool useColoring) :
155  MSDevice(holder, id),
156  myManualTypeID(manualType),
157  myAutomatedTypeID(automatedType),
158  myResponseTime(responseTime),
159  myRecoveryRate(recoveryRate),
160  myInitialAwareness(initialAwareness),
161  myMRMDecel(mrmDecel),
162  myCurrentAwareness(1.),
163  myUseColorScheme(useColoring),
164  myTriggerMRMCommand(nullptr),
165  myTriggerToCCommand(nullptr),
166  myRecoverAwarenessCommand(nullptr),
167  myExecuteMRMCommand(nullptr),
168  myPrepareToCCommand(nullptr) {
169  // Take care! Holder is currently being constructed. Cast occurs before completion.
170  myHolderMS = static_cast<MSVehicle*>(&holder);
171  // Ensure that the holder receives a driver state as soon as it is created (can't be done here, since myHolderMS is incomplete)
173 
174 
175  // Check if the given vTypes for the ToC Device are vTypeDistributions
177  const bool automatedVTypeIsDist = vehCtrl.hasVTypeDistribution(myAutomatedTypeID);
178  const bool manualVTypeIsDist = vehCtrl.hasVTypeDistribution(myManualTypeID);
179 
180  // Check if the vType of the holder matches one of the given vTypes
181  std::string holderVTypeID = holder.getVehicleType().getID();
182  if (holderVTypeID == myManualTypeID) {
183  myState = ToCState::MANUAL;
184  } else if (holderVTypeID == myAutomatedTypeID) {
185  myState = ToCState::AUTOMATED;
186  } else if (manualVTypeIsDist && holderVTypeID.find(myManualTypeID) == 0) {
187  // Holder type id starts with type distribution name.
188  // We assume that this means that it is from the given distribution.
189  myState = ToCState::MANUAL;
190  myManualTypeID = holderVTypeID;
191  } else if (automatedVTypeIsDist && holderVTypeID.find(myAutomatedTypeID) == 0) {
192  // Holder type id starts with type distribution name.
193  // We assume that this means that it is from the given distribution.
194  myState = ToCState::AUTOMATED;
195  myAutomatedTypeID = holderVTypeID;
196  } else {
197  throw ProcessError("Vehicle type of vehicle '" + holder.getID() + "' ('" + holder.getVehicleType().getID()
198  + "') must coincide with manualType ('" + manualType + "') or automatedType ('" + automatedType
199  + "') specified for its ToC-device (or drawn from the specified vTypeDistributions).");
200  }
201 
202  // Eventually instantiate given vTypes from distributions
203  if (myState == ToCState::MANUAL && automatedVTypeIsDist) {
205  } else if (myState == ToCState::AUTOMATED && manualVTypeIsDist) {
207  }
208 
209  initColorScheme();
210 
211 #ifdef DEBUG_TOC
212  std::cout << "initialized device '" << id << "' with "
213  << "myManualType=" << myManualTypeID << ", "
214  << "myAutomatedType=" << myAutomatedTypeID << ", "
215  << "myResponseTime=" << myResponseTime << ", "
216  << "myRecoveryRate=" << myRecoveryRate << ", "
217  << "myInitialAwareness=" << myInitialAwareness << ", "
218  << "myMRMDecel=" << myMRMDecel << ", "
219  << "myCurrentAwareness=" << myCurrentAwareness << ", "
220  << "myState=" << _2string(myState) << std::endl;
221 #endif
222 
223  assert(myInitialAwareness <= 1.0 && myInitialAwareness >= 0.0);
224 }
225 
226 
227 
228 void
230  //RGBColor(red, green, blue)
233  myColorScheme[PREPARING_TOC] = RGBColor(200, 200, 250); // light blue
234  myColorScheme[MRM] = RGBColor(250, 50, 50); // red
235  myColorScheme[RECOVERING] = RGBColor(250, 210, 150); // light yellow
236  myColorScheme[UNDEFINED] = RGBColor(150, 150, 150); // gray
237 }
238 
239 
240 SUMOTime
242 #ifdef DEBUG_TOC
243  std::cout << SIMTIME << " ensureDriverStateExistence() for vehicle '" << myHolder.getID() << "'" << std::endl;
244 #endif
245  // Ensure that the holder has a driver state
246  if (myHolderMS->getDriverState() == nullptr
247  && !myHolderMS->hasDevice("driverstate")) {
248  // Create an MSDriverState for the vehicle if it hasn't one already,
249  // and has no DriverState Device attached (that will create the driver state, then)
251  }
252  return 0;
253 }
254 
256  // deschedule commands associated to this device
257  if (myTriggerMRMCommand != nullptr) {
259  }
260  if (myTriggerToCCommand != nullptr) {
262  }
263  if (myRecoverAwarenessCommand != nullptr) {
265  }
266  if (myExecuteMRMCommand != nullptr) {
268  }
269  if (myPrepareToCCommand != nullptr) {
271  }
272 }
273 
274 void
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].";
279  WRITE_WARNING(ss.str());
280  value = MAX2(0.0, MIN2(1.0, value));
281  }
282  myCurrentAwareness = value;
283  std::shared_ptr<MSSimpleDriverState> ds = myHolderMS->getDriverState();
284  ds->setAwareness(value);
285 }
286 
287 
288 void
290  myState = state;
291  if (myUseColorScheme) {
292  setVehicleColor();
293  }
294 }
295 
296 void
301 }
302 
303 void
305  // Clean up previous MRM Commands
306  descheduleMRM();
307  // Remove any preparatory process
309  // .. and any recovery process
311  // ... and any pending ToC to manual
312  descheduleToC();
313  // Immediately trigger the MRM process
314  triggerMRM(0);
315 }
316 
317 
318 void
320 #ifdef DEBUG_TOC
321  std::cout << SIMTIME << " requestToC() for vehicle '" << myHolder.getID() << "' , timeTillMRM=" << timeTillMRM << std::endl;
322 #endif
323  if (myState == AUTOMATED) {
324  // Initialize preparation phase
325 
326  // @todo: Sample response time from distribution
327  SUMOTime responseTime = myResponseTime;
328 
329  // Schedule ToC Event
332 
333  // Clear eventually prior scheduled MRM
334 // descheduleMRM();
335  assert(myExecuteMRMCommand == nullptr);
336  assert(myTriggerMRMCommand == nullptr);
337  if (responseTime > timeTillMRM) {
338  // Schedule new MRM if driver response time is higher than permitted
341  }
342 
343  // Start ToC preparation process
347  } else {
348  // Switch to automated mode is performed immediately
349  // Note that the transition MRM/PREPARING_TOC->AUTOMATED, where a downward ToC is aborted, is handled here as well.
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.";
353  WRITE_WARNING(ss.str());
354  }
356  }
357 }
358 
359 
360 SUMOTime
362 #ifdef DEBUG_TOC
363  std::cout << SIMTIME << " triggerMRM() for vehicle '" << myHolder.getID() << "'" << std::endl;
364 #endif
365  // Clear ongoing MRM
366  descheduleMRM();
367 
368  // Start MRM process
371  setState(MRM);
373  setAwareness(1.);
374 
375  return 0;
376 }
377 
378 
379 SUMOTime
381 #ifdef DEBUG_TOC
382  std::cout << SIMTIME << " triggerUpwardToC() for vehicle '" << myHolder.getID() << "'" << std::endl;
383 #endif
385  setAwareness(1.);
387 
388  descheduleToC();
389  // Eventually stop ToC preparation process
391  // Eventually abort MRM
392  descheduleMRM();
393  // Eventually abort awareness recovery process
395 
396  return 0;
397 }
398 
399 
400 SUMOTime
402 #ifdef DEBUG_TOC
403  std::cout << SIMTIME << " triggerDownwardToC() for vehicle '" << myHolder.getID() << "'" << std::endl;
404 #endif
406 
407  // @todo: Sample initial awareness
408  double initialAwareness = myInitialAwareness;
409  setAwareness(initialAwareness);
410 
411 #ifdef DEBUG_TOC
412  std::cout << SIMTIME << " Initial awareness after ToC: " << myCurrentAwareness << std::endl;
413 #endif
414 
415  // Start awareness recovery process
419 
420  descheduleToC();
421  // Eventually stop ToC preparation process
423  // Eventually abort MRM
424  descheduleMRM();
425 
426  return 0;
427 }
428 
429 void
431  // Eventually abort scheduled MRM
432  if (myTriggerMRMCommand != nullptr) {
434  myTriggerMRMCommand = nullptr;
435  }
436  // Eventually abort ongoing MRM
437  if (myExecuteMRMCommand != nullptr) {
439  myExecuteMRMCommand = nullptr;
440  }
441 }
442 
443 
444 void
446  if (myTriggerToCCommand != nullptr) {
448  myTriggerToCCommand = nullptr;
449  }
450 }
451 
452 void
454  // Eventually stop ToC preparation process
455  if (myPrepareToCCommand != nullptr) {
457  myPrepareToCCommand = nullptr;
458  }
459 }
460 
461 void
463  // Eventually stop ToC preparation process
464  if (myRecoverAwarenessCommand != nullptr) {
466  myRecoverAwarenessCommand = nullptr;
467  }
468 }
469 
470 
471 void
472 MSDevice_ToC::switchHolderType(const std::string& targetTypeID) {
473 #ifdef DEBUG_TOC
474  std::cout << SIMTIME << " Switching type of vehicle '" << myHolder.getID() << "' to '" << targetTypeID << "'" << std::endl;
475 #endif
476  MSVehicleType* targetType = MSNet::getInstance()->getVehicleControl().getVType(targetTypeID);
477  if (targetType == 0) {
478  WRITE_ERROR("vType '" + targetType->getID() + "' for vehicle '" + myHolder.getID() + "' is not known.");
479  return;
480  }
481  myHolderMS->replaceVehicleType(targetType);
482 }
483 
484 
485 SUMOTime
487 #ifdef DEBUG_TOC
488  std::cout << SIMTIME << " ToC preparation step for vehicle '" << myHolder.getID() << "'" << std::endl;
489 #endif
490  // TODO: Devise preparation of ToC (still needs discussion). At least: do not overtake. Perhaps, increase gap to leader.
491 
492  if (myState == PREPARING_TOC) {
493  return DELTA_T;
494  } else {
495 #ifdef DEBUG_TOC
496  std::cout << SIMTIME << " Aborting ToC preparation for vehicle '" << myHolder.getID() << "'" << std::endl;
497 #endif
499  return 0;
500  }
501 }
502 
503 
504 SUMOTime
506  const double currentSpeed = myHolderMS->getSpeed();
507 #ifdef DEBUG_TOC
508  std::cout << SIMTIME << " MRM step for vehicle '" << myHolder.getID() << "', currentSpeed=" << currentSpeed << std::endl;
509 #endif
510 
511  // Induce slowdown with MRMDecel
512  std::vector<std::pair<SUMOTime, double> > speedTimeLine;
513  const double nextSpeed = MAX2(0., currentSpeed - ACCEL2SPEED(myMRMDecel));
514  speedTimeLine.push_back(std::make_pair(t - DELTA_T, currentSpeed));
515  speedTimeLine.push_back(std::make_pair(t, nextSpeed));
516  myHolderMS->getInfluencer().setSpeedTimeLine(speedTimeLine);
517 
518  // Prevent lane changes during MRM
519  // TODO: seems not to function
520  std::vector<std::pair<SUMOTime, int> > laneTimeLine;
521  const int currentLane = myHolderMS->getLaneIndex();
522  laneTimeLine.push_back(std::make_pair(t - DELTA_T, currentLane));
523  laneTimeLine.push_back(std::make_pair(t, currentLane));
524  myHolderMS->getInfluencer().setLaneTimeLine(laneTimeLine);
525 
526  if (myState == MRM) {
527  return DELTA_T;
528  } else {
529 #ifdef DEBUG_TOC
530  std::cout << SIMTIME << " Aborting MRM for vehicle '" << myHolder.getID() << "'" << std::endl;
531 #endif
532  return 0;
533  }
534 }
535 
536 
537 SUMOTime
539 #ifdef DEBUG_TOC
540  std::cout << SIMTIME << " Awareness recovery step for vehicle '" << myHolder.getID() << "'" << std::endl;
541 #endif
542  // Proceed with awareness recovery
543  if (myCurrentAwareness < 1.0) {
545  }
546 
547 #ifdef DEBUG_TOC
548  std::cout << SIMTIME << " currentAwareness = " << myCurrentAwareness << std::endl;
549 #endif
550 
551  const bool awarenessRecoveryCompleted = myCurrentAwareness == 1.0;
552  if (awarenessRecoveryCompleted) {
553 #ifdef DEBUG_TOC
554  std::cout << SIMTIME << " Awareness recovery completed for veh '" << myHolder.getID() << "'" << std::endl;
555 #endif
557  myRecoverAwarenessCommand = nullptr;
558  setState(MANUAL);
559  return 0;
560  }
561  return DELTA_T;
562 }
563 
564 
565 std::string
566 MSDevice_ToC::getParameter(const std::string& key) const {
567  if (key == "manualType") {
568  return myManualTypeID;
569  } else if (key == "automatedType") {
570  return myAutomatedTypeID;
571  } else if (key == "responseTime") {
573  } else if (key == "recoveryRate") {
574  return toString(myRecoveryRate);
575  } else if (key == "initialAwareness") {
577  } else if (key == "mrmDecel") {
578  return toString(myMRMDecel);
579  } else if (key == "currentAwareness") {
581  } else if (key == "state") {
582  return _2string(myState);
583  } else if (key == "holder") {
584  return myHolder.getID();
585  }
586  throw InvalidArgument("Parameter '" + key + "' is not supported for device of type '" + deviceName() + "'");
587 }
588 
589 
590 void
591 MSDevice_ToC::setParameter(const std::string& key, const std::string& value) {
592 #ifdef DEBUG_TOC
593  std::cout << "MSDevice_ToC::setParameter(key=" << key << ", value=" << value << ")" << std::endl;
594 #endif
595  if (key == "manualType") {
596  myManualTypeID = value;
598  if (myState == MANUAL) {
599  switchHolderType(value);
600  }
601  } else if (key == "automatedType") {
602  myAutomatedTypeID = value;
604  if (myState == AUTOMATED || myState == PREPARING_TOC || myState == MRM) {
605  switchHolderType(value);
606  }
607  } else if (key == "responseTime") {
609  } else if (key == "recoveryRate") {
610  myRecoveryRate = TplConvert::_2double(value.c_str());
611  } else if (key == "initialAwareness") {
612  myInitialAwareness = TplConvert::_2double(value.c_str());
613  } else if (key == "currentAwareness") {
614  myCurrentAwareness = TplConvert::_2double(value.c_str());
615  } else if (key == "mrmDecel") {
616  myMRMDecel = TplConvert::_2double(value.c_str());
617  } else if (key == "requestToC") {
618  // setting this magic parameter gives the interface for inducing a ToC
619  const SUMOTime timeTillMRM = TIME2STEPS(TplConvert::_2double(value.c_str()));
620  requestToC(timeTillMRM);
621  } else if (key == "requestMRM") {
622  // setting this magic parameter gives the interface for inducing an MRM
623  requestMRM();
624  } else if (key == "awareness") {
625  // setting this magic parameter gives the interface for setting the driverstate's awareness
626  setAwareness(TplConvert::_2double(value.c_str()));
627  } else {
628  throw InvalidArgument("Parameter '" + key + "' is not supported for device of type '" + deviceName() + "'");
629  }
630 }
631 
632 
634 MSDevice_ToC::_2ToCState(const std::string& str) {
635  if (str == "UNDEFINED") {
636  return UNDEFINED;
637  } else if (str == "MANUAL") {
638  return MANUAL;
639  } else if (str == "AUTOMATED") {
640  return AUTOMATED;
641  } else if (str == "PREPARING_TOC") {
642  return PREPARING_TOC;
643  } else if (str == "MRM") {
644  return MRM;
645  } else if (str == "RECOVERING") {
646  return RECOVERING;
647  } else {
648  WRITE_WARNING("Unknown ToCState '" + str + "'");
649  return UNDEFINED;
650  }
651 }
652 
653 
654 std::string
656  if (state == UNDEFINED) {
657  return "UNDEFINED";
658  } else if (state == MANUAL) {
659  return "MANUAL";
660  } else if (state == AUTOMATED) {
661  return "AUTOMATED";
662  } else if (state == PREPARING_TOC) {
663  return "PREPARING_TOC";
664  } else if (state == MRM) {
665  return "MRM";
666  } else if (state == RECOVERING) {
667  return "RECOVERING";
668  } else {
669  WRITE_WARNING("Unknown ToCState '" + toString(state) + "'");
670  return toString(state);
671  }
672 }
673 
674 /****************************************************************************/
675 
static bool getBoolParam(const SUMOVehicle &v, const OptionsCont &oc, std::string paramName, bool deflt, bool required)
Definition: MSDevice.cpp:264
void doRegister(const std::string &name, Option *v)
Adds an option under the given name.
Definition: OptionsCont.cpp:75
RGBColor color
The vehicle&#39;s color, TraCI may change this.
static std::string getManualType(const SUMOVehicle &v, const OptionsCont &oc)
Representation of a vehicle in the micro simulation.
Definition: MSVehicle.h:79
long long int SUMOTime
Definition: SUMOTime.h:36
void descheduleRecovery()
Remove ongoing awareness recovery process from the event-queue.
ToCState myState
Current state of the device.
Definition: MSDevice_ToC.h:226
#define ACCEL2SPEED(x)
Definition: SUMOTime.h:54
SUMOVehicle & myHolder
The vehicle that stores the device.
Definition: MSDevice.h:195
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).
Definition: MSNet.cpp:160
T MAX2(T a, T b)
Definition: StdDefs.h:68
void createDriverState()
Create a DriverState for the vehicle.
Definition: MSVehicle.cpp:5364
SUMOTime DELTA_T
Definition: SUMOTime.cpp:35
WrappingCommand< MSDevice_ToC > * myExecuteMRMCommand
Definition: MSDevice_ToC.h:239
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)
#define TIME2STEPS(x)
Definition: SUMOTime.h:60
#define TS
Definition: SUMOTime.h:45
std::string myAutomatedTypeID
vehicle type ID for automated driving
Definition: MSDevice_ToC.h:204
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)
Definition: MsgHandler.h:242
The car-following model and parameter.
Definition: MSVehicleType.h:66
static OptionsCont & getOptions()
Retrieves the options.
Definition: OptionsCont.cpp:58
#define SIMTIME
Definition: SUMOTime.h:65
int getLaneIndex() const
Definition: MSVehicle.cpp:4625
static std::mt19937 * getParsingRNG()
WrappingCommand< MSDevice_ToC > * myTriggerMRMCommand
Definition: MSDevice_ToC.h:236
void setSpeedTimeLine(const std::vector< std::pair< SUMOTime, double > > &speedTimeLine)
Sets a new velocity timeline.
Definition: MSVehicle.cpp:265
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,. ...
Definition: MSDevice_ToC.h:223
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:49
#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.
Definition: SUMOVehicle.h:60
ToCState
Enum describing the different regimes for the device,.
Definition: MSDevice_ToC.h:84
MSVehicleControl & getVehicleControl()
Returns the vehicle control.
Definition: MSNet.h:309
#define SIMSTEP
Definition: SUMOTime.h:64
MSEventControl * getBeginOfTimestepEvents()
Returns the event control for events executed at the begin of a time step.
Definition: MSNet.h:402
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 ...
#define STEPS2TIME(x)
Definition: SUMOTime.h:58
MSVehicle * myHolderMS
The holder vehicle casted to MSVehicle*.
Definition: MSDevice_ToC.h:231
static double getFloatParam(const SUMOVehicle &v, const OptionsCont &oc, std::string paramName, double deflt, bool required)
Definition: MSDevice.cpp:231
T MIN2(T a, T b)
Definition: StdDefs.h:62
static void insertDefaultAssignmentOptions(const std::string &deviceName, const std::string &optionsTopic, OptionsCont &oc)
Adds common command options that allow to assign devices to vehicles.
Definition: MSDevice.cpp:112
SUMOTime myResponseTime
Definition: MSDevice_ToC.h:207
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
Definition: MSDevice_ToC.h:202
double myCurrentAwareness
Definition: MSDevice_ToC.h:217
const int VEHPARS_COLOR_SET
#define DEFAULT_MRM_DECEL
const RGBColor & getColor() const
Returns this type&#39;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.
#define WRITE_ERROR(msg)
Definition: MsgHandler.h:248
Abstract in-vehicle device.
Definition: MSDevice.h:65
Influencer & getInfluencer()
Returns the velocity/lane influencer.
Definition: MSVehicle.cpp:5196
Structure representing possible vehicle parameter.
static std::string getStringParam(const SUMOVehicle &v, const OptionsCont &oc, std::string paramName, std::string deflt, bool required)
Definition: MSDevice.cpp:198
void deschedule()
Marks this Command as being descheduled.
virtual const SUMOVehicleParameter & getParameter() const =0
Returns the vehicle&#39;s parameter (including departure definition)
void setVehicleColor()
A storage for options typed value containers)
Definition: OptionsCont.h:92
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.
Definition: MSVehicleType.h:94
static double _2double(const E *const data)
converts a char-type array into the double value described by it
Definition: TplConvert.h:305
void setState(ToCState state)
Set the ToC device&#39;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.
Definition: MSDevice.cpp:126
#define DEFAULT_RECOVERY_RATE
double myRecoveryRate
Definition: MSDevice_ToC.h:209
WrappingCommand< MSDevice_ToC > * myRecoverAwarenessCommand
Definition: MSDevice_ToC.h:238
std::shared_ptr< MSSimpleDriverState > getDriverState() const
Returns the vehicle driver&#39;s state.
Definition: MSVehicle.h:896
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.
Definition: MSVehicle.cpp:272
WrappingCommand< MSDevice_ToC > * myTriggerToCCommand
Definition: MSDevice_ToC.h:237
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&#39;s current speed.
Definition: MSVehicle.h:479
const std::string deviceName() const
return the name for this type of device
Definition: MSDevice_ToC.h:113
void switchHolderType(const std::string &targetTypeID)
Switch the device holder&#39;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&#39;s ID.
SUMOTime triggerMRM(SUMOTime t)
Trigger execution of an MRM.
WrappingCommand< MSDevice_ToC > * myPrepareToCCommand
Definition: MSDevice_ToC.h:240
std::map< ToCState, RGBColor > myColorScheme
Coloring scheme,.
Definition: MSDevice_ToC.h:220
#define DEFAULT_RESPONSE_TIME
The ToC Device controls transition of control between automated and manual driving.
Definition: MSDevice_ToC.h:55
virtual const MSVehicleType & getVehicleType() const =0
Returns the vehicle&#39;s type.
double myMRMDecel
Deceleration rate applied during MRM.
Definition: MSDevice_ToC.h:214
double myInitialAwareness
Definition: MSDevice_ToC.h:211
static std::string getAutomatedType(const SUMOVehicle &v, const OptionsCont &oc)