# K2Aley GAR-BOT RP5 Local AI Agent

Copyright (c) 2026 K2Aley. GAR-BOT. All rights reserved.

This is the local Raspberry Pi 5 agent for GAR-BOT. It runs offline by default
and exposes a small HTTP API for the 7 inch touchscreen, voice path, LoRa bridge,
or remote control software.

## Safety Default

`hardware_enabled` is `false` in `config/gar_bot_agent.json`. In this mode the
agent logs commands but does not move motors or claws.

Set it to `true` only after:

- GAR-BOT is raised off the ground.
- Main fuse and E-stop are installed.
- Motor wiring is checked.
- Claw controller boards are covered.
- No electronics are exposed for wet use.

## Install On Raspberry Pi 5

Copy this `rp5_ai_agent` folder to the Pi, then run:

```bash
cd rp5_ai_agent
chmod +x scripts/install_on_rp5.sh
./scripts/install_on_rp5.sh
sudo systemctl start gar-bot-agent
```

For the GAR-BOT RP5 account:

```bash
GAR_BOT_USER=gar-bot ./scripts/install_on_rp5.sh
```

From this Windows project folder, you can also push it directly:

```powershell
.\scripts\deploy_from_windows.ps1 -HostName 192.168.0.226 -UserName gar-bot
```

## User Service Without Sudo

If sudo is not available yet, run the agent as the `gar-bot` user:

```bash
mkdir -p ~/.config/systemd/user
cp ~/rp5_ai_agent/systemd/gar-bot-agent.user.service ~/.config/systemd/user/gar-bot-agent.service
systemctl --user daemon-reload
systemctl --user enable --now gar-bot-agent.service
```

Status:

```bash
systemctl --user status gar-bot-agent.service
curl http://127.0.0.1:8080/status
```

To make the user service start before login after reboot, run this once with
sudo access:

```bash
sudo loginctl enable-linger gar-bot
```

## Test Without Moving Hardware

```bash
python3 -m venv .venv
. .venv/bin/activate
pip install -r requirements.txt
python -m gar_bot_agent.app --config config/gar_bot_agent.json --once "status"
python -m gar_bot_agent.app --config config/gar_bot_agent.json --once "open left claw"
python -m gar_bot_agent.app --config config/gar_bot_agent.json --once "stop"
```

## HTTP API

Start:

```bash
python -m gar_bot_agent.app --config config/gar_bot_agent.json
```

Status:

```bash
curl http://localhost:8080/status
```

Command:

```bash
curl -X POST http://localhost:8080/command \
  -H "Content-Type: application/json" \
  -d '{"text":"open both claws"}'
```

Emergency stop:

```bash
curl -X POST http://localhost:8080/stop
```

## Supported Local Commands

- `stop`
- `forward`
- `reverse`
- `left`
- `right`
- `open left claw`
- `open right claw`
- `open both claws`
- `close left claw`
- `close right claw`
- `home both claws`

## Hardware Map

Motor GPIO pins match `GAR-BOT_CONNECTIONS.md`.

Claws:

- `Claw Left 1`: `/dev/ttyACM0`
- `Claw Right 2`: `/dev/ttyACM1`

RP5 USB ports:

- USB 1: left claw board
- USB 2: right claw board
- USB 3: 7 inch touchscreen
- USB 4: LoRa/radio USB bridge or powered hub if needed

Pico Voice uses the RP5 40-pin header, not USB. FT232RL USB-TTL is removed from
the active RP5 USB plan.

The Keyestudio claw serial protocol is left as a safe placeholder until the
exact board firmware command format is confirmed.

## Optional Local LLM

The agent can use a local Ollama-compatible model as a command classifier. It
still cannot drive hardware directly; it only maps natural language into the
approved command list.

In `config/gar_bot_agent.json`:

```json
"ollama_enabled": true,
"ollama_model": "llama3.2:1b"
```

Keep `hardware_enabled` false while testing the model.
