Autonomous navigation system designed for a differential drive robot. This project implements a robust Wall-Following Algorithm using IR distance sensors and a Real-Time Proportional Controller to correct trajectory errors on the fly.
Built from scratch in C without high-level abstractions, interacting directly with registers and implementing a custom UART Driver for Dynamixel actuators.
(The robot continuously adjusts its distance to the wall using P-Control logic)
The system features a safety-first "Arming Sequence". The robot does not move until the mode is activated (Center Button) and a direction is selected.
👁️ Click to expand Main Logic Diagram
graph TD
Start([Start System]) --> Init[Init UART, Timers & Interrupts]
Init --> Idle{Wait for Input}
Idle -- "Center Button" --> Arm[Mode ENABLED<br/>Wait for Direction]
Arm -- "Left/Right Joystick" --> SetDir[Set Direction Flags]
SetDir --> CheckLoop{Check Loop Condition}
CheckLoop -- "Flags=True & Mode=True" --> Algorithm[Execute Wall Follower]
Algorithm --> CheckJoy{Joystick Moved?}
CheckJoy -- "YES (Emergency Stop)" --> Stop[STOP Robot & Reset Flags]
Stop --> Idle
CheckJoy -- NO --> CheckLoop
style Start fill:#f9f,stroke:#333,stroke-width:2px
style Stop fill:#ffaaaa,stroke:#333,stroke-width:2px
Complex decision-making process involving Proportional Error Correction for straight lines and specific sub-routines for corners and dead-ends.
👁️ Click to expand Algorithm Diagram
graph TD
Start([Start Algorithm]) --> Read[Read All Sensors]
Read --> Front{Wall in Front?}
%% BRANCH: WALL IN FRONT
Front -- YES --> RightClose{Right Wall Close?}
RightClose -- YES --> Rot90[Rotate 90 Left]
RightClose -- NO --> TurnLeft[Turn Left]
TurnLeft --> Advance1[Advance]
Rot90 --> DetectRight{Detect Right Wall?}
DetectRight -- YES --> Merge((Continue))
%% RECOVERY MODE (Lost Wall)
DetectRight -- NO --> LargeRot[Wide Rotation<br/>Advance + Turn Right]
LargeRot --> Read2[Read Sensors]
Read2 --> FrontVeryClose{Front Wall<br/>Very Close?}
FrontVeryClose -- YES --> Rot180[Rotate 180]
FrontVeryClose -- NO --> DetectRight
Rot180 --> DetectRight
%% BRANCH: NO WALL IN FRONT (Proportional Control)
Front -- NO --> Calc["Calculate Error<br/>(Ideal - Actual)"]
Calc --> ErrBig{"Error > 3<br/>(Too Far)"}
ErrBig -- YES --> TurnRight[Turn Right]
ErrBig -- NO --> ErrSmall{"Error < -3<br/>(Too Close)"}
ErrSmall -- YES --> TurnLeft2[Turn Left]
ErrSmall -- NO --> Advance2[Advance Fast]
TurnRight --> Advance3[Advance]
TurnLeft2 --> Advance3
Advance2 --> Merge
Advance3 --> Merge
Merge --> Read
The code is structured to separate business logic from hardware specifics:
main.c: High-level decision making and state management.robot_control.c: Low-level driver implementation. Direct manipulation of P3.2/P3.3 for UART and Timer_A0/A1 for precise timing.
Instead of using a pre-built library, a custom driver was written to communicate with the Dynamixel AX-12A motors via UART Half-Duplex.
- Packet Construction: Manually assembling the byte frame (
Header,ID,Length,Instruction,Checksum). - Error Handling: Implementation of
TxPacketSegurto retry transmission upon checksum failures.
- Efficient Polling: Optimized sensor reading cycles to avoid blocking the CPU.
- Bitwise Operations: Extensive use of bit masking for register configuration (NVIC, GPIO) to minimize memory footprint.
- Microcontroller: TI MSP432P401R (ARM Cortex-M4F)
- Actuators: Dynamixel AX-12A (Smart Serial Servos)
- Sensors: IR Distance Sensors (Sharp GP2Y0A21YK)
- Interface: Nokia 5110 LCD & Joystick Shield
- Import the source files (
.c,.h) into Code Composer Studio. - Ensure the target is set to
MSP432P401R. - Build and Flash via USB Debugger.
