Making a ROS Controller
From scratch(ish) this time!
Wait, you’re making a controller again?
Previously I posted about Making a GameHat Into a ROS Controller.
So why am I at it again? First off, the GameHat doesn’t allow for analogue control, the analogue stick is recognised on or off… This means the spiders would be either full speed or not moving — which isn’t ideal. Next, I need many more buttons (who wouldn’t want more buttons?) I want to be able to change what each of the inputs do in relation to the robot I’m working with.
My robotic spiders have different control surface needs to buggies, robotic arms and flying robots, I want a controller that will work with all of these.
I also found these cool analogue sticks after pulling apart a drone controller I didn’t need.
The part list
- 7" touch screen screen
- Teensy 3.2
- USB 5A bucky
- 4 x 18650 batteries in keystone trays
- Pi4
- Heaps of buttons from jaycar
- A couple of joysticks from an old controller I had
- Two analogue sliders
- Some custom child-boards for the buttons and the wiring
Designing the controller
The hand-made boards for the buttons and the Teensy are custom, the rest of the parts have no real customisation apart from position. I modelled the side controllers on where the buttons are on a Nintendo switch and where the buttons are on the LogiTech F170 controller. I modelled the wiring on the Teensy board around fitting it in the smallest board possible.
Once again I’m using OpenSCAD and my pre-defined workflow to code-up all the models.
I start by putting all of the components into an OpenSCAD project.
Then I use the scientific method of moving stuff until I feel happy about it’s placement. Which involves me putting my mouse pointer in the air, squinting a bit then moving everything around… over and over again.
This approach seems really tedious, after years building robots from multiple parts I have found that using the actual parts as cut-outs for the models I’m making means:
- A lot less “test parts” that go in the bin
- Parts that are more space-efficient
- Less parts overall that need to be bolted, glued or generally bubblegum’d together — aka lighter parts
- Consistent cable spacing
So overall — less time printing, less waste and more-suitable parts. The only downside is that the parts are generally more complex and changes mean a reprint of larger parts.
After an undisclosed amount (haha — a lot!) of time, I have a layout that I am happy with.
The 3d models are made up of 4 main pieces.
The middle frame is where almost everything connects to almost everything else.
The top shell holds the joysticks in place and covers most of the components.
The bottom side panels cover the underside of the joystick and protects the corners.
The battery panel protects the batteries while making it easy to remove/replace them.
All together that looks a bit like this
After printing all the parts and mounting all the components the controller is looking really good.
Embedded controller
I started here for the joystick command but I modified it heavily. This code forces the Teensy to register as a joystick.
There’s a bit of hacking required to get it working right on linux which is 90% done on mine, just one slider doesn’t work for some reason.
The source code is in the github repo with all the other code but in-short it’s a high-speed state machine. The state of all the controls is measured 100s of times per second and if it changes, the state it sent using the Teensy joystick library.
For more detail checkout the embedded arduino code.
Installing ROS
We’ve done this before! I followed the standard instructions for Noetic — Noetic is the latest LTS for ROS1 — this would have suited ROS2 as well but my robots are currently all in ROS1 code.
I had to install the teensyduino linux code for the joystick drivers.
To test it I ran roscore
on the host machine :
$ roscore
On the joystick OS I ran the joy_node
command but overrode the device parameter:
$ rosrun joy joy_node _dev:=/dev/input/js1
Lastly I subscribed to the ros topic:
$ rostopic echo /joy
(I’ve SSH’d into the joystick from my ROS VM to show all the terminals in one place)
Tu-daaah!
There you have it, a working joystick that publishes to a ROS joy
topic, has wifi, a keyboard and essentially everything I need when playing with robots in the field.
What’s missing?
The one thing it’s missing is the ability to just plug it in and have it charge. The controller has a lot of battery storage and — considering what it’s running — that battery storage should easily last a session or two on a single charge, I’ll add one in when I find the right charge controller.
Now, back to my spiders…