返回资讯中心
外部精选
软件工程
#开发者实时流

开发者发布面向树莓派机器人的Python感知框架

来源标题:I created the perfect framework for hackers who want to experiment with hardware

开发者推出一个按感官组织的树莓派机器人Python框架,每项能力都是通过同一事件总线通信的模块。框架包含视觉、听觉、平衡、语音和行走模块,不含触觉、嗅觉和味觉;每类硬件都有模拟后端,可在笔记本上完整运行和测试。该框架在树莓派OS Bookworm(64位)上安装,语音模型需单独下载。

Hacker News 最新dario-fino2026/11/30 · 今天13 分钟阅读

以下正文同步自 Hacker News 最新,版权归原站所有,已转换为易读排版。

A Python framework for Raspberry Pi robots that is organised by the senses. Every capability is a module that talks over one event bus:

Touch, smell and taste are intentionally left out. Balance (the vestibular sense) is included because the dynamic gait needs it.

Every hardware piece has a simulated backend, so the whole stack runs and tests on a laptop.

┌───────────── EventBus (pub/sub, threaded) ─────────────┐ sight.* ◄────┤ Sight Hearing Balance Voice Walker ├────► servos hearing.* │ camera microphone IMU TTS / STT gait + IK│ balance.* └────────────────────────────────────────────────────────┘

Install

Do this on the Pi, with Raspberry Pi OS Bookworm (64-bit):

sudo apt install -y python3-picamera2 python3-opencv libportaudio2 espeak-ng alsa-utils i2c-tools sudo raspi-config nonint do_i2c 0 # enable I2C for the servo board and IMU python3 -m venv --system-site-packages .venv # system site packages so picamera2/opencv are visible source .venv/bin/activate pip install -e ".[all]" rairos info # shows which backends were found

Speech models are separate downloads:

On a laptop, pip install -e ".[dev]" and everything runs simulated.

rairos sim # simulated robot: type "walk forward", "trot gait", "stop" rairos gait --gait crawl --plot crawl.png # simulate a gait and plot footfalls + stability rairos run config/quadruped.yaml # run a real robot from a config file rairos say "hello world"

from rairos import Robot from rairos.senses import Sight, Hearing, Balance from rairos.voice import Voice from rairos.locomotion import Walker

robot = Robot("rex") robot.add(Sight(config={"detectors": ["face", "color:red"]})) robot.add(Hearing()) robot.add(Balance()) voice = robot.add(Voice(config={"wake_word": "robot", "stt_model": "~/models/vosk-model-small-en-us-0.15"})) walker = robot.add(Walker(config={"body": "quadruped", "gait": "crawl"}))

@voice.command("walk forward") def _(): walker.walk(vx=0.04)

@voice.command("turn {direction}") def _(direction): walker.walk(wz=0.4 if direction == "left" else -0.4)

@robot.bus.on("sight.face") def _(ev): voice.say("hello human")

robot.run_forever()

Walking gaits

rairos.locomotion gives you a 3-DOF leg model (coxa, femur, tibia) with analytic inverse kinematics, quadruped and hexapod body presets, and two kinds of gait. Both kinds take a body velocity command (vx, vy, wz), so they can walk forward, sideways and turn in place.

The centre of mass stays inside the support polygon at every instant, so the robot can freeze mid-step without falling.

These gaits let the centre of mass leave the support polygon. In a trot only a diagonal pair is down, and the robot stays up through rhythm and speed. Timing comes from a Central Pattern Generator: one Hopf oscillator per leg, coupled so that the oscillators lock into the gait's phase pattern. Calling walker.set_gait("pace") while trotting changes the coupling, and the oscillators re-synchronise in about 1.5 s without stopping.

Switching between a static and a dynamic gait works like this: the walker finishes its current steps, plants every foot, swaps the gait and then resumes the last command.

Topic Payload

sight.motion {"area", "boxes"}

sight.face {"faces", "center": (x, y)}. Centre is normalised to -1..1, with +x to the right and +y up

sight.color {"name", "center", "pixel", "radius", "area"}

hearing.audio np.int16 chunk (16 kHz mono)

hearing.level {"rms", "db", "pitch_hz"}

hearing.loud {"db"} (a clap or bang)

hearing.speech_start / hearing.speech_end None / {"duration"}

balance.attitude {"roll", "pitch", "roll_rate", "pitch_rate"}

balance.fall {"roll", "pitch"}. The walker halts when it sees this

voice.speaking True / False. Hearing mutes itself while this is True

voice.partial, voice.heard live and final transcripts

voice.wake, voice.command, voice.unknown the wake word was heard, a command matched, or nothing matched

walker.cmd ← {"vx", "vy", "wz"} to drive the walker from anywhere

walker.gait ←, walker.halt ←, walker.height ← control topics

walker.state {"gait", "static", "phase", "cmd", "idle", "margin", "height"} at 5 Hz

Hardware notes

Servos: a PCA9685 board at 0x40. A hexapod's 18 servos need a second board at 0x41 (bridge the A0 pad). Power the servos from a separate 5–6 V supply rated at several amps, never from the Pi's 5 V pin.

Calibration: the joint angle 0 is defined as the coxa pointing straight out, the femur horizontal and the tibia straight. Use servo_map in the YAML to set each joint's offset (the servo's degrees at joint angle 0) and its direction (-1 for a mirrored servo).

IMU: an MPU6050 on I²C bus 1 at 0x68. Mount it flat with x pointing forward. The conventions are roll > 0 when the left side is up, and pitch > 0 when the nose is down.

Audio: a USB mic plus a speaker, or a ReSpeaker HAT. Set hearing.device if the default input isn't the right one.

Extending

Subclass rairos.Module, implement setup(), step(dt) and teardown(), then registry.register("name", Cls) to make it usable from YAML. examples/custom_module.py shows how.

正文由 探How 从来源站点 RSS 同步,内容未经改写;遇到排版缺失或需要图片、视频时请以原文为准。

打开原文
去社区讨论 →