PiCrawler / Program the Robot
Program the Robot
Use Windows VS Code to edit a Python file on the Pi, run it there and read the output.
Your Windows computer runs VS Code. The Raspberry Pi runs the Python program under Linux. Unlike the Mega workflow, you save a file on the Pi and run it there; there is no PlatformIO Build/Upload step.
Connect VS Code
Complete Start Here first: establish plain SSH, preserve the original installation and calibration, and run the passive Python check. Remote SSH installs a VS Code server on the Pi, so it comes after preservation.
- On Windows, install Microsoft's Remote - SSH extension in VS Code.
- Press Ctrl+Shift+P, choose Remote-SSH: Connect to Host…, and enter the same verified
user@hostused for plain SSH. Select Linux if asked. - Choose File → Open Folder… and open
~/engineering-club-picrawleron the Pi, where you savedpi_identity.py. If you chose another folder, open that one. Confirm VS Code's remote indicator names the intended Pi.
Edit one Python file
Open pi_identity.py in the remote window. Add this line at the end, then save with Ctrl+S:
Python · pi_identity.py on the Pi
print("Engineering Club: Python is running on the Pi")Keep club scripts separate from vendor checkouts and installed libraries. Do not call a file picrawler.py, robot_hat.py, vilib.py or a standard-library module name: it can hide the intended module. Begin with this one file; add structure when a real experiment needs it.
Run it on the Pi
In that remote VS Code window, choose Terminal → New Terminal. This terminal runs on the Pi. In the Pi Linux shell, confirm the folder and run the file:
Pi Linux shell
pwd
python3 pi_identity.pyUse the same recovered interpreter as in Start Here. If the Python extension is installed, select that interpreter with Python: Select Interpreter too; the shell command must still name the correct executable.
The identity lines should appear again, followed by:
Engineering Club: Python is running on the PiThis is expected output for your added line, not evidence that the club robot has been tested. If it is absent, save the remote file and check the terminal's working folder and interpreter. Installing a package on Windows does not install it on the Pi.
Continue to hardware
Return to the passive program if the environment is unclear. A missing package is a reason to inspect the recovered installation, not to use privileged pip installs, blind upgrades or a new SD image as a default fix.
For a first live experiment, use the recovery qualification checklist. Import only the reviewed subsystem after its gates; a crawler constructor can command servos, and a camera import can initialize capture. Keep a supervised cutoff available: a debugger pause or disconnected SSH session does not stop PWM output.
Find functions in the Source/API lookup, or browse Projects & Experiments for proposals. Optional environment, reproducibility and architecture research remains below. VS Code's Remote SSH documentation explains the editor connection.
Reference: user python workflow
A clean normal development workflow
Use a dedicated Pi-side project such as ~/engineering-club-picrawler/. Keep recovered vendor checkouts and installed packages intact. A sensible future layout is README/environment notes; src/club_crawler/main.py; behaviors/movement.py, vision.py, sensors.py; diagnostics/; experiments/; config/; trajectories/; and ignored logs/. These are design locations, not a newly authored robot framework. Start with one script and extract modules only as reuse appears.
Where code executes
VS Code Remote SSH shows an editor on the laptop while its remote terminal and Python execute on the Pi. After V1 preservation, connect using the actually verified account/host, open the club folder and select the exact Pi interpreter. Saving writes the Pi file. Running a Windows interpreter cannot command the Pi by importing the package on Windows. Closing the laptop or pausing the debugger does not remove servo output.
Python finds picrawler, robot_hat and vilib along the selected interpreter's search path. A source folder visible in the editor is not necessarily the installed module. Do not name a club file picrawler.py, robot_hat.py, vilib.py, json.py or time.py: local names can shadow the intended import. Record interpreter executable, distribution metadata and actual source path/hash. V1 supplies a passive metadata capture procedure. Vilib import is not a passive diagnostic because its class-level camera object initializes.
Environments and requirements
First preserve the recovered working interpreter and package/card state. Do not casually create a new venv, install the newest NumPy or run upstream system installers to make an experiment start. Camera/GPIO/audio dependencies include OS packages and binary bindings outside pip declarations. A future spare-card environment should record OS/kernel/architecture/Python, apt package versions, all four vendor SHAs, app SHA and model hashes. If a venv is chosen, verify whether needed distro camera packages are visible; --system-site-packages is an option to evaluate, not isolation guaranteed to work with every stack.
The proposed application can import Picrawler from picrawler, Ultrasonic/Pin/Music from robot_hat, and Vilib from vilib. Instantiate only the subsystems actually needed, behind deliberate initialization. A distance logger need not create a crawler. Keep top-level imports/constructors free of hidden motion wherever the architecture permits.
For a simple club script on the qualified interpreter, execute python3 src/main.py from the project root if that is the authored entry point. For a packaged src/club_crawler layout, use the deliberately configured editable application install and python -m club_crawler.main; the latter is not automatically importable from an uninstalled src layout. These are alternative future layouts, not two commands to paste into the old Pi. If hardware permissions require a privileged process, deliberately choose and record its interpreter and calibration home rather than adding sudo until an import succeeds. Use project-relative asset paths resolved from a known root, not an accidental current directory.
Run and stop deliberately
Review startup side effects and support the robot before the first constructor. Arm only after the chosen pose/calibration/source baseline is confirmed. For early programs, run short bounded sequences with operator observation. Ctrl+C asks Python to unwind; cleanup may be delayed by a blocking call or background worker. In a future controller, latch stop, clear pending commands and wait for explicit active-command status. Do not automatically command sit after every exception; it can worsen a jam or fall. Keep an independent accessible power cutoff for an active fault, and use a normal Linux shutdown when the system is stable.
Git without a new repository requirement
Keep club work in an appropriate directory of the existing Engineering Club repository or an explicitly chosen future picrawler-lab repository. This pass creates no new repository. Use main for reviewed state, feature/<goal> for changes, experiment/<question> for trial branches, and known-good tags tied to actual bench evidence. A tag such as bench-YYYY-MM-DD-gait-baseline is meaningful only after that dated test exists.
Commit app code, owned trajectories, schemas, tests that validate real boundaries, board configs for added MCUs, dependency/environment records, and small sanitized example logs. Keep credentials/API keys/Wi-Fi profiles, real robot calibration backups when private, card images, personal recordings, giant model/video datasets, .venv/, __pycache__/, .pio/, build caches and system files out of normal source control. Store robot-specific backup references and hashes without publishing secrets. Preserve a patch plus complete source archive for recovered untracked vendor edits; a git diff alone omits untracked content.
Develop one small behavior, record actual outcomes, commit it, then integrate. No new Python framework, all-at-once dependency migration or broad vendor rewrite is required. Source evidence: V1 SOFTWARE_ARCHITECTURE, NETWORKING_AND_REMOTE_DEVELOPMENT, PHYSICAL_RECOVERY_PLAN; club-authoring and club-architecture.
Reference: configuration and reproducibility
Persistent settings and reproducibility
Configuration has several owners. Keep robot-specific calibration, application policy, Linux device setup, network credentials and model assets separate. Do not make one giant public JSON file containing all of them.
| Setting | Location / format | Loaded and written | Backup / corruption effect |
|---|---|---|---|
| Current upstream servo offsets | expanduser("~/.config/.picrawler.config"); fileDB key picrawler_servo_offset_list, 12-number textual list | Robot construction reads; matched helper/set_offset writes and clamps ±20 degrees | Copy actual user/root candidate before constructor; missing data can fall back to zeros, malformed/wrong-length data can fail or misbehave |
| Historical offsets | V1 inspected old core selects /opt/picrawler/picrawler.config | Depends on recovered implementation, despite same version string | Preserve original path and source; do not rename blindly |
| Network | Actual OS connection profile, e.g. NetworkManager-managed system/user configuration | OS network service; tools/profile location depend on recovered OS | Private backup plus local access path; corruption can remove SSH |
| Interpreter/library selection | venv/launch path, installed metadata and source SHAs, not a magic PiCrawler settings file | Selected at process startup | Record executable/import path and OS packages; wrong environment can lose Robot export/camera bindings |
| Camera orientation/resolution | App's saved flags passed to camera_start; stock runtime flags do not persist themselves | App config load at startup | Save camera calibration/flip alongside resolution; corruption or change can reverse steering |
| Audio | Actual boot overlay, ALSA config/mixer plus V4 profile | OS boot/audio initialization; repair tools write several files | Preserve before audio scripts; wrong revision can silence output or select wrong pins |
| App settings | Proposed config/robot.example.json in source, private robot.local.json override | Explicit app loader; schema/default validation before hardware | Bad settings fail closed to unarmed status; never silently default into movement |
| Model assets | Vilib /opt/vilib; effective-user ~/.vosk_models and ~/.piper_models | Feature/model loader; downloads separate from code installation | Hash/record source/license; missing model disables feature, does not trigger unrelated robot repair |
| Service | Future systemd unit; absolute interpreter/working directory and user | Service manager; reload unit definition then restart deliberately | Copy known-good unit and record permissions; restart must not restore motion/queue |
Recommended application schema: schemaVersion; robot profile ID; declared frame/leg ordering; motion policy (approved actions, speed/repeat ceilings, verified trajectory IDs); sensing policy (range thresholds, invalid/stale rules); camera mode/flip; telemetry/log settings; external endpoint references; and optional feature flags. Keep secrets out of this file. Proposed bounds are not physical limits until qualified. An explicit private calibration path/hash reference is more reproducible than copying offsets into every experiment.
Load config before constructing hardware, validate finite numbers, enums, ranges and feature prerequisites, and refuse unknown schema versions. Store atomically through a temporary file plus replace when implementing configuration writes. Keep an immutable before snapshot and a new after snapshot with date, source/interpreter identity and SHA-256. App defaults should enable diagnostics/idle, not locomotion. Code changes require process restart; runtime target changes can be accepted between segments; kernel/boot overlay changes may need reboot. Record the specific restart rather than saying every setting needs one.
No real offsets, current OS profile, credentials, model inventory or card backup are supplied here. Current physical state remains unknown. Source evidence: pc-core, hat-robot, hat-filedb, vi-install, voice-stt, voice-tts, hat-audio and V1 calibration/recovery documents.
Reference: software architecture
Software architecture and installation boundaries
The application script chooses behavior. The PiCrawler package supplies leg geometry and gait targets. Robot HAT supplies the robot interpolation base, servo/PWM/ADC/GPIO/I2C abstractions and audio adapters. Vilib supplies camera acquisition and vision. SunFounder voice-assistant supplies the actual STT/TTS/LLM orchestration behind several one-line re-export modules. Linux provides device nodes, permissions, network services and audio/camera stacks underneath them.
Repository versus installed package
A repository is a working tree of source and Git history. An installed distribution is what a Python interpreter finds through its import path. They can point to different source, versions and local modifications. Historical picrawler-2.1.4-py3.13.egg and robot_hat-2.3.0-py3.13.egg names reveal packaging and interpreter context, not an exact Git commit. Two PiCrawler snapshots with different paths and behavior still report 2.1.4. Preserve both installed files and checkouts.
The boundaries to inspect
| Layer | Relevant files | Responsibility |
|---|---|---|
| User behavior | examples/*.py or future club scripts | Inputs, state, perception-to-action decisions |
| PiCrawler | picrawler/picrawler.py | Coordinate conversion, action sequences, calibration reference |
| Servo robot | robot_hat/robot.py | Offsets, signs and synchronized angle interpolation |
| Electrical command | servo.py, pwm.py, adc.py, i2c.py, pin.py | Device communication and pulse construction |
| Camera/vision | vilib/vilib.py, detection modules | Frames, algorithms and web preview |
| Speech/intent | sunfounder_voice_assistant/* | Models, audio input/output, providers and lifecycle hooks |
| Linux | Device nodes, boot overlays, sound routing | Interfaces and execution permissions |
A failure at one boundary does not imply a failure at every layer. ImportError happens before a servo command. An absent /dev/i2c-1 blocks MCU access. An audio file error can coexist with good movement. A camera stream can work while optional vision models fail to import. Split diagnostics accordingly.
Declared dependencies are incomplete for the whole system
PiCrawler's pyproject declares Python >=3.7 and only readchar as a dependency. It does not express a pinned Robot HAT/Vilib/SunFounder voice graph in that dependency list. Robot HAT and Vilib also have empty pyproject dependency lists, while their install scripts install numerous apt and pip requirements. Thus pip show or successful package installation does not demonstrate the complete hardware stack.
The current Robot HAT installer uses apt tools/libraries and pip packages including smbus2, gpiozero, pyaudio, spidev, pyserial, pillow and pygame, then installs SunFounder voice-assistant from a Git URL without pinning its SHA. Its GPIO driver imports lgpio; the actual provisioning of that import must be verified in the OS rather than inferred from the pyproject. Current package initialization checks several imports and can deliberately skip exporting heavy classes if prerequisites are missing. That can again make from robot_hat import Robot fail for a reason different from a removed API.
The voice package declares piper-tts, vosk, pyaudio, sounddevice and edge-tts, but the source graph also uses requests, NumPy and provider/runtime features. A declared >=3.7 version is not proof that every feature works on all those Python versions: for example, current LLM code imports enum.StrEnum. Feature-level compatibility and installed runtime versions matter.
Permissions and side effects
Official examples run with sudo for hardware access. Root execution can select different package paths and configuration homes, which is particularly important after the calibration-path refactor. Constructing Picrawler moves servos and can create/read/chmod config storage through fileDB. Importing Vilib initializes a Picamera2 object. Installing packages, audio scripts, doctor --fix and VS Code Server all change the machine. Read-only metadata capture must come first.
Process and timing model
The stock movement layer blocks while interpolating servo angles. Vilib has camera/web threads and latest-value shared results. The voice example has a separate action worker, but its completion accounting is incomplete. None of those arrangements constitutes a hard real-time supervisor. A future club service should have one motion owner, explicit state, bounded commands and fresh sensor samples, with logging outside the time-critical path.
Development without modifying vendor code first
Use separate club scripts that import the recovered compatible packages. Preserve any existing vendor edits in Git patches and archives. For motion data and application behavior, a new module or data file is easier to audit than rewriting the whole library. If a vendor bug must be fixed, make a minimal separately tested patch against a pinned source version, record its hash and keep the original source. This research pass identifies defects and architecture opportunities; it does not replace the installed library or create a live robot service.
Source evidence: pc-core, pc-metadata, hat-metadata, hat-install, hat-init, hat-pin, vi-metadata, vi-install, voice-metadata, voice-llm, club-authoring.
Qualified next experiments
Choose one small experiment
- Read-only / offline: inspect pinned source and numerical frame/IK behavior without constructing a crawler.
- Active sensor: characterize raw ultrasonic failures and timing while stationary; no crawler object is needed for a distance logger.
- Actuator test: one supported pose or leg change only after backups, calibration and physical gates.
- Proposed custom application: build the pose explorer, range laboratory or telemetry station incrementally. These applications do not yet exist.
Continue
Meeting checklist · Source library · Modification atlas · All project proposals