-
Notifications
You must be signed in to change notification settings - Fork 0
VexOS Execution Cycle
Knowledge of the VexOS internal execution cycle is often useful when designing event-based robot structures. This page goes hand-in-hand with the documentation on VexOS Events.
To correctly interpret how the VexOS execution cycle works, it is important to understand the different states of the Cortex Microcontroller can be placed in and the transitions between those states. The Cortex states are controlled by either the competition field control software (when plugged into the field) or by a competition switch. Competition switches can be either a hardware device or a (virtual) software device implemented by the IFI Loader program. The competition switch has two toggle switches:
+---+ +---+
Enable | | | X | Driver
Disable | X | | | Autonomous
+---+ +---+
Changes to the switch positions control how the robot moves between modes. The robot states for various switch positions are given below:
| State # | Switch 1 | Switch 2 | State Description |
|---|---|---|---|
| 1 | Disable | Autonomous | Robot disabled, before autonomous starts |
| 2 | Enable | Autonomous | Robot enabled, autonomous is running |
| 3 | Disable | Driver | Robot disabled, before operator control starts |
| 4 | Enable | Driver | Robot enabled, operator control is running |
In a normal competition where there is a pause to tabulate scores at the end of autonomous mode, the states advance sequentially from 1 to 4. If operator control begins immediately at the end of autonomous, then state 3 is skipped.
The transition from 1 to 2 and from 3 to 4 happens seamlessly. However, all other state transitions cause a robot reboot, which is a re-initializion of all software on the Cortex. Unless information is preserved in Global Data Slots, it is erased during such a reboot. VexOS does a lot of global data handling automatically, so the reboots will be more transparent than is straight easyC. It is still important to understand when the reboots happen, since all of the event sequence diagrams start with a reboot.
VexOS uses the concept of a Run Mode to describe the combined competition settings and execution phase. There are four distinct run modes:
- Setup - this is where hardware must be created and is always the first phase run on VexOS start-up
- Initialize - this is the second phase of startup, run after hardware setup has finished. This is also the run mode while the robot is disabled.
- Autonomous - executing in autonomous mode
- Operator - executing in operator control mode
The run mode can be queried using the following API function (from VexOS.h):
RunMode VexOS_getRunMode();This sequence shows the common Setup and Initialize phases. These are the same regardless of whether the robot is in autonomous or operator control mode.
-> Reboot
-> Set Run Mode = Setup
Run Subsystem Constructors, in the order they are passed to DefineRobot(...)
Run Robot Constructor
Write hardware configuration to Cortex
-> Set Run Mode = Initialize
Run Robot Initializer
Fire 'Initialize' Event
While Disabled {
Update Timing Variables
Run Command Scheduler
Fire 'DisabledPeriodic' Event
}
Fire 'DisabledEnd' Event
-> *Start Run Phase*
Note, if the Robot starts up without being disabled (such as when no field or competition switch is present), the "While Disabled" block never runs.
This sequence shows the Autonomous run phase:
-> Set Run Mode = Autonomous
Fire 'AutonomousStart' Event
Start Selected Autonomous Program (if exists)
While Not Disabled AND Mode is Autonomous {
Update Timing Variables
Run Command Scheduler
Fire 'AutonomousPeriodic' Event
}
Reboot
Note that if the robot is disabled or the mode is set away from Autonomous via the competition switch, the robot reboots and control goes back to the reboot sequence above.
This sequence shows the Operator run phase:
-> Set Run Mode = Operator
Fire 'OperatorStart' Event
While Not Disabled AND Mode is Operator {
Update Timing Variables
Run Command Scheduler
Fire 'OperatorPeriodic' Event
}
Reboot
Again, note that if the robot is disabled or the mode is set away from Drive via the competition switch, the robot reboots and control goes back to the reboot sequence.
I wish that these reboots were not the case, but this is an IFI decision that VexOS does its best to deal with.