This project is a high-performance line follower robot firmware designed for the STM32F103C8T6 (Blue Pill) microcontroller. It features an advanced navigation system capable of handling multiple complex zones, including:
- Black Box: Initial blind navigation.
- Curved Sections: Smooth PID control for sinuous lines.
- Hexagon Zone: Logic for navigating complex polygonal paths.
- Checkerboard: Handling discontinuous lines.
- Brain/Color Zone: Special logic for color inversion or specific tasks.
The system uses a 6-channel IR sensor array for line detection and an H-Bridge motor driver for differential drive control.
- Microcontroller: STM32F103C8T6 (Blue Pill)
- Motor Driver: L298N, TB6612FNG, or similar H-Bridge driver.
- Sensors: 6-Channel Analog IR Line Sensor Array (e.g., QTR-8A or generic).
- Chassis: Differential drive robot chassis.
- Power: LiPo battery (2S or 3S recommended).
Based on Core/Inc/motor_control.h:
| Function | STM32 Pin | Timer/Channel | Description |
|---|---|---|---|
| Left Motor PWM | PB6 | TIM4 CH1 | Speed control for Left Motor |
| Left Motor Dir | PA4 | GPIO Output | Direction for Left Motor |
| Right Motor PWM | PB7 | TIM4 CH2 | Speed control for Right Motor |
| Right Motor Dir | PA5 | GPIO Output | Direction for Right Motor |
Note: Ensure your motor driver supports PWM+Direction control. If using L298N with IN1/IN2/EN pins, connect PWM to EN and Direction to IN1 (with IN2 inverted via hardware or code modification).
The system expects 6 Analog Sensors.
Current Configuration Note: The generated main.c currently initializes ADC1 on PA0. You must configure the remaining ADC channels in STM32CubeMX or main.c to match your hardware (typically PA0-PA3, PA6-PA7, avoiding the motor pins PA4/PA5).
| Sensor Index | Recommended Pin | Description |
|---|---|---|
| Sensor 0 (Left) | PA0 | ADC1 Channel 0 |
| Sensor 1 | PA1 | ADC1 Channel 1 |
| Sensor 2 | PA2 | ADC1 Channel 2 |
| Sensor 3 | PA3 | ADC1 Channel 3 |
| Sensor 4 | PA6 | ADC1 Channel 6 |
| Sensor 5 (Right) | PA7 | ADC1 Channel 7 |
- LED: PC13 (On-board LED) - Used for calibration status.
- Debug/Aux: PA8, PA9, PA10, PA11 are configured as outputs (usage defined in user code).
Core/Src/enhanced_line_follower_fixed.c: The main entry point and control loop. Replaces the standardmain.clogic.Core/Inc/motor_control.h: Motor control logic and pin definitions.Core/Src/sensor_processing.c: Sensor data normalization, calibration, and line position calculation.Core/Src/calibration.c: Routines for calibrating sensor min/max values.
The robot uses a state machine to switch between different navigation strategies:
- Calibration: On startup, the robot calibrates sensors (rotate over line).
- Black Box: Blind acceleration.
- Line Follow: PID control based on weighted average of sensor inputs.
- Special Zones: Detected via specific sensor patterns (e.g., all white, all black, specific widths).
-
Open in STM32CubeIDE:
- Select
File>Open Projects from File System... - Point to the project directory.
- Select
-
Configuration:
- Open
final test i hope.iocif you need to change pin assignments using CubeMX. Warning: Regenerating code might overwrite manual changes inmain.c.
- Open
-
Build:
- Click the "Hammer" icon or
Project>Build Project.
- Click the "Hammer" icon or
-
Flash:
- Connect ST-Link V2.
- Click "Run" or "Debug".
On startup, the robot expects to be placed on the line. It may perform a calibration sequence (spinning left/right) to learn the white/black values. Ensure the LED (PC13) indicates the calibration state.
Strategy analysis and zone logic based on robot_strategy.md.