2  Line Following Robot Operation

The robot’s operation is divided into two distinct configuration levels: build-time configuration through software compilation and runtime operation of RoboZero.

At build time, critical parameters are set through compilation flags and constants. The DEBUG_LEVEL flag determines the robot’s operational mode: normal operation (0), analysis mode (1), or speed mode (2). Each mode compiles with different features and behaviors. Other build-time configurations include PID default constants, sensor weights, speed profiles, and timing parameters. These decisions fundamentally shape the robot’s behavior and available features.

During runtime operation, the robot’s functioning begins with a calibration phase, essential for adapting to varying lighting conditions and surface characteristics. Upon powering up, the robot waits for the first button press, which initiates the calibration sequence. During calibration, the robot samples each of its six line sensors multiple times, establishing minimum and maximum values for each sensor. These values create a baseline for converting raw sensor readings into meaningful position data.

After calibration, the robot waits for a second button press to begin its line following operation. The six-sensor array continuously reads the line position, with the outer sensors serving as markers for extreme deviations and the inner sensors providing precise positioning data. Each sensor reading is normalized using the calibration data and weighted based on its position in the array. The weighted average of these readings determines the robot’s position relative to the line.

The control system operates on a continuous loop, processing sensor data and adjusting motor outputs. A PID (Proportional-Integral-Derivative) controller calculates the necessary corrections based on the line position error - the difference between the current position and the desired center position. The proportional component provides immediate response to position errors, while the derivative component helps predict and dampen oscillations, resulting in smooth motion.

Speed control is managed dynamically based on the current situation. In straight sections, the robot can maintain higher speeds, while curves require speed adjustment for stability. The system includes a boost mechanism that temporarily increases speed when exiting curves to optimize lap times. The operating mode, determined at build time, affects the available speed ranges and control parameters.

Course markers on the track trigger specific behaviors. The robot can detect intersections, lap markers, and mode-change markers using dedicated marker sensors. When passing over these markers, the robot adjusts its operation accordingly - counting laps, changing speeds, or preparing to stop. The system is designed to complete a configurable number of laps before automatically stopping.

If compiled with debugging enabled (DEBUG_LEVEL > 0), the logging system operates continuously during the robot’s operation. In analysis mode, it captures detailed performance data including line position, error values, motor speeds, and PID corrections. This data is temporarily stored in circular buffers and written to flash memory when safe conditions are met - typically during straight sections where precise control is less critical. The system also records significant events such as marker detections, mode changes, and lap completions.

When the programmed number of laps is completed, the robot enters its stopping sequence. It gradually reduces speed to ensure controlled deceleration and precise stopping. After stopping, if debugging is enabled, the collected performance data remains stored in flash memory, ready for retrieval and analysis.

Data retrieval, available only in debug builds, occurs through a USB interface when the robot is stationary. Upon receiving the appropriate command through the serial interface, the robot transmits its stored data in a structured format, including session headers, performance records, event logs, and lap statistics. This data can then be analyzed to optimize the robot’s parameters such as PID constants, speed profiles, and acceleration rates.

The entire system prioritizes real-time performance while ensuring data collection doesn’t interfere with the robot’s primary line-following function. Error checking and recovery mechanisms are implemented throughout the system, from sensor reading validation to data storage verification, ensuring reliable operation even under challenging conditions.

2.1 Operating Procedure

2.1.1 Initial Setup

  1. Place the robot near the course
  2. Power on the robot
  3. Wait for initial setup delay (600ms)
    • Status LED will be on during this period
    • Motors will be inactive
  4. After delay, LED turns off and robot is ready for calibration

2.1.2 Calibration Process

  1. Press the start button for first calibration phase
    • LED will turn on
  2. The calibration process:
    • Takes 400 samples from each sensor
    • 30ms delay between samples (total ~12 seconds)
    • Establishes minimum and maximum values for each sensor
  3. After calibration completes:
    • LED turns off
    • Robot waits for second button press

2.1.3 Operation Start

  1. Place robot on the track
  2. Press start button again to begin operation
    • LED turns on
    • Robot starts line following operation
  3. Initial operating parameters:
    • Speed mode begins at BASE_FAST (115)
    • PID control active with default parameters
    • Normal operating mode engaged

2.1.4 During Operation

The robot recognizes three marker patterns: 1. Finish line marker (both sensors) - Updates lap count - Triggers stop sequence on second detection 2. Speed mode marker (left sensor only) - Toggles between normal and precision mode - In precision mode: SPEED_SLOW - In normal mode: BASE_FAST 3. Intersection marker (both sensors) - Logged but no special action taken

2.1.5 Stop Sequence

The robot will stop automatically when: 1. Second finish line is detected 2. Stop sequence activates: - Speed reduces to SPEED_BRAKE - After 50ms deceleration - Final stop after 300ms - Motors power off

2.1.6 Data Retrieval (Debug Mode Only)

If DEBUG_LEVEL > 0: 1. When robot stops, flash memory is marked as ready 2. LED displays transmission pattern: - Alternates between slow blink (1000ms) and fast blink (300ms) - Pattern switches every 3000ms 3. Data can be retrieved through serial interface 4. After successful transmission: - Log ready flag is cleared - LED pattern stops

2.1.7 Error Recovery

If line is lost: 1. Robot uses last valid position 2. Position is forced to extreme (-100 or 100) based on last direction 3. PID controller attempts to recover 4. Robot continues operation if line is found

2.1.8 Operating Modes

Two base operating speeds: 1. Normal Mode (BASE_FAST): - Base speed of 115 - Curve speed reduction active - Boost after curves (if not in precision mode)

  1. Precision Mode:
    • Activated by left marker
    • Uses SPEED_SLOW
    • Disables boost feature
    • More conservative operation

Debug Operating Modes (if DEBUG_LEVEL > 0): 1. Analysis Mode (DEBUG_LEVEL = 1): - 5 laps - Conservative speeds - Full data logging

  1. Speed Mode (DEBUG_LEVEL = 2):
    • 3 laps
    • Maximum performance
    • Full data logging