Software Architecture Overview:
Two-Arduino architecture: Brain (high-level control) + Spinal Chord (motor execution).
Clear separation of concerns: Brain decides what to do, Spinal Chord decides how to move the wheels.
3-bit command protocol: Brain sends compact motion commands (0–7) to Spinal Chord.
Closed-loop behavior: Brain uses IR and ultrasonic sensing to react to the environment and drive the state machine.
Brain Arduino Responsibilities:
Sensor fusion: reads 4 IR sensors (start/end lines) + 2 ultrasonic rangefinders.
Actuation control: drives 2 servos (gates) and sends 3-bit motor commands.
State machine: implements full autonomous sequence as a finite-state machine.
Safety & robustness: verification states, end-line re-check, and global timeout
Spinal Chord Arduino Responsibilities:
Motor driver interface: controls 4 omniwheel motors via two L298N H-bridges.
Command decoding: reads 3 digital inputs and maps them to 7 movement primitives.
Inertia management: inserts a short braking pause on every direction change.
Motor balancing: per-wheel PWM scaling to compensate for mechanical differences.
Brain State Machine:
Core loop: readSensors() → runStateMachine() on every iteration.
State-based logic: each state has its own handler function (easier to modify and debug).
Main phases: orient to start line → navigate course → deploy mechanism → reposition → loop.
Transitions: driven by sensor thresholds and precise timers (ms).
Spinal Chord motor control details:
Single loop: always updateSpeed(), readCommand(), manageStateTransitions(), executeMovement().
Non-blocking braking: 10 ms brake window implemented with isBraking flag, no delays.
Omniwheel patterns: specific IN1/IN2 combinations for forward, backward, strafe, and rotation.
Speed tuning: PWM and per-motor scale factors adjusted empirically to get straight motion.
Modularity and future extensions:
Function-per-state: easy to insert new behaviors (e.g., obstacle avoidance, new mission phases).
Config via constants: thresholds, distances, and timings can be tuned without touching logic.
Decoupled controllers: Brain logic can evolve (e.g. higher-level planner) without touching motor driver code.
Testing strategy: each state and movement can be tested individually by forcing starting states.