helva-robot/README.md

6.3 KiB

Helva Roboter

We build a robot with raspberry and arduino.

Checkout Repo

cd /opt
git checkout https://git.dyn.mcf.at/Max/helva-robot.git

Raspberry Face

Install Packages

sudo apt update
sudo apt install -y nginx python3 python3-venv

sudo mkdir -p /opt/face
sudo chown -R $USER:$USER /opt/face

python3 -m venv /opt/face/venv
/opt/face/venv/bin/pip install --upgrade pip
/opt/face/venv/bin/pip install fastapi uvicorn netifaces

Exchange Nginx Web-Folder

sudo rm -r /var/www/html
sudo ln -s /opt/helva-robot/face/var/www/html/ /var/www/

Permissions of Webfolder

sudo chown -R www-data:www-data /var/www/html

Nginx Vhost

sudo ln -s /opt/helva-robot/face/etc/nginx/sites-available/face /etc/nginx/sites-enabled/

Restart nginx

sudo systemctl restart nginx

Test Face Server

In Browser

http://pi-ip/

From Somewhere

Neutral + wander

curl -X POST http://<pi>/api/state -H "Content-Type: application/json" \
  -d '{"emotion":"neutral","intensity":0.6,"look":null}'

Angry + starring right

curl -X POST http://<pi>/api/state -H "Content-Type: application/json" \
  -d '{"emotion":"angry","intensity":0.9,"look":{"x":0.9,"y":0.0}}'

start Talking

curl -X POST http://<pi>/api/state -H "Content-Type: application/json" \
  -d '{"talk":{"enabled":true}}'

talk faster and stronger

curl -X POST http://<pi>/api/state -H "Content-Type: application/json" \
  -d '{"talk":{"enabled":true,"rate_hz":5.5,"amount":1.0,"jitter":0.35}}'

stop talking

curl -X POST http://<pi>/api/state -H "Content-Type: application/json" \
  -d '{"talk":{"enabled":false}}'

emotion + talk

curl -X POST http://<pi>/api/state -H "Content-Type: application/json" \
  -d '{"emotion":"happy","intensity":0.85,"talk":{"enabled":true,"rate_hz":4.2,"amount":0.95}}'

blink + happy

curl -X POST http://<pi>/api/state -H "Content-Type: application/json" \
  -d '{"emotion":"happy","blink":true,"intensity":0.85}'

systemd Services

sudo ln -s /opt/helva-robot/face/etc/systemd/system/face.service /etc/systemd/system/
sudo ln -s /opt/helva-robot/face/etc/systemd/system/redirect_to_tethering.service /etc/systemd/system/

sudo chown -R www-data:www-data /opt/face/*.py
sudo chmod -R 755 /opt/face/*.py

Start:

sudo systemctl daemon-reload
sudo systemctl enable --now face.service
sudo systemctl status face.service --no-pager

Face Control UI

http://localhost/control/

Debug Face

SSE-Stream going to browser?

curl -N http://127.0.0.1:8001/events | head

is nginx delivering /events through

curl -N http://localhost/events | head

check Endpoint /api/state

directly curl -s -X POST http://127.0.0.1:8001/api/state
-H "Content-Type: application/json"
-d '{"emotion":"happy","intensity":0.9,"blink":true}' | jq

throught nginx curl -s -X POST http://localhost/api/state
-H "Content-Type: application/json"
-d '{"emotion":"happy","intensity":0.9,"blink":true}'

check python face server

sudo systemctl status face.service --no-pager
sudo journalctl -u face.service -n 50 --no-pager

restart/reload face server service

sudo systemctl daemon-reload
sudo systemctl restart face.service

check listening Port

sudo ss -ltnp | grep :8001

restart/status of face service

sudo systemctl restart face.service
sudo systemctl status face.service --no-pager

Arduino Motor Steering

Pin assignment Arduino -> 2 pcs Motor-Driver-Boards (BTS7960)

  • one BTS7960 is for the two left 12V DC motors in parallel
  • one BTS7960 is for the two right 12V DC Motors

Caution! This drivers only work for DC Motors. For stepper motors you will need different motor drivers.

Left BTS#1

Power

  • VCC -> Arduino 5V
  • GND -> Arduino GND

Steering - NEVER activate both directions at once!!!

  • RPWM -> Arduino D5 (PWM)
  • LPWM -> Arduino D6 (PWM)

Enabled - either directly 5V or steer it from arduino

  • R_EN -> Arduino D7
  • L_EN -> Ardiono D8

Right BTS#2

Power

  • VCC -> Arduino 5V
  • GND -> Arduino GND

Steering - NEVER activate both directions at once!!!

  • RPWM -> Arduino D9 (PWM)
  • LPWM -> Arduino D10 (PWM)

Enabled - either directly 5V or steer it from arduino

  • R_EN -> Arduino D11
  • L_EN -> Ardiono D12

Arduino Steering Code

Upload to Arduino: drive/arduino-sketch/arduino-sketch.ino

Test with Arduino Serial Monitor

slow forward

f 60

slow backward

r 60

Web Control

For Web-UI-Controller you need to have access to the raspberry-pi i.e. via a hotspot on it.

Setup

ln -s /opt/helva-robot/drive/opt/drive-ctl/ /opt/
sudo chown -R www-data:www-data /opt/drive-ctl
sudo chmod -R 755 /opt/drive-ctl

sudo apt install -y python3-venv
python3 -m venv /opt/drive-ctl-venv

sudo chown -R $USER:$USER /opt/drive-ctl-venv
/opt/drive-ctl-venv/bin/pip install fastapi uvicorn pyserial

source /opt/drive-ctl-venv/bin/activate
pip install fastapi uvicorn pyserial

Configure Arduino-USB-ID

ls -l /dev/serial/by-id/ 2>/dev/null

Example Output

usb-1a86_USB2.0-Serial-if00-port0 -> ../../ttyUSB0

Watch USB devices while replugging

dmesg -T | tail -n 80

Configure the USB-Device-ID in /opt/helva-robot/drive/opt/drive-ctl/server.py

Activate Web Control Interface

sudo ln -s /opt/helva-robot/drive/etc/nginx/sites-available/drive /etc/nginx/sites-enabled/drive
sudo nginx -t && sudo systemctl reload nginx

Systemd Service for Backend

ln -s /opt/helva-robot/drive/etc/systemd/system/drive-ctl.service /etc/systemd/system/
sudo systemctl daemon-reload
sudo systemctl enable --now drive-ctl
sudo systemctl status drive-ctl --no-pager -l

Check Serial device is stable, otherwise create a udev rule

ls -l /dev/ttyACM0 /dev/ttyUSB0
dmesg | tail -n 50

Open Web Control UI

http://pi-ip/drive/

Debug drive-ctl WebUI

check local webservice

curl -s http://127.0.0.1:8002/health

should be -> {"ok": true, ... } -> otherwise look at the logs:

journalctl -u drive-ctl -n 80 --no-pager

Networking / AccessPoint / Captive Portal

see /network/ folder for config

Captive Portal

allows you to log into the raspi AP and you get automatically to the page of the roboter