Project files
- car_brain13 files
- digital_twin10 files
- scripts1 file
- tests2 files
- tools12 files
- README.md4 KB
- requirements.txt1 KB
README.md
Machine-translated by Robotheca from the original in Chinese (opens in a new tab). License: MIT (opens in a new tab).
Brain Project (Raspberry Pi / Desktop)
The brain of Ganbei No. 1 β responsible for AI interaction, decision-making, and communication with the cerebellum.
Cross-platform: Python code runs the same set on Windows development and Raspberry Pi (Linux) deployment.
Architecture
car_brain/
βββ protocol/ Protocol module
β βββ crc8.py CRC8 checksum (consistent with Arduino side)
β βββ commands.py Command constants (consistent with Arduino side commands.h)
β βββ frame.py Frame packaging / parsing
βββ serial_link.py Serial communication layer (frame transmission and reception)
βββ brain.py Brain state machine (state view / heartbeat / button decision)
βββ app.py CLI entry point
tests/
βββ test_protocol.py Protocol unit tests
βββ test_brain_loop.py BrainβCerebellum memory joint debugging tests
Installation
pip install -r requirements.txt # Requires pyserial
Running Tests
# Protocol unit tests + brainβcerebellum joint debugging tests
python -m unittest discover -s tests -v
test_brain_loop.py uses two threads and memory pipes to simulate the complete "brain β cerebellum" conversation,
allowing protocol loopback verification without any hardware.
Running the Demo
Method 1: Connect to a Real/Virtual Serial Port
# Windows real serial port
python -m car_brain.app --port COM3 --demo
# Linux / Raspberry Pi
python -m car_brain.app --port /dev/ttyAMA0 --demo
Method 2: Directly drive the native cerebellum (no serial port required, recommended for joint debugging)
First, compile the native cerebellum program (see firmware/arduino/README.md), then let the brain drive it via stdin/stdout pipes:
python -m car_brain.app --native ../firmware/arduino/.pio/build/native/program.exe --demo
This way, you don't need to install com0com virtual serial ports on Windows to see the complete two-way conversation.
ποΈ Voice Control (Offline Recognition with VOSK)
Wake up by saying "Ganbei chulai" (cheers) into the microphone, then give a command; or say everything in one go (e.g., "Ganbei chulai turn on the light").
Supported commands: turn on the headlights / turn off the lights / mute / unmute / level one to four / emergency stop.
Preparation (one-time)
# 1. Create a Python 3.13 virtual environment (system 3.14 may not fully support speech libraries)
py -3.13 -m venv .venv
# 2. Install dependencies
.venv\Scripts\python.exe -m pip install -r requirements.txt
# 3. Download the VOSK Chinese model (~42MB) and extract it to the user directory:
# https://alphacephei.com/vosk/models/vosk-model-small-cn-0.22.zip
# The extracted directory should be ~/vosk-model-small-cn-0.22
# Alternatively, set the environment variable VOSK_MODEL to point to the model directory
Running Voice Control
.venv\Scripts\python.exe -m car_brain.app --native <cerebellum_exe_path> --voice --seconds 120
A microphone is required. Voice recognition is offline and does not require an internet connection. On Windows, it will say "I'm listening, please give a command" as voice feedback.
How to Add / Remove Commands
The "list" of commands is in the COMMAND_RULES table in car_brain/voice.py (each line = one group of synonyms + command):
COMMAND_RULES = (
(("turn on the headlights", "turn on the lights", "turn on the light", "lights on"), ("light", "on")), # synonyms β command
(("brake", "emergency brake", "stop"), ("ebrk", None)),
)
- Add synonyms: Simply add words to the keyword tuple in the corresponding line
- Add new commands, reuse existing actions: Add a new line and use an existing command name (e.g.,
strip) - Add completely new actions: Add a new line + add a processing branch in
on_voice_commandincar_brain/app.py; if a new protocol command is needed, also add a method incar_brain/brain.py - Delete commands: Simply delete the corresponding line
Changing the TTS Voice
Set the environment variable TTS_VOICE (default: zh-CN-XiaoxiaoNeural ζζ):
set TTS_VOICE=zh-CN-YunxiNeural # Yunxi (male voice)
set TTS_VOICE=zh-CN-XiaoyiNeural # Xiaoyi (female voice)
Options: XiaoxiaoNeural (ζζ) / YunxiNeural (δΊεΈ) / YunyangNeural (δΊζ¬) / XiaoyiNeural (ζδΌ).
Directory Planning (Future Iterations)
audio/ββ Engine sound synthesis + audio managementcloud/ββ 4G communication / MQTT / app integrationgps/ββ Location reporting
Files by @RevolutionLA, at commit a7b0c9d, read from GitHub in your browser. Hardware license: MIT; software license: MIT. Robotheca doesn't review code: read it before running it.