# terrencelei/autonomous-shopping-cart architecture

> Architecture diagram of the GitHub repository terrencelei/autonomous-shopping-cart, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-11-22). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/terrencelei/autonomous-shopping-cart
- Repository: https://github.com/terrencelei/autonomous-shopping-cart

## Overview

This repository is an autonomous shopper-following cart: camera detections are converted into target distance and angle, the Pi follower computes wheel commands, and ESP32 firmware drives the motors and reports encoder counts. A separate straight-line follower shares vision and motor protocol; vision also has a color-vector collection and weight-training branch. The main follower, vision, and tooling excerpts support these boundaries; firmware behavior and some subsystem details are represented only by README statements, so those links cite the README.

Main entry points: [`vision/yolo_detect.py`](https://github.com/terrencelei/autonomous-shopping-cart/blob/main/vision/yolo_detect.py) (Detection and tracking), [`follow.py`](https://github.com/terrencelei/autonomous-shopping-cart/blob/main/follow.py) (Serial motor I/O), [`follow_straight.py`](https://github.com/terrencelei/autonomous-shopping-cart/blob/main/follow_straight.py) (Straight follower), [`firmware/cart_motor/cart_motor.ino`](https://github.com/terrencelei/autonomous-shopping-cart/blob/main/firmware/cart_motor/cart_motor.ino) (ESP32 motor controller)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_sensing["Vision and tracking"]
  node_vision["Detection and tracking<br/>[yolo_detect.py]"]
end

subgraph group_control["Cart following"]
  node_follow["Reactive follower<br/>[follow.py]"]
  node_straight["Straight follower<br/>[follow_straight.py]"]
  node_motorio["Serial motor I/O<br/>[follow.py]"]
  node_control_logic["Damped control and odometry<br/>[follow.py]"]
  node_straight_logic["Distance controller<br/>[follow_straight.py]"]
end

subgraph group_hardware["Motor hardware"]
  node_esp["ESP32 motor controller<br/>[cart_motor.ino]"]
  node_motors(("Drive motors and encoders"))
end

subgraph group_reid["Color re-identification tools"]
  node_collector["Color-vector collector<br/>[collect_vectors.py]"]
  node_vectors[("Labeled color vectors<br/>[vectors.csv]")]
  node_trainer["Re-identification trainer"]
  node_weights["HSV chunk weights"]
end

node_shopper(("Designated shopper"))
node_camera(("IMX500 camera"))

node_shopper -->|"appears before"| node_camera
node_camera -->|"provides frames and detections"| node_vision
node_vision -->|"supplies target and obstacles"| node_follow
node_follow -->|"computes wheel demands"| node_control_logic
node_follow -->|"sends commands and reads feedback"| node_motorio
node_motorio -->|"sends RPM commands"| node_esp
node_esp -->|"returns encoder counts"| node_motorio
node_esp -->|"drives and reads"| node_motors
node_straight -->|"imports tracking"| node_vision
node_straight -->|"computes distance demand"| node_straight_logic
node_straight -->|"uses serial protocol"| node_motorio
node_collector -->|"captures detections"| node_camera
node_collector -->|"appends labeled profiles"| node_vectors
node_trainer -->|"loads training data"| node_vectors
node_trainer -->|"writes weights"| node_weights
node_weights -.->|"optional inference calibration"| node_vision

click node_vision "https://github.com/terrencelei/autonomous-shopping-cart/blob/main/vision/yolo_detect.py"
click node_follow "https://github.com/terrencelei/autonomous-shopping-cart/blob/main/follow.py"
click node_straight "https://github.com/terrencelei/autonomous-shopping-cart/blob/main/follow_straight.py"
click node_motorio "https://github.com/terrencelei/autonomous-shopping-cart/blob/main/follow.py"
click node_control_logic "https://github.com/terrencelei/autonomous-shopping-cart/blob/main/follow.py"
click node_straight_logic "https://github.com/terrencelei/autonomous-shopping-cart/blob/main/follow_straight.py"
click node_esp "https://github.com/terrencelei/autonomous-shopping-cart/blob/main/firmware/cart_motor/cart_motor.ino"
click node_collector "https://github.com/terrencelei/autonomous-shopping-cart/blob/main/vision/collect_vectors.py"
click node_vectors "https://github.com/terrencelei/autonomous-shopping-cart/blob/main/vision/vectors.csv"
click node_trainer "https://github.com/terrencelei/autonomous-shopping-cart/blob/main/vision/vision_weight_trainer.py"
click node_weights "https://github.com/terrencelei/autonomous-shopping-cart/blob/main/vision/weights_by_hsv_chunk.csv"

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_vision toneBlue
class node_follow,node_straight,node_motorio,node_control_logic,node_straight_logic toneAmber
class node_esp,node_motors toneMint
class node_collector,node_vectors,node_trainer,node_weights toneRose
class node_shopper,node_camera toneIndigo
```

## Components

### Vision and tracking

- [Detection and tracking](https://github.com/terrencelei/autonomous-shopping-cart/blob/main/vision/yolo_detect.py): `vision/yolo_detect.py`

### Cart following

- [Reactive follower](https://github.com/terrencelei/autonomous-shopping-cart/blob/main/follow.py): `follow.py`
- [Straight follower](https://github.com/terrencelei/autonomous-shopping-cart/blob/main/follow_straight.py): `follow_straight.py`
- [Serial motor I/O](https://github.com/terrencelei/autonomous-shopping-cart/blob/main/follow.py): `follow.py`
- [Damped control and odometry](https://github.com/terrencelei/autonomous-shopping-cart/blob/main/follow.py): `follow.py`
- [Distance controller](https://github.com/terrencelei/autonomous-shopping-cart/blob/main/follow_straight.py): `follow_straight.py`

### Motor hardware

- [ESP32 motor controller](https://github.com/terrencelei/autonomous-shopping-cart/blob/main/firmware/cart_motor/cart_motor.ino): `firmware/cart_motor/cart_motor.ino`
- **Drive motors and encoders**

### Color re-identification tools

- [Color-vector collector](https://github.com/terrencelei/autonomous-shopping-cart/blob/main/vision/collect_vectors.py): `vision/collect_vectors.py`
- [Labeled color vectors](https://github.com/terrencelei/autonomous-shopping-cart/blob/main/vision/vectors.csv): `vision/vectors.csv`
- [Re-identification trainer](https://github.com/terrencelei/autonomous-shopping-cart/blob/main/vision/vision_weight_trainer.py): `vision/vision_weight_trainer.py`
- [HSV chunk weights](https://github.com/terrencelei/autonomous-shopping-cart/blob/main/vision/weights_by_hsv_chunk.csv): `vision/weights_by_hsv_chunk.csv`

### Other components

- **Designated shopper**
- **IMX500 camera**

## Connections

- Designated shopper → IMX500 camera: appears before (evidence: `README.md`)
- IMX500 camera → Detection and tracking: provides frames and detections (evidence: `README.md`)
- Detection and tracking → Reactive follower: supplies target and obstacles (evidence: `README.md`)
- Reactive follower → Damped control and odometry: computes wheel demands (evidence: `follow.py`)
- Reactive follower → Serial motor I/O: sends commands and reads feedback (evidence: `follow.py`)
- Serial motor I/O → ESP32 motor controller: sends RPM commands (evidence: `README.md`)
- ESP32 motor controller → Serial motor I/O: returns encoder counts (evidence: `README.md`)
- ESP32 motor controller → Drive motors and encoders: drives and reads (evidence: `README.md`)
- Straight follower → Detection and tracking: imports tracking (evidence: `follow_straight.py`)
- Straight follower → Distance controller: computes distance demand (evidence: `follow_straight.py`)
- Straight follower → Serial motor I/O: uses serial protocol (evidence: `follow_straight.py`)
- Color-vector collector → IMX500 camera: captures detections (evidence: `vision/collect_vectors.py`)
- Color-vector collector → Labeled color vectors: appends labeled profiles (evidence: `vision/collect_vectors.py`)
- Re-identification trainer → Labeled color vectors: loads training data (evidence: `vision/vision_weight_trainer.py`)
- Re-identification trainer → HSV chunk weights: writes weights (evidence: `vision/vision_weight_trainer.py`)
- HSV chunk weights → Detection and tracking: optional inference calibration
