LBP.Robot
0.5.0
dotnet add package LBP.Robot --version 0.5.0
NuGet\Install-Package LBP.Robot -Version 0.5.0
<PackageReference Include="LBP.Robot" Version="0.5.0" />
<PackageVersion Include="LBP.Robot" Version="0.5.0" />
<PackageReference Include="LBP.Robot" />
paket add LBP.Robot --version 0.5.0
#r "nuget: LBP.Robot, 0.5.0"
#:package LBP.Robot@0.5.0
#addin nuget:?package=LBP.Robot&version=0.5.0
#tool nuget:?package=LBP.Robot&version=0.5.0
LBP.Robot
Bonsai package for the Little Brain Project robot hardware I/O. Provides Source nodes that stream sensor data from the physical robot (cameras, raw UDP bytes) into a Bonsai workflow.
Objective
Bridge the LBP robot hardware to Bonsai. The robot carries two cameras (ESP32-CAM and Raspberry Pi Zero) and communicates over WiFi via UDP. This package wraps those streams into reactive IObservable<T> sequences so Bonsai workflows can consume camera frames and raw sensor bytes the same way they would consume any other Bonsai source.
Summary
| Node | Output | Transport |
|---|---|---|
UdpJpegStream |
FrameData (IplImage + metadata) |
UDP, chunked JPEG from ESP32-CAM |
RpiJpegStream |
IplImage |
UDP, single-frame JPEG from RPi Zero |
BmpStream |
Bitmap frame | HTTP, BMP image stream |
ReceiveBytes |
byte[] |
UDP generic datagram receiver |
ToUInt16Array |
byte[] |
UDP datagram receiver (uint16 payloads) |
How It Works
Camera streams
ESP32-CAM (UdpJpegStream) — The ESP32 breaks each JPEG frame into multiple UDP packets. Each packet header carries [frameId, totalChunks, chunkIndex]. The node reassembles all chunks for a given frameId into a complete JPEG byte array, decodes it with OpenCV CV.DecodeImage, and emits a FrameData (image + frame number). A "HELLO" datagram is sent to the ESP32 on startup to trigger streaming.
Raspberry Pi Zero (RpiJpegStream) — The RPi sends complete JPEG frames as single UDP packets (identified by 0xFF 0xD8 SOI magic bytes). A background task periodically sends a "hello" keepalive to maintain the stream. Each received frame is decoded with OpenCV and emitted as IplImage.
BMP HTTP stream (BmpStream / BmpVideoSource) — Polls an HTTP URL every 100 ms, downloads a BMP image, and fires NewFrame events through the AForge IVideoSource interface. BmpStream wraps this in a Bonsai VideoCapture so it integrates with standard Bonsai image processing nodes.
Generic UDP (ReceiveBytes / ToUInt16Array)
On subscribe, sends an optional connection message to the remote device, then opens a UDP listener. Every incoming datagram is emitted as byte[]. This is the generic channel for OSC-framed sensor data (/bumpers, /wencoders, /analogs, /gyro) — pair it with Bonsai.Osc.ReceiveMessage nodes downstream to decode the OSC payload.
Code Structure
LBP.Robot/
├── LBP.Robot.csproj # net472; deps: Bonsai.Core, OpenCV.Net, AForge, Bonsai.Video
├── UdpJpegStream.cs # Source<FrameData> — ESP32-CAM chunked JPEG receiver
├── RpiJpegStream.cs # Source<IplImage> — RPi Zero JPEG receiver + keepalive
├── BmpStream.cs # VideoCapture — HTTP BMP stream Bonsai node
├── BmpVideoSource.cs # IVideoSource — AForge polling worker thread
├── ReceiveBytes.cs # Source<byte[]> — generic UDP datagram listener
├── ToUInt16Array.cs # Source<byte[]> — UDP listener (uint16 payloads)
└── FrameMetadata.cs # data class — carries FrameNumber per frame
Dependencies
| Package | Version | Role |
|---|---|---|
| Bonsai.Core | 2.9.0 | Source<T>, IObservable, combinator attributes |
| OpenCV.Net | 3.4.2 | JPEG decoding → IplImage |
| AForge.Video | 2.2.5 | IVideoSource / worker thread for BmpStream |
| Bonsai.Video | 2.5.0 | VideoCapture base class for BmpStream |
| Bonsai.Osc | 2.9.0 | OSC framing used by downstream workflow nodes |
Integration with the rest of LBP
- Camera → LBP.Torch:
RpiJpegStreamorUdpJpegStreamproduceIplImageframes. Feed them throughBonsai.Visiontransforms (resize, convert, normalize) and then intoLBP.Torch.ToTensorto produce aTensorfor the neural network forward pass. - Sensor bytes → OSC → brain:
ReceiveBytesfeeds raw bytes toBonsai.Osc.ReceiveMessage. Decoded OSC values (/analogs,/bumpers) can be assembled into tensors viaLBP.Torch.ToTensoror scalar expressions and routed to the network. - Motor commands → robot: Motor outputs from the neural network are sent back to the robot via standard Bonsai
SendMessageUDP nodes using the/wheelsOSC address. - Simulation drop-in: When using the Python 2D or MuJoCo 3D simulator instead of the real robot, the workflow does not use
LBP.Robotnodes at all — OSC messages are sent/received over the same ports.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET Framework | net472 is compatible. net48 was computed. net481 was computed. |
-
.NETFramework 4.7.2
- AForge (>= 2.2.5)
- AForge.Video (>= 2.2.5)
- AForge.Video.DirectShow (>= 2.2.5)
- Bonsai.Core (>= 2.9.0)
- Bonsai.Osc (>= 2.9.0)
- Bonsai.Video (>= 2.5.0)
- OpenCV.Net (>= 3.4.2)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.