An autonomous sumo wrestling robot for AVR microcontrollers featuring pluggable strategies and hardware abstraction for motors, distance sensing, and line detection.
Target: AVR (e.g., ATmega328P) at 16 MHz Behavior: Selectable autonomous strategies via a strategy pattern Core sensors: HC-SR04 ultrasonic for opponent detection; CNY70 reflective for arena boundary Actuators: Dual DC motors via L298N driver with differential drive
| Component | Driver | Pins (Arduino) | Notes |
|---|---|---|---|
| HC-SR04 (ultrasonic) | hcsr04.h/c |
TRIG: PB4 (12); ECHO: PD2 (2) | Interrupt-driven pulse timing via INT0 and Timer1 |
| L298N (motor driver) | l298n.h/c |
Left: IN1=PB3(11), IN2=PD3(3), EN=PB2(10); Right: IN1=PD7(7), IN2=PB0(8), EN=PB1(9) | Differential drive; PWM enable pins |
| CNY70 (line sensor) | cny70.h |
PD4 (4) | Digital black/white detection |
- Strategy Pattern: Runtime selection of robot behaviors via function pointers. See
include/core/strategy.handsrc/core/strategy.c. - Strategies:
basic_seek_and_attack: Rotate until opponent ≤10 cm, then charge .line_seek_and_attack: Adds boundary evasion using CNY70 .
- Main Application: Initializes hardware, selects a strategy, and runs it indefinitely.
This project uses PlatformIO. Ensure platformio.ini is configured for the AVR target. Build and flash with:
pio run --target upload
The robot will wait 3 seconds after power-on before starting the selected strategy.
- Create
src/strategies/my_strategy.cwithmy_strategy_init()andmy_strategy_run()(infinite loop). - Add enum value to
strategy_tininclude/core/strategy.h. - Add function declarations to
include/core/strategy.h. - Add a case in
src/core/strategy.cto assign function pointers. - Select in
main.cviastrategy_init(STRATEGY_MY_STRATEGY).
- The strategy manager uses static function pointers for runtime dispatch with minimal RAM overhead (4 bytes) .
- Distance sensing includes robust error handling and retries.
- Motor control includes safety delays between direction changes.