Mode Management Mainloop Spec
From DGC Wiki
This is a slightly more abstract-but-closer-to-code version of Ryan's mainloop pseudo-code.
Mode Manager Datum: (Please add fields that may be missing. Please leave your username for reference.)
MM_datum {
// constants for modules & modes ...
// var's
struct Path new_path[NUM_MODULES]; // just arrived from modules
bool present[NUM_MODULES]; // whether each module is present
struct Path path[NUM_MODULES]; // paths we're evaluating on
double safety[NUM_MODULES]; // safety of each path
struct Path curPath; // the one we're driving on now
double curSafety; // safety of the curPath at the moment
// frequently updated by deadbaby sensing
int mode;
double global_speedlimit;
struct State curState; // updated frequently
int deadBabySignal; // dead baby sensing has caught something?
// add'l parameters
double paranoid; // if high, apply more safety
int resourceLevel; // something along the line of keeping
// track of failed system components
// maybe a bitmask for critical|major|minor
}
The main loop will look something like this:
main() {
while (vehicle running) {
get_all_paths(); // update paths to work over
chk_safety(MM.paths); // check safety of all updated paths
// Emergency circumstances: under these conditions, no matter what the // current mode is, we go into emergency mode. This part should include // checking the deadbaby flag. ...
// The big switch statement of modes. the contents should follow the
// mode-switch grid.
switch (MM.mode) {
case FAST:
if (canSwitchTo(...)) switchTo(...);
elseif (canSwitchTo(...)) switchTo(...);
...
case NORMAL: ...
case SLOW: ...
case STOP: ...
case REVERSE: ...
case PASSTHROUGH: ...
default:
// error msg
}
// Now choose path
MM.curPath = path[whatever module MM.mode maps to];
if (MM.mode == STOP) {
stop_vehicle(); // (KD & SAH)
}
// Modify path if needed
check_global_speedlimit(); // (RC)
apply_global_speedlimit(MM.curPath); // and broadcast to other modules (RC)
send_path_to_PF(MM.curPath); // (KD & SAH)
}
}
switchTo (mode) {
MM.mode = mode;
switch (mode) {
// any other stuff that needs to be done when switching modes
// e.g. case STOP: broadcast
}
}
![[Main Page]](../../../../upload/alice.jpg)