Robotic swerve drive platform developed for Northwoods Church Christmas program
Control is all using an XBox Series wireless controller.
Input | Control Description |
---|---|
RB | Hold to enable driving |
Left Joystick Forward/Reverse | Drive forward/reverse |
Left Joystick Left/Right | Drive left/right |
Right Joystick Left/Right | Rotate counter-clockwise/clockwise |
RB + LB | Hold to enable line following |
D-pad Up/Down | Line follow forward/reverse |
LT + RT | Hold for 2 seconds to enable module homing |
A | When in homing mode, hold for 1 second to save new home position |
The driver controller will vibrate to indicate various events.
Vibration Pattern | Description |
---|---|
Faint rumble with no buttons/joysticks moved | XBox Controller connected to Raspberry Pi after controller power on or platform reboot |
500ms pulse | Indicates drive mode has been activated and joysticks now command platform motion. Will occur when RB is pressed and joysticks are centered. |
Rapid pulses | Indicates drive mode is locked out because joysticks are not centered. Will occur when RB is pressed while joysticks are not centered. |
Continuous waves | Indicates homing mode is primed. Will occur when LT and RT are both held for at least two seconds. |
Continuous medium intensity | Indicates new home position was saved. Will occur after homing mode is primed and A is held for an additional 1 second. |
Whenever a module is swapped; a module, motor, or sensor is unmounted and remounted; or a freshly imaged Raspberry Pi controller is installed, you will need to "home" the swerve modules so they all move together properly. Symptoms of an improperly homed platform range from the platform not driving straight to the platform moving erratically or stalling. You should see all modules pointed in the same direction when moving using only the left joystick after homing is performed successfully.
To save a new home position, do the following:
- Turn platform power off
- Align all modules so the bevel gear on the wheel is facing toward the right side of the platform. Using a square is best to ensure each module is aligned to the platform
- Turn platform power on
- Connect XBox Controller
- Prime homing calibration by holding LT & RT for at least 2 seconds
- You should feel a continuous wave vibration pattern when homing is primed
- While continuing to hold LT & RT, press and hold A for at least 1 second
- You should feel continuous steady vibration when homing has saved
- Release all buttons and try driving to validate homing
Homing values save to /home/pi/.config/Swerve-Platform/moduleHomes
on the Raspberry Pi, so everything is saved across power cycles.
The robot is able to follow a 2 in white line on a black floor in the forward and reverse direction. Manual driving takes priority over line following.
The start and end of the line can be established by a perpindicular line at least 6 in wide at least 12 in from the end of the line. When line following is first enabled, the robot assumes it is inbetween both end stops. If line following continues to be enabled, then the robot will stop when it detects an end stop and will only allow movement in the direction it came from. If line following is disabled after it reaches the end stop, then the robot assumes it is inbetween both ends stops and movement in the wrong direction will be allowed.
The robot centers itself on the line through rotation. Therefore, over time robot yaw may drift. The easiest way to correct this while keeping the robot on the line is to manually rotate the robot after it has come to a stop.
If the robot does not detect the line, then it will attempt to steer back towards the direction it last saw the line. If the robot still does not detect the line after some time, then line following is disabled and the robot must be manually centered back on the line.
Tested in Linux, but might work in other environments because most of build is conducted in Docker for cross compilation.
mkdir build
cd build
../utils/toolchain.sh rpi3-armv8 --pull --export
cmake -DCMAKE_TOOLCHAIN_FILE=../utils/armv8-rpi3-linux-gnueabihf.cmake -DCMAKE_BUILD_TYPE=Debug ..
make -j`nproc`
Steps 1-4 may be skipped once the environment is set up appropriately.
A GitHub codespace container is available for this project.
This project uses pre-commit to check code formatting before accepting commits.
First install the prerequisites:
- python3 (with pip) - instructions
- Python 3.9.x from the Python website works well. Make sure to check the add to path option in the installer.
- pip packages:
- You may need to add the pip install path to your shell's path if you're using Git Bash. In git bash:
- Open (or create) new file
~/.bashrc
by runningvim ~/.bashrc
- Add this to the end:
PATH=$PATH:$LOCALAPPDATA/Programs/Python/Python39/Scripts/
(changePython39
to match your python version)- Note: The actual path you need to add (
$LOCALAPPDATA/Programs/Python/Python39/Scripts/
in the above example) depends on your Python installation. If y ou do thepip install
steps first, pip will print the path you need to add. - To type in Vim, type i and you should see
INSERT
at the bottom of the window to indicate you're editing in insert mode
- Note: The actual path you need to add (
- Exit by pressing Esc then type
:wq
and press Enter - Run
source ~/.bashrc
to update your session
- Open (or create) new file
- clang-format -
pip install clang-format
- pre-commit -
pip install pre-commit
- You may need to add the pip install path to your shell's path if you're using Git Bash. In git bash:
Then initialize:
pre-commit install
pre-commit run
The first run may take a moment, but subsequent automatic runs are very fast.
You'll now have the linter run before each commit! For compatibility with Windows, we recommend the pip version of clang-format, but wpi-format will find any installed clang-format
binary in the system path.
- Copy
bin
,lib
, andscripts
to/home/pi/swerve-platform/
- Copy
scripts/swerve-platform.service
to/etc/systemd/system/
:sudo cp /home/pi/swerve-platform/scripts/swerve-platform.service /etc/systemd/system
- Adjust permissions of unit file:
sudo chmod 644 /etc/systemd/system/swerve-platform.service
- Enable service:
sudo systemctl enable swerve-platform.service
- Reboot
The image/
directory contains directives to set up an image with most settings preconfigured. Unfortunately, this is not building correctly in GitHub actions, so the manual steps are documented here.
Start with Raspberry Pi OS Lite. Legacy (Buster) definitely works. Latest (Bullseye) should also work, but may have some compatibility issues. Use 32-bit OS version if prompted.
Use Balena Etcher to write the downloaded Raspberry Pi OS image to a microSD card.
On first boot,
- Expand the filesystem so the full SD card space is usable. This can be done using
raspi-config
- Change the hostname to
NWCC-platform-alpha
(or your preferred hostname that will later be used for SSH access) - Enable SSH access
Then reboot before continuing setup.
sudo apt-get update
sudo apt-get upgrade
Add the following lines to /boot/config.txt
dtparam=spi=on
dtoverlay=mcp2515-can0,oscillator=16000000,interrupt=25
dtoverlay=spi-bcm2835-overlay
sudo apt-get install can-utils
sudo apt install dkms linux-headers
- Reboot
git clone https://github.com/atar-axis/xpadneo.git
cd xpadneo
sudo ./install.sh
- Update controller firmware in Windows using XBox Accessories App
echo 'options bluetooth disable_ertm=Y' | sudo tee -a /etc/modprobe.d/bluetooth.conf
systemctl edit bthelper@hci0
and add the following content:[Unit] After=hciuart.service bluetooth.service Before= [Service] ExecStartPre=/bin/sleep 5
- Add
Privacy = device
to /etc/bluetooth/main.conf - Reboot
- Run the following with XBox controller in pair mode. Lines after
sudo bluetoothctl
are run inside bluetoothctl prompt:sudo bluetoothctl agent on default-agent scan on ** note MAC address of XBox controller. Will be XX:XX:XX:XX:XX:XX in future steps** scan off pair XX:XX:XX:XX:XX:XX trust XX:XX:XX:XX:XX:XX exit
- Controller should change to solid light after
pair
step. Controller will reconnect on reboot. Usejstest /dev/input/js0
to test joystick inputs (fromsudo apt install joystick
package)
Content from the following external sources is used within this project: