Skip to content
cabbagecultistPublic

About

No description, website, or topics provided.

Resources

Stars

3 stars

Watchers

1 watching

Forks

Latest commit

 

History

31 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🦆 Rubber Duck Sumo Robot

Build Status Language License: MIT

A fully autonomous sumo robot, designed from scratch by a team of CEGEP students, featuring a robust sensor array, advanced tracking algorithms, and professional-grade firmware to compete against university-level teams.



📖 Table of Contents


🌟 About The Project

Rubber Duck is an autonomous sumo robot built for the IEEE Sumo Bot Competition. As the only team of CEGEP (pre-university) students in a field of university competitors, our goal was to engineer a robot that could not only compete but also demonstrate professional-grade design and software engineering practices.

This project involved designing, building, and programming a robot from the ground up. We focused on creating a system that was robust, modular, and maintainable. The result is a high-performance robot that leverages a sophisticated sensor array, a fault-tolerant I2C communication bus, and an object-oriented firmware architecture to outmaneuver opponents.

This repository contains the complete C++ firmware, showcasing a test-driven development approach, advanced control algorithms, and a deep understanding of embedded systems principles.


✨ Key Features

  • 🎯 Advanced Opponent Tracking: Utilizes a 5-sensor Time-of-Flight (ToF) array and a weighted-average algorithm to calculate precise opponent angles, with temporal filtering to ensure smooth, non-jittery tracking.
  • 🛡️ Robust I2C Error Recovery: Features a custom I2CManager that automatically detects bus timeouts and performs a multi-stage recovery protocol, ensuring sensor reliability even in electrically noisy environments.
  • ⚙️ Modular, Object-Oriented Firmware: Written in C++, the code is organized into distinct classes for each subsystem (sensors, motors, I2C), promoting code reuse, separation of concerns, and maintainability.
  • 🧪 Integrated Test Modes: A state-machine architecture allows switching between multiple modes (I2C Scanner, Sensor Test, Motor Test, Full Competition Mode), enabling rapid diagnostics and subsystem validation.
  • ⚡ High-Performance Drive System: Powered by a Dual VNH5019 motor driver and controlled by a custom PID loop, allowing for precise, high-torque movements for both aggressive and defensive maneuvers.
  • 👀 Reliable Edge Detection: Employs QTR reflectance sensors with logic to prevent false positives, ensuring the robot stays within the ring during intense combat.

🛠️ Tech Stack

The project was built using a combination of carefully selected hardware and modern software development tools.

Category Technology / Component
Microcontroller ESP32 Dev Module
Firmware C++
Frameworks Arduino Framework
Build System PlatformIO
Sensors • 5 x VL53L4CD Time-of-Flight Distance Sensors
• 2 x QTR Reflectance Sensors
Actuators Pololu Dual VNH5019 Motor Shield
Design & CAD Onshape
Version Control Git & GitHub

🏗️ Software Architecture

The firmware is designed with modularity, robustness, and testability as core principles, following an object-oriented paradigm.

The system is orchestrated by the SumoBot class, which manages the current operational mode and delegates tasks to specialized handler classes.

  • I2CManager: A crucial abstraction that handles all low-level I2C communication. It manages bus speed, scans for devices, and contains the logic for the fault-tolerant bus recovery mechanism.
  • DistanceSensorArray: Manages the array of 5 VL53L4CD sensors. It handles the complex initialization sequence (power-cycling via XSHUT pins, sequential address assignment) and provides a simple interface to get processed distance data.
  • ReflectanceSensorArray: A clean interface for the QTR edge sensors.
  • MotorDriver: Wraps the motor shield library, providing high-level functions like setSpeeds(), rotate(), and stop().
  • PIDController: A standard implementation of a Proportional-Integral-Derivative controller used for smoothing motor control and accurately turning towards the target.
  • TestMode System: An abstract base class TestMode defines a common interface (setup(), loop()). Concrete classes like DistanceSensorTestMode, ReflectanceTestMode, and the final TrackingMode implement this interface. This design pattern makes it trivial to add new functionalities or diagnostic routines while keeping the main loop clean.
// Simplified Main Loop in main.cpp
void setup() {
  sumoBot.begin(); // Initializes I2C and sets up the current mode
}

void loop() {
  sumoBot.update(); // Delegates to the loop() function of the active mode
}

🚀 Getting Started

To get a local copy up and running, follow these simple steps.

Prerequisites

Installation & Flashing

  1. Clone the repo:
    git clone https://github.com/cabbagecultist/Sumo.git
  2. Open the project in VS Code:
    cd Sumo
    code .
  3. Build and Upload:
    • PlatformIO will automatically detect the platformio.ini file and download the required libraries (QTRSensors, DualVNH5019MotorShield).
    • Connect your ESP32 board via USB.
    • Use the PlatformIO toolbar to build and upload the firmware to the board.

🤖 Usage

The robot's behavior is determined by the selectedMode variable in src/main.cpp. To change modes, modify this line and re-flash the firmware.

// In src/main.cpp
...
SumoBot()
{
  // Change this line to switch modes
  selectedMode = MODE_TRACKING; // Available modes are listed in the enum
  setMode(selectedMode);
}
...
  • MODE_DISTANCE: Continuously prints readings from all 5 distance sensors. Useful for calibration and checking for sensor timeouts.
  • MODE_REFLECTANCE: Prints readings from the edge detection sensors. Ideal for calibrating the line detection threshold.
  • MODE_MOTOR: Runs the motors through a sinusoidal speed profile to test the drive system.
  • MODE_I2C_SCANNER: Scans the I2C bus and prints the addresses of all connected devices.
  • MODE_TRACKING: The full competition mode, integrating all subsystems for autonomous operation.

🧠 Technical Challenges & Lessons Learned

This project presented several real-world engineering challenges. Here are two of the most significant:

1. I2C Bus Instability with Multiple Sensors

  • The Problem: An I2C bus with 5 sensors and high-current motors is prone to electrical noise and communication errors. A single sensor failing to respond can lock up the entire bus, paralyzing the robot. The standard Arduino Wire library offers no protection against this.
  • The Solution: I designed and implemented a dedicated I2CManager class with a fault-tolerant, multi-stage recovery protocol. If a sensor read times out, the manager automatically triggers a bus reset. This involves manually pulsing the SCL line to force any stuck slave device to release the SDA line, followed by generating a clean I2C STOP condition before re-initializing the Wire library. This made the sensor array exceptionally reliable.
  • What I Learned: This taught me the low-level mechanics of the I2C protocol beyond simple library calls. I gained a deep appreciation for defensive programming in embedded systems and learned how to design fault-tolerant software that can gracefully handle hardware-level failures.

2. Precise and Stable Opponent Tracking

  • The Problem: A naive "turn towards the closest sensor" algorithm is jittery and inefficient. The robot would often oscillate and could be easily confused if an opponent was positioned between two sensors.
  • The Solution: I developed a more intelligent tracking algorithm. Instead of just using the single closest reading, the code identifies the two closest sensors. If they are neighbors and their distance readings are similar, it calculates a weighted average of their respective angles to estimate the opponent's true position. Furthermore, this calculated angle is passed through a temporal moving average filter (applyTemporalAveraging) to smooth out noise and create stable, decisive turning motions controlled by a PID loop.
  • What I Learned: I gained practical experience in sensor data fusion and signal processing. This challenge forced me to move beyond simple conditional logic and apply control theory concepts (filtering, PID) to translate noisy, discrete sensor data into smooth, continuous physical action.

📈 Future Improvements

While the robot is fully functional, there are several areas for future enhancement:

  • Advanced State Machine: Implement a more sophisticated strategy engine (e.g., SEARCHING, ATTACKING, EVADING states) to make the robot's behavior more dynamic and less predictable.
  • Dual I2C Bus: Leverage the ESP32's two hardware I2C peripherals to split the sensor load, improving bus bandwidth and further increasing stability.
  • Wireless Telemetry: Use the ESP32's built-in WiFi or Bluetooth to stream real-time sensor data and diagnostic information to a laptop, enabling live debugging without a physical serial connection.

📄 License

Distributed under the MIT License. See LICENSE.txt for more information.

About

No description, website, or topics provided.

Resources

Stars

3 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages