Skip to content

Code Structure

Elisson Araújo edited this page Nov 22, 2024 · 1 revision

Code Structure

System Architecture

The SSL embedded Firmware in game flow, at each iteration try to update the current control message read from Nrf receiver, if a new message is received the new speed setpoints will be passed to the steering motors and the the kick parameters will be updated and the msg_watchdog timer is reset, with that, the next code segment executes the parameters for robot activities, this time including dribbler control, at the end of the code a telemetry message is sent to each time range.

As the execution speed of this loop is much faster than the loop for sending new messages through baseStation in the next interactions, the update functions acted to keep the robot functioning according to the last message received, until a new message is received or the value of NO_MSG_TIME be reached, when this occurs the robot locks the steering motors and the capacitors stop being charged regardless of the parameters of the last message, if the value of this timer reaches the value HALT_TIME the steering motors go to stand-by. Firmware Architecture

Main objects and methods:

  • radio_recv (nRF24Communication) object that represents nRF receiver, through which control messages are received:

    • updatePacket: Checks if the radio is working correctly, resetting and reconfiguring it if not and search for new control messages on the wireless network established by the baseStation.
    • getRobotVectorSpeed: Returns the direction parameters of the current message [vx, vy, w].
    • getKick: Returns the parameters for the kick mechanism of the current message [front, chip, charge, kickstrength, dribbler, dribblerSpeed].
  • motion (MotionControl) object that represents the robot's motors.

    • moveRobot: Updates the setpoints of the steering motors based on the PID control for the steering parameters passed by radio_recv and at the current speeds of the motors.
    • stopRobot: Set the motors in stand-by mode.
    • breakRobot: Locks the motors in the current position.
    • moveMotorPID: Updates the setpoint of a motor based on the PID control by its id, being used normally to control the dribbler.
    • stopMotor: Set the motor on stand-by by its id, used to set the dribbler's motor in this mode when its use is not required.
  • kick (Kicker) object that represents the robot's kick mechanism.

    • update: Updates the activity performed by the mechanism based on whether the robot has the ball, the capacitor load and the kick parameters passed by radio_recv.
    • stopCharge: Stops the capacitor charging regardless of what the kick parameters in radio_recv define.
    • getDribblerSpeed: returns the map of the dribbler's motor speed received in percentage by radio_recv for rad/s.
  • radio_send (nRF24Communication) object that represents nRF sender, where telemetry messages are sent back to baseStation:

    • sendTelemetryPacket: Sends the feedback message with the current status of the robot, which message has [id, steering motor speed (m1, m2, m3, m4), dribbler motor speed, capacitor load, if the robot has the ball and the battery charge].

File Organization

Following the pattern of including libraries in projects on platformIO and for better organization classes were created and their respective .h and .cpp are in folders with the same names in the lib folder, the subfolders of the Firmware directory are shown below.

├── lib
│   ├── Debugger
│   ├── FastPWM
│   ├── Kicker
│   ├── MotionControl
│   │   ├── FastPWM
│   │   ├── Navigation
│   │   └── PID_Controller
│   │       ├── DriverBLDC
│   │       └── Encoder
│   │           ├── QEI
│   │           └── QEInterruption
│   ├── nRF24Communication
│   │   ├── nRF24L01P
│   │   ├── nrf-config.h
│   │   └── nrf-utils.h
│   └── Utils
│       ├── MPU6000
│       ├── NeoPixel
│       └── ports_v1.2.h
└── src
    └── main.cpp