Mars/Wars has a preseason tradition of a 6 week minibot build and competition. We started with tethered sumobots years ago. Last year we used the Romi code as a base to building actual wpilib bots. This year we wanted to run wpilib bots on real hardware. We don’t have enough roborios and aren’t going to invest in them now. This post is to document what it takes with 2023 versions to use a RPI or NVidia Jetson to make a wpilib robot. This will probably change with 2024 versions. Hopefully REV, CTRE and other vendors will consider this use case.
Let’s try to build a CAN-only wpilib bot that supports both REV and CTRE devices. Wpilib has a HAL (hardware abstraction layer) system which targets athena, athena2 (roborios) and simulation. There is vague language about adding a custom HAL, but zero examples. VMX-pi does this but I didn’t realize it was open source. I think it was Peter Johnson who pointed out that the simulation HAL has an extension system to support actual hardware. So really, the simulation HAL is a universal HAL.
Off we go down the simulation HAL path. NI provides us with a closed source binary blob that provides DriverStation comms and CAN comms. It turns out the wpilib simulation HAL also provides DriverStation comms via an extension. Simply set an environment variable, and they will be loaded. export HALSIM_EXTENSIONS=“libhalsim_ds_socket.so”
There are a bunch of cheap Canable-type usb to can converters. Using the candlelight firmware, they work great with linux SocketCAN. CTRE has examples on how to use these with their hardware GitHub - CrossTheRoadElec/Phoenix-Linux-SocketCAN-Example: Phoenix API example for Linux-Desktop and Raspberry Pi
REV has a another promising repo. GitHub - REVrobotics/CANBridge: Generic CAN Bridge emulating FRC netcomm CAN driver for connecting a PC to the CAN Bus with WPILib 2020+ and SPARK MAX (FW 1.5.0 or higher) or other drivers, currently only supported in Windows. But there is an old branch on github called “SocketCAN”. This could work. I fixed up the bit rot. Now we have a simulation HAL CAN extension for SocketCAN. GitHub - FRC-Team-4143/CANBridge at 4143
We are getting there. So far we are using a RPI or Jetson with a canable, wpilib compiled with simulation HAL, DS extension, CAN extension, REV drivers for linuxarm64 and CTRE drivers from the Phoenix-Linux-SocketCAN-Example repo.
The CTRE drivers implement their own socketCAN extension. It is great they did this, but excludes all other vendors. SocketCAN doesn’t care if you have multiple users of an interface. We can let the CTRE traffic go through their library and all other vendors go through the canbridge extension. They do need a call to FeedEnable() periodically.
There is another problem though. The REV linuxarm64 drivers check to see if they are working in a simulation HAL. If they are, they don’t enable. That seems reasonable for a simulation HAL, but remember, the “simulation HAL” could have been called “universal HAL”. Not a huge problem, we’ll just lie to the REV drivers and say that we aren’t in a simulation.
Now we have a working wpilib CAN bot with DriverStation support. PWM outputs and digital/analog inputs could be implemented with simulation HAL extensions for specific hardware.
It would be great if vendors published linuxarm64 libraries that did the exact same thing as the libathena target libraries. It would also be great if REV published the CANBridge for Linux with SocketCAN and SparkMax support. (I think SparkMax are almost the same as candlelight fw devices but something makes it not work (might be tx checksums)). I’ve only tried this so far with CTRE Phoenix5 firmware.
Here is a working proof of concept repo for a C++ bot that actually makes motor spin. GitHub - FRC-Team-4143/jetsonNative: native C++ FRC wpilib robot code running on a Jetson
Edited: to say VMX-PI hal is opensource