This repository contains the firmware for the University at Buffalo NASA Lunabotics rover. The system serves as a deterministic communication bridge between an ESP32-S3 and a Beckhoff CX7000 PLC using Modbus TCP over a wired W5500 Ethernet connection.
The firmware is architected to prioritize motor control stability and real-time sensor processing through a dual-core FreeRTOS implementation.
To ensure deterministic performance, tasks are pinned to specific CPU cores:
- Core 0: Control & Communication (
modbus_task)- Manages a non-blocking Modbus TCP client to interface with the Beckhoff PLC.
- Executes a custom state machine for writing control/speed words and reading motor status.
- Core 1: Sensing & User Interface
tof_task: Continuous 20Hz polling of the VL53L0X Time-of-Flight sensor for obstacle tracking.oled_task: Updates an SSD1306 display with real-time distance metrics and system status.
The system utilizes FreeRTOS Mutexes to prevent bus contention on the shared I2C bus (SDA: GPIO 5, SCL: GPIO 4) used by both the ToF sensor and the OLED display.
- Deterministic Control: Achieved a rigid motor control loop through non-blocking asynchronous callbacks and optimized task scheduling.
- Hardware Interface: Utilizes SPI for the W5500 Ethernet controller to bypass Wi-Fi latency in high-interference environments.
- Interactive UART CLI: A custom command-line interface allows for real-time troubleshooting and manual motor overrides (enable, stop, velocity tuning) without halting the RTOS scheduler.
- Robust Signal Logic: Implemented digital filtering for sensor readings to filter invalid distance data and manage range status errors.
The system features a serial interface (115200 baud) for live diagnostics:
enable: Energizes the motor system.stop/disable: Halts all movement and clears target speed.vel <n>: Dynamically updates the target speed word.stat: Returns a snapshot of current motor status, command words, and sensor telemetry.
ModbusEthernetEthernet(W5500 support)Adafruit_VL53L0XAdafruit_SSD1306Wire&SPI