Regbot firmware: Difference between revisions

From Rsewiki
Line 20: Line 20:
== Module list ==
== Module list ==


Most modules consist of a class.
Modules are encapsulated in a class.
All modules are defined in a header file (*.h), which includes the instance's global name.
They are all defined in a header file (*.h), which includes the instance's global name.
The implementation is a *.cpp file with the same name.
The implementation is a *.cpp file with the same name.


Line 32: Line 32:
** ucontrolbase (The base elements of a PID controller, i.e. an integrator and a pole-zero filter, and combine these to a PID controller.)
** ucontrolbase (The base elements of a PID controller, i.e. an integrator and a pole-zero filter, and combine these to a PID controller.)
** ucontrolturn (A specialized controller for turning. An extension of the control base.)
** ucontrolturn (A specialized controller for turning. An extension of the control base.)
* ucurrent     (Current measurements calculations.)
* ucurrent (Current measurements calculations.)
* udisplay    (Handling of the small 128x32 pixel O-Led display.)
* udisplay    (Handling of the small 128x32 pixel O-Led display.)
* ueeconfig    (Handling of save and recall configuration from flash memory.)
* ueeconfig    (Handling of save and recall configuration from flash memory.)
Line 51: Line 51:
** usubss      (Subscription support class for all modules.)
** usubss      (Subscription support class for all modules.)
* uusbhost    (Support for Logitech gamepad control of the robot using the USB-host connector (if connected).)
* uusbhost    (Support for Logitech gamepad control of the robot using the USB-host connector (if connected).)
Pin definitions are (mostly) in the ''main.h'' file.
All files not starting with the letter ''u'' are functions found on the net or modified library functions.
=== Module class structure ===

Revision as of 10:44, 11 March 2025

Back to Regbot

Main structure

The main (Arduino) file is regbot.ino

Arduino starts by calling a setup() function. This function sets up all modules and used libraries. All calibration values and other saved settings are loaded and implemented during the setup.

Arduino then calls loop(). This function holds the main loop, doing:

  • Listen for incoming commands (from USB) and service data subscriptions.
  • At regular intervals (1ms):
    • Read sensors,
    • Run control
    • Implement on actuators
    • Do data logging

Module list

Modules are encapsulated in a class. They are all defined in a header file (*.h), which includes the instance's global name. The implementation is a *.cpp file with the same name.

All modules, sub-modules and some additional library support files are in the src subdirectory.

The modules and sub-modules are (in alphabetic order):

  • uad (interrupt based Analogue to digital conversion.)
  • ucommand (A service module handling a few commands that didn't fit anywhere else.)
  • ucontrol (Implements all control actions, then is both PID controllers and the connection between them.)
    • ucontrolbase (The base elements of a PID controller, i.e. an integrator and a pole-zero filter, and combine these to a PID controller.)
    • ucontrolturn (A specialized controller for turning. An extension of the control base.)
  • ucurrent (Current measurements calculations.)
  • udisplay (Handling of the small 128x32 pixel O-Led display.)
  • ueeconfig (Handling of save and recall configuration from flash memory.)
  • uencoder (Calculating robot pose and velocity based on motor encoder values.)
  • uimu2 (Calculation tilt based on accelerometer and gyro.)
  • uirdist (Calculation distance based on analogue values from sensor, as well as sensor on and off)
  • ulinesensor (Line sensor calibration and data handling.)
  • ulog (Data logging.)
  • umission (Hold and maintain all mission lines.)
    • umissionline (Mission line class.)
    • umissionthread (Mission thread handling.)
  • umotor (Motor driver interface.)
  • umotortest (Support function that attempts to estimate motor parameters.)
  • urobot (Handling of the robot such as battery monitoring, power off and status LED.)
  • uservo (interface to servos.)
  • uusb (Handling interface on USB, including data subscriptions.)
    • usubs (Subscription item class.)
    • usubss (Subscription support class for all modules.)
  • uusbhost (Support for Logitech gamepad control of the robot using the USB-host connector (if connected).)

Pin definitions are (mostly) in the main.h file.

All files not starting with the letter u are functions found on the net or modified library functions.

Module class structure