ROS2 GAMEPAD ROVER
Tiny experiment to interface Bluetooth control and ROS2
I had originally planned on making this page a super detailed explanation of how I did this and all the issues I had to fix, but I ran out of time to finish the page and build log over winter break, so here's a cleaned-up version of the notes I made when working through this project. There are a lot of links to pages that solved my specific issues. Think of this as a combination of works cited and appendix for the youtube version.
I plan on cleaning this page up at some point, but needed to get this project online so I can focus on my coursework (I get to work on Robot Arms this semester!)
I installed everything on a 2gb Raspberry Pi 3B+, you can install full Ubuntu Desktop if you have a Pi 4 with 4gb, but I didn't at the time I did this project.
Ubiquity does have ros2 pre-installed distros, though they also will require some more powerful hardware. https://learn.ubiquityrobotics.com/noetic_pi_image_downloads
Code can be found at https://github.com/KeplerElectronics/ROS2_GAMEPAD_ROVER/tree/main, though its mostly just modifications of tutorial code to make everything mesh together.
General process:
- Install Ubuntu server and get wifi working
- Get Motor Hat Working
- Get Pubsub example working from ROS documentation
- Install and validate Joy package
- Connect Subscriber node to Joy message
- Set up Launchfile
- Set up everything so it will run launchfile on startup
Here's the list of absolutely necessary docs:
Ubuntu Install
https://www.raspberrypi.com/software/ https://ubuntu.com/core/docs/networkmanager/configure-wifi-connections
ROS2 Install
https://docs.ros.org/en/humble/Installation.html
Motor Hat Install
https://ubuntu.com/tutorials/gpio-on-raspberry-pi#2-installing-gpio
https://learn.adafruit.com/adafruits-raspberry-pi-lesson-4-gpio-setup/adafruit-pi-code (dont forget blinka)
https://learn.adafruit.com/adafruit-dc-and-stepper-motor-hat-for-raspberry-pi/using-dc-motors
Publisher/Subscriber
Install Joy
https://docs.ros.org/en/api/sensor_msgs/html/msg/Joy.html
Make sure to source Joy!!
https://get-help.robotigniteacademy.com/t/ros2-foxy-package-joy-not-found/14287
source /opt/ros/foxy/setup.bash Test controller input while joy is running with
ros2 topic echo joy
I used an 8bitdo SF30Pro wired. I was able to make bluetooth work, then it broke upon shutdown and I never bothered to fix it. For my uni Lunabotics project, I'm pushing for a 2.4G wireless controller with a dongle.
you can try and use this for pairing https://ubuntu.com/core/docs/bluez/reference/pairing/outbound-pairing
Create a Launchfile
https://docs.ros.org/en/foxy/Tutorials/Intermediate/Launch/Creating-Launch-Files.html
Error code -2 is the script not being able to handle ros giving it arguments. I cannot find how to accept arguments anywhjere for ros2
https://robotics.stackexchange.com/questions/22896/roslaunch-exit-code-2-error
(I saved this page but can't remember why, so here it is since I probably used it as a source) https://answers.ros.org/question/229185/roslaunch-namespace-substitution-within-group-tags/
The reason this wasn’t working was because I specified a separate namespace for joy. Removing that made it work like a charm
Add launch stuff to .bashrc
https://answers.ros.org/question/87866/how-to-edit-the-bashrc-file/ https://ostechnix.com/ubuntu-automatic-login/
BONUS NOTES :D
Follow ros instructions to build package, this is pretty useful https://docs.ros.org/en/humble/Tutorials/Beginner-Client-Libraries/Creating-Your-First-ROS2-Package.html
From the hello world package, add the adafruit motorkit stuff in, rebuild with colcon and run it, motor should move. (make sure that everything is plugged in)
Make sure to source the ROS scripts!!!
source install/local_setup.bash https://docs.ros.org/en/humble/Tutorials/Beginner-CLI-Tools/Understanding-ROS2-Nodes/Understanding-ROS2-Nodes.html
You can name different ros nodes in the setup file, allowing you to run them individually
Gave up and just tried to get the pubsub example working - it ran! Use ctrl alt f2 to get to new term to run other stuff