Skip to content

marcsanz-dev/MSP432-Autonomous-Maze-Solver

Repository files navigation

🤖 MSP432 Autonomous Maze Solver

C Hardware Algorithms

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.


🎥 Demo

(The robot continuously adjusts its distance to the wall using P-Control logic)


🧠 Algorithmic Logic (Flowcharts)

1. Main Control Loop & State Machine

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
Loading

2. Wall Following Logic (Right Hand Rule)

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
Loading

🏗️ Technical Architecture

1. Hardware Abstraction Layer (HAL)

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.

2. Custom Protocol Implementation

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 TxPacketSegur to retry transmission upon checksum failures.

3. Memory & Resource Management

  • 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.

🛠️ Hardware Stack

  • 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

💻 How to Flash

  1. Import the source files (.c, .h) into Code Composer Studio.
  2. Ensure the target is set to MSP432P401R.
  3. Build and Flash via USB Debugger.

About

Autonomous Maze-Solving Robot powered by MSP432 (ARM Cortex-M4F). Written in C with a custom HAL, implementing Real-Time Proportional Control algorithms and a byte-level UART driver for Dynamixel motors.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors