PicoRobot is a Rust-based project for the Pololu 3pi+ 2040 Robot, utilizing the rp-pico HAL and the RTIC framework.
Before you begin, ensure you have the following installed:
- Rust: Install via rustup.rs.
- Thumbv6m Target:
rustup target add thumbv6m-none-eabi
- probe-rs: For flashing and debugging.
cargo install probe-rs --features cli
Ensure that .cargo/config.toml is configured for your debug probe. The default configuration uses probe-rs.
[runner]
runner = "probe-rs run --chip RP2040 --protocol swd"To flash and run a specific example from the examples/ directory, use the --example flag:
cargo run --release --example <example_name>| Example | Description |
|---|---|
motors_demo |
Basic motor control (forward, backward, stop) |
encoders_demo |
Reading wheel encoders via PIO (Software Decoding) |
encoders_hw_demo |
High-performance asynchronous encoder tracking (Hardware Decoding) |
target_velocity_demo |
PID-controlled constant velocity using encoder feedback |
line_sensors_demo |
Calibrating and reading the 5-channel reflectance sensor array |
line_following_demo |
Full line-following application with calibration and PID steering |
leds_demo |
Controlling the RGB LEDs |
leds_off |
Utility to turn off all RGB LEDs |
display_demo |
Using the OLED display with embedded-graphics |
imu_demo |
Reading data from the onboard IMU |
uart_echo_demo |
Echoes characters received on UART0 (GP28/GP29) |
blink_led |
Basic blinky example (migrated from main) |
To test the uart_echo_demo, you will need a USB-to-TTL serial adapter connected to the robot's UART pins (GP28/TX and GP29/RX).
- Connect the Adapter:
- Adapter RX -> Robot GP28 (TX)
- Adapter TX -> Robot GP29 (RX)
- Adapter GND -> Robot GND
- Flash the Demo:
cargo run --release --example uart_echo_demo
- Connect using
screen: Identify your serial device (e.g.,/dev/tty.usbserial-XYZ) and run:To exit screen, pressscreen /dev/tty.<your_serial_device> 115200
Ctrl+AthenKthenY.
The project provides high-level drivers for the robot's subsystems in src/hal/.
| Module | Description | Key Features |
|---|---|---|
motors |
Dual DC Motor Control | PWM speed control, Direction handling |
encoders |
Quadrature Encoders | PIO-based hardware counting, Zero CPU overhead |
closed_loop_motors |
Velocity Control | PID controller integration for constant speed |
line_sensors |
Reflectance Array | 5-channel RC timing, Calibration, Scaled output |
display |
OLED Screen | SH1106 driver, embedded-graphics integration |
leds |
RGB LEDs | APA102 (DotStar) driver via SPI |
imu |
Inertial Sensors | Accelerometer and Gyroscope access |
This project uses defmt for efficient logging. When running with probe-rs, logs are automatically displayed in your terminal.
You can set the log level at runtime by setting the DEFMT_LOG environment variable:
DEFMT_LOG=trace cargo run --release --example target_velocity_demoAvailable levels: error, warn, info, debug, trace.
Use these macros in your code to print logs:
error!("Error message")warn!("Warning message")info!("Info message")debug!("Debug message")trace!("Trace message")