# jarrydstringy/linefollower-pid-control architecture

> Architecture diagram of the GitHub repository jarrydstringy/linefollower-pid-control, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-05). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/jarrydstringy/linefollower-pid-control
- Repository: https://github.com/jarrydstringy/linefollower-pid-control

## Overview

PIDControl is firmware for an AVR line-following robot. On startup, the main loop calibrates sensor ranges until a button press, then detects markers and estimates line position, applies PD-based steering, adjusts speed on straights, and stops at a counted marker. Motor PWM setup and ADC initialization are delegated to small hardware modules. The excerpts show the controller reading ADC registers directly as well as the sensor module exposing a read helper; unsampled hardware wiring is not inferred.

Main entry points: [`PIDControl.c`](https://github.com/jarrydstringy/linefollower-pid-control/blob/master/PIDControl.c) (Main loop), [`Sensors.c`](https://github.com/jarrydstringy/linefollower-pid-control/blob/master/Sensors.c) (ADC setup), [`Motors.c`](https://github.com/jarrydstringy/linefollower-pid-control/blob/master/Motors.c) (PWM setup)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_control["Robot Control"]
  node_controller["Main loop<br/>[PIDControl.c]"]
  node_calibration["Range calibration<br/>[PIDControl.c]"]
  node_line["Line position<br/>[PIDControl.c]"]
  node_markers["Marker detection<br/>[PIDControl.c]"]
  node_steering["PD steering<br/>[PIDControl.c]"]
end

subgraph group_sensing["Sensor Input"]
  node_sensor_init["ADC setup<br/>[Sensors.c]"]
  node_sensor_read["Sensor reader<br/>[Sensors.c]"]
end

subgraph group_motors["Motor Output"]
  node_motor_setup["PWM setup<br/>[Motors.c]"]
end

node_robot(("Robot operator"))
node_sensor_array["Eight line sensors"]
node_motor_hw["Motor PWM outputs"]

node_robot -->|"starts"| node_controller
node_controller -->|"calibrates"| node_calibration
node_controller -->|"initializes ADC"| node_sensor_init
node_controller -->|"sets up motors"| node_motor_setup
node_controller -->|"checks markers"| node_markers
node_controller -->|"estimates position"| node_line
node_controller -->|"applies correction"| node_steering
node_controller -->|"reads ADC"| node_sensor_array
node_calibration -->|"samples ranges"| node_sensor_array
node_markers -->|"samples sides"| node_sensor_array
node_line -->|"samples line"| node_sensor_array
node_sensor_read -->|"reads ADC"| node_sensor_array
node_sensor_init -->|"configures ADC"| node_sensor_array
node_steering -->|"sets PWM"| node_motor_hw
node_controller -->|"stops motors"| node_motor_hw
node_motor_setup -->|"configures PWM"| node_motor_hw

click node_controller "https://github.com/jarrydstringy/linefollower-pid-control/blob/master/PIDControl.c"
click node_calibration "https://github.com/jarrydstringy/linefollower-pid-control/blob/master/PIDControl.c"
click node_line "https://github.com/jarrydstringy/linefollower-pid-control/blob/master/PIDControl.c"
click node_markers "https://github.com/jarrydstringy/linefollower-pid-control/blob/master/PIDControl.c"
click node_steering "https://github.com/jarrydstringy/linefollower-pid-control/blob/master/PIDControl.c"
click node_sensor_init "https://github.com/jarrydstringy/linefollower-pid-control/blob/master/Sensors.c"
click node_sensor_read "https://github.com/jarrydstringy/linefollower-pid-control/blob/master/Sensors.c"
click node_motor_setup "https://github.com/jarrydstringy/linefollower-pid-control/blob/master/Motors.c"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_controller,node_calibration,node_line,node_markers,node_steering toneBlue
class node_sensor_init,node_sensor_read toneAmber
class node_motor_setup toneMint
class node_robot,node_sensor_array,node_motor_hw toneIndigo
```

## Components

### Robot Control

- [Main loop](https://github.com/jarrydstringy/linefollower-pid-control/blob/master/PIDControl.c): `PIDControl.c`
- [Range calibration](https://github.com/jarrydstringy/linefollower-pid-control/blob/master/PIDControl.c): `PIDControl.c`
- [Line position](https://github.com/jarrydstringy/linefollower-pid-control/blob/master/PIDControl.c): `PIDControl.c`
- [Marker detection](https://github.com/jarrydstringy/linefollower-pid-control/blob/master/PIDControl.c): `PIDControl.c`
- [PD steering](https://github.com/jarrydstringy/linefollower-pid-control/blob/master/PIDControl.c): `PIDControl.c`

### Sensor Input

- [ADC setup](https://github.com/jarrydstringy/linefollower-pid-control/blob/master/Sensors.c): `Sensors.c`
- [Sensor reader](https://github.com/jarrydstringy/linefollower-pid-control/blob/master/Sensors.c): `Sensors.c`

### Motor Output

- [PWM setup](https://github.com/jarrydstringy/linefollower-pid-control/blob/master/Motors.c): `Motors.c`

### Other components

- **Robot operator**
- **Eight line sensors**
- **Motor PWM outputs**

## Connections

- Robot operator → Main loop: starts (evidence: `README.md`)
- Main loop → Range calibration: calibrates (evidence: `PIDControl.c`)
- Main loop → ADC setup: initializes ADC (evidence: `PIDControl.c`)
- Main loop → PWM setup: sets up motors (evidence: `PIDControl.c`)
- Main loop → Marker detection: checks markers (evidence: `PIDControl.c`)
- Main loop → Line position: estimates position (evidence: `PIDControl.c`)
- Main loop → PD steering: applies correction (evidence: `PIDControl.c`)
- Main loop → Eight line sensors: reads ADC (evidence: `PIDControl.c`)
- Range calibration → Eight line sensors: samples ranges (evidence: `PIDControl.c`)
- Marker detection → Eight line sensors: samples sides (evidence: `PIDControl.c`)
- Line position → Eight line sensors: samples line (evidence: `PIDControl.c`)
- Sensor reader → Eight line sensors: reads ADC (evidence: `Sensors.c`)
- ADC setup → Eight line sensors: configures ADC (evidence: `Sensors.c`)
- PD steering → Motor PWM outputs: sets PWM (evidence: `PIDControl.c`)
- Main loop → Motor PWM outputs: stops motors (evidence: `PIDControl.c`)
- PWM setup → Motor PWM outputs: configures PWM (evidence: `Motors.c`)
