Modes of operation: BOARD_RUN The motors are set to move automatically based on the physics algorithm. LEDs reflect battery status. Enabled interrupts are only: IMU (timer) interrupt PWM interrupt Hall sensor interrupt (in emergency) watchdog interrupt Main loop handles stopping (BOARD_RUN->BOARD_STOP, on stopping after certain velocity attained, or on high sideways tilt at low speed) and safety BOARD_STOP Default condition on startup. The motors are isolated from the power supply. LEDs reflect battery status. Enabled interrupts are only: IMU (timer) interrupt -> calculate tilt angle as usual Hall sensor interrupt -> update e_theta only (updating the speed variables requires a rotating motor!) (in emergency) watchdog interrupt Main loop handles starting (BOARD_STOP->BOARD_RUN, on observed tilt angle around zero (flat) for a few seconds) and setup (BOARD_STOP->BOARD_SET, on button press/no prox) and safety BOARD_SET This allows selection of particular setup routines using buttons. The motors are isolated. Enabled interrupts are only: (emergency) watchdog interrupt Main loop handles button inputs to select menu 1-4 and item 1-4, LEDs reflect the selection. Menus/items 1. Safe modes 1. No limiting (full power) 2. Torque (current) limit to 20% 3. Velocity (voltage) limit to 20% 4. Velocity and torque limit to 20% 2. Data logging 1. Log IMU data 2. Log currents and battery voltage 3. Log temperature 3. Calibration 1. Hall sensor offset calibration (-> BOARD_HALL_CAL) 2. Current sensor calibration 3. IMU calibration BOARD_HALL_CAL Hall sensor calibration. This spins each motor at a known slow speed (assuming no load) and uses special hall sensor interrupt to average and store e_theta at each reading change. Enabled interrupts: Hall sensor calibration interrupt - averages and stores readings PWM calibration interrupt - makes PWM cycles given a particular e_theta and voltage (rather than current -> runs open loop) (in emergency) watchdog interrupt LEDs reflect status of calibration. On exit goes to BOARD_STOP. BOARD_CUR_CAL Current sensor calibration. This sets a given PWM cycle on each of the measured phases, so a current can be measured across a resistor to V-. Buttons determine the PWM cycle and are used to set the cycle which gives a particular current reading (such as 1A, 2A, 5A, etc). Enabled interrupts: PWM calibration interrupt 2 - makes a PWM cycle given a particular duty cycle and phase - open loop and not for motor control (in emergency) watchdog interrupt LEDs reflect status of calibration. Buttons control current. On exit goes to BOARD_STOP. BOARD_IMU_CAL IMU Calibration. This reads the IMU when it is still and sets the required offset parameters. Interrupts: IMU calibration interrupt (in emergency) watchdog interrupt LEDs reflect status of calibration. On exit goes to BOARD_STOP.