Motor Controller - The-Bug-Bashers/iBOARCode GitHub Wiki

Overview

The Motor Controller service (C++) controls the robot’s motors.
It calculates individual motor speeds based on target speed and direction, runs a software PWM loop, and uses a PID controller to maintain correct motor speeds.

It also publishes real-time motor data (speeds, targets, PID values) via MQTT.


Best Practices

  • Other services only need to send desired headings and speeds - the controller handles the rest.
  • Always run in a named screen session: MotorController.
  • Start the MQTT Broker first.

🛠️ Commands

Action Command
Compile g++ main.cpp MotorController.cpp MotorControl.cpp Encoder.cpp MQTTHandler.cpp PID.cpp -o MotorController -lgpiod -lmosquitto -lpthread
Run sudo screen -S MotorController ./MotorController
Test if running `sudo screen -list
Stop sudo screen -S MotorController -X stuff "^C"

[!WARNING]
The stop command only works if the session is named MotorController.