/dex

Primary LanguageC

Dex

An open source self balancing robot designed for the Raspberry Pi Pico and controlled by a DS4 controller. Dex was made with 3D printed ABS, a custom PCB, and a whole lot of patience. This repository shall serve as a reference for anyone making their own balancing robot. The code is well formatted for your convenience you nerd. Note this is an intermediate project so take your time and have fun.

Image 1

Software

This project uses the several libraries including FreeRTOS, BTstack, and the Pico SDK. Each is a specific versions and can be setup with a recursive git clone. For this project the software utilizes both cores on the RP2040. _

Core 0

The primary purpose of core 0 is to handle all of the CWY43 SPI and MPU6050 I2C interrupts that hog all the cpu.

Core 1

The FreeRTOS scheduler runs on this core to prevent conflicting timing with the SPI interrupted. The bluetooth callback also gets processed here.

FreeRTOS Scheduler Tasks Description Task Delay us
stat_led_task blinky blinky 500000us
bt_hid_inputs process controller inputs 20000us
stepper_left_task controls the left stepper varying per step
stepper_right_task controls the right stepper varying per step
mpu6050_task requests gyro/accelerometer data and processed roll angle with Kalman filter 20000us
pid_task calculates the output for the stepper motors 10000us
good_boy_task watches the dog 500000us

Overclocking

Please note this project overclock the RP2040 to 250MHz and configures the configTICK_RATE_HZ 100000 (10us period). This is to give enough time for the schedule overhead. The reason for the high tick rate is because the steppers need step at very high rates.

PCB

This PCB was made in Eagle Cad and can find the PCB under resources/pcb. Please note there are two mistakes that i've hand wired for this current pcb. The holes for the switch are too small and cut traces to make the switch come before the 5V regulator. I'll update the files with a fixed design soon.

Image 1

CAD

This project was designed in Fusion 360 and all the files can be found under resources/cad.

Image 1

BOM 💣

Name Count Price (meets count) Description Rating Notes Link
Raspberry Pi PIco W 1 $18.96 MPU Clock: 135MHz 2 Cores Amazon Link
PCB 1 $24.05 Custom PCB designed Engineering Level: Maximum Designed in Eagle and order on JLCPCB N/A
NEMA 17 Stepper 2 $13.99 Main Motors Max Current 2a Amazon Link
Stepper Driver A4988 2 $14.99 Drives the stepper motors Min Step Rate: 500kHz Amazon Link
MPU-6050 1 $7.59 3 Axis Gryo and Accelerometer 16bit Amazon Link
L7805CV 1 $8.59 5V Voltage Regulator 35Vin and 5Vout/1.5A Amazon Link
Power Switch 1 $6.99 AC 125V 2A Only cuts power 5V power not stepper input voltage Amazon Link
LED 4 $11.99 Forward Voltage: R/Y 2.0-2.2V; B/G/W 3.0-3.2V; Max. Current: 20mA User about 100Ohm resistor Amazon Link
Beeper 1 $7.99 Active beeeper 2.5-4V/25mA. Make sure to be extra annoying Amazon Link
Resistors 4 $5.99 Resistor for LEDS Amazon Link
Headers N/A $7.99 Used for PCB and IO Amazon Link
Battery 1 $44.99 Any 4s Lipo will work 4S Lipo Battery 5200mAh 14.8V 60C Amazon Link
O rings 2 $5.99 Goes over 3d printed wheel for grip 110mm OD 100mm ID 5mm Width I used the wheels from Wouter here Amazon Link
3D Printed Chassis 1 0 Main body of the robot Designed in Fusion 360 N/A
3D printed Wheels 2 0 Main wheels with rubber O rings Designed in Fusion 360 CREDIT DESIGN N/A

Known Issues

  • Sometimes the program will halt when trying to connect to the BT HID.
  • Cannot reconnect to pico after pair to another controller.

Starting Debugger

Plug in debugger and run:

openocd -f interface/cmsis-dap.cfg -c "adapter speed 5000" -f target/rp2040.cfg -s tcl

confrim this starts on localhost:3333

open another terminal and run:

gdb-multiarch dex.elf

in this termincal type the command

target remote localhost:3333

load with

load