Skip to content

Modules in Each State

amadrafi edited this page Nov 9, 2021 · 2 revisions

Propulsion

Idle

/src/propulsion/main.cpp

  • Only used for transitioning.

Calibrating

/src/propulsion/main.cpp

  • Firstly, it checks if state_processor is initialised and if the motor data is ready
  • If state_processor is not initialized, it will initialize motors and send the motor data to the central database

Failure Condition: If state_processor is in critical failure after intializing motors, handleCriticalFailure is called which sets the running of the current thread to false, makes Propulsion enter critical failure and motor data is updated on the central data base.

Ready

/src/propulsion/main.cpp

  • While in Ready, it is checked if the Pod has changed states (encountered_transition)
  • If so, the settings data is sent to motors using prepareMotors called by sendOperationalCommand

Acceleration

/src/propulsion/main.cpp

  • Before everything else, it updates the motor data and velocity of the vehicle
  • Three things are then calculated: the average RPM, maximum current from the batteries, and maximum temperature from the motors
  • The code then sends the target rpm to the motor controllers, therefore accelerate the vehicle
  • If everything is not initialised, a message will appear saying "State Processor not initialised"

Failure Braking

src/propulsion/main.cpp

  • Quick warning, although it is named kEmergencyBraking in the file, it technically uses kFailureBraking from the state machine codebase and the switch happens in main.cpp
  • It sends a message to the motor controllers to stop all processes and logs it in the console

Cruising, Nominal Braking

src/propulsion/main.cpp

  • In these states, a message is sent to motor controllers to stop all processes and logs it in the console

Telemetry

Ready

src/telemetry/main.cpp

  • It sends and receive data from the main threads

Other States

src/telemetry/writer.cpp

  • Sends a message for each state transition to the client

Brakes

Idle, Finished

src/brakes/main.cpp

  • If a nominal braking command is given, checks if the magnetic and frictional brakes are clamped
  • If they are not clamped then commands to clamp them are sent
  • {This thread now sleeps for 1000ms as detailed by kBrakeCommandWaitTime}
  • Then checks if the brake button for the magnetic and frictional brake are pressed

Failure Condition: After the above, braking failure (checkBrakingFailure) is checked for, which is caused by brakes being retracted at this stage. If this condition is met, Brakes enters critical failure and the emergency brakes data is updated on the central data base.

  • If no braking command is given, then it is checked if the brakes are clamped
  • If they are, then brakes are retracted
  • Similar to before, it is checked if the brake button for the magnetic and frictional brake are pressed

Failure Condition: After the above, accelerating failure (checkAccFailure) is checked for, which is caused by brakes being clamped at this stage. If this condition is met, Brakes enters critical failure and the emergency brakes data is updated on the central data base.

Calibrating

src/brakes/main.cpp

  • Checks if the magnetic and frictional brakes are clamped - if so, then they are retracted
  • It is checked again whether both brakes are unclamped, if so, then Brakes enter the Ready state and updates the central data base with its emergency brakes data
  • {This thread now sleeps for 1000ms as detailed by kBrakeCommandWaitTime}
  • It is now checked if the brake button for the magnetic and frictional brake are pressed

Failure Condition: After the above, accelerating failure (checkAccFailure) is checked for, which is caused by brakes being clamped at this stage. If this condition is met, Brakes enters critical failure and the emergency brakes data is updated on the central data base.

Accelerating, Cruising

src/brakes/main.cpp

Failure Condition: Accelerating failure (checkAccFailure) is checked for, which is caused by brakes being clamped at this stage. If this condition is met, Brakes enters critical failure and the emergency brakes data is updated on the central data base.

Nominal Braking, Emergency Braking

src/brakes/main.cpp

  • Checks whether the magnetic and frictional brakes are clamped
  • If not, then they are clamped
  • {This thread now sleeps for 1000ms as detailed by kBrakeCommandWaitTime}
  • It is now checked if the brake button for the magnetic and frictional brake are pressed

Failure Condition: After the above, braking failure (checkBrakingFailure) is checked for, which is caused by brakes being retracted at this stage. If this condition is met, Brakes enters critical failure and the emergency brakes data is updated on the central data base.

Navigation

Calibrating

src/navigation/main.cpp

  • Checks whether the navigation module has been initialized, if so, then it calibrates for gravity

Accelerating

src/navigation/main.cpp

  • Checks if the initial timestamp has been set
  • If not then a timestamp is initialized for integration and the function to check if the timestamp has been initialized (setHasInit) is set to true

Emergency Braking, Cruising, Nominal Braking

src/navigation/main.cpp

  • The navigate command is used here, which takes acceleration readings from IMU, applies the Kalman filter (link documentation here) , integrates and then updates the central data base with new values

Other States (Idle and Ready)

src/navigation/main.cpp

  • Only used for transitioning

Sensors

Idle, Accelerating, Cruising, Nominal Braking

src/sensors/gpio_manager.cpp

  • Nothing is done

Failure Stopped, Emergency Braking

src/sensors/gpio_manager.cpp

  • clearHP is called
  • It is logged that Sensors is in a emergency state

Ready

src/sensors/gpio_manager.cpp

There are two instances where Sensors acts during Ready:

  1. If there has been a change in battery status from previous then
  • sethp is called and it is logged that Sensors is ready
  1. When the pod transitions into Ready
  • sethp is called and it is logged that Sensors is in kReady

Finished

src/sensors/gpio_manager.cpp

  • clearHP is called
  • It is logged that kFinished is reached
Clone this wiki locally