Extending RobotPy/wpilib for a new motor controller

Dear Python development people at ChiefDelphi,

I would like to use Python wpilib to run a robot based on a Raspberry Pi. The standard wpilib has class support for FRC standard motor controllers (Talon, etc).

Is there a proper way to extend the wpilib to support Pi native motor controllers (typically lower power DC/Stepper/Servo motors)? I know there are several, but I started off with the MotorHAT from Adafruit, that comes with a Python library, so I have access to the source code for speaking to the board itself.

I would like to approach this in a way that fits in with the overall WPIlib philosophy, either deriving a class from an existing one…perhaps a sibling class to an existing motor controller class.

The goal is to create a low cost Pi based platform for training new students in the off season, then transfer those skills to the RoboRIO prior to build season.

Any input and direction would be appreciated.

In going through the wpilib documentation, I looked at both the Jaguar (edu.wpi.first.wpilibj.Jaguar) and Talon classes. They are both derived from edu.wpi.first.wpilibj.PWMSpeedController. I also saw an I2C class used for communicating with an I2C bus (which the Pi has).

  • Does the pure Python wpilib have the PWMSpeedController and I2C classes?
  • If I were to derive a Python class from PWMSpeedController, can I pull code from the Adafruit library, use the I2C class, and get this to run in a manner consistent with the larger RobotPy methodology (robot initialization, working with Joystick/network tables, PID, etc.)
  • Am I looking in the right place?

Pasting from my prior post about this:

RobotPy’s WPILib can run on any platform that a Hardware Abstraction Layer (HAL) exists for. Currently, two exist:

  • One for running on the RoboRIO that talks directly to the hardware present on the RoboRIO
  • Another for running in simulation that talks directly to a large dictionary that stores the running robot parameters

To do what you want, you would need to create a HAL for a RPi. Creating a new HAL wouldn’t be particularly difficult, but I suspect it would be a lot of effort. The difficult part would be providing an equivalent to the driver station (or writing your own interface that allows the current DS to talk to it).


We have documentation similar to the Javadocs at http://robotpy.readthedocs.io/projects/wpilib/en/latest/api.html … so you can see what we do and do not have (spoiler: we have everything Java has).

Everything in WPILib is tightly bound to the HAL API. For example, the simulation HAL API can be found at https://github.com/robotpy/robotpy-wpilib/blob/master/hal-sim/hal_impl/functions.py

You could create your own HAL package that implements the right functions that do the right things and the the current wpilib could be usable without modifications. You just might find that the number of things needed to be implemented would be higher than you would like.

Also, here’s a concrete example of what happens with the Talon.set call:

  1. talon inherits from PWMSpeedController, and configures the various PWM timing things it needs to work
  2. PWMSpeedController.set calls PWM.setSpeed which calls hal.setPWMSpeed
  3. In simulation, this is the function that gets called. On the RoboRIO, the HAL C API function of the same name gets called.

Just about everything in wpilib that interfaces with hardware works that way.


Thanks so much for taking the time to reply. I understand much better now what is involved, and the tight binding between RobotPy and the RoboRio specific HAL. You’re right, the time and effort seems to make it impractical to rebuild a HAL for the Pi (much more than I had bargained for).

It appears that Kauai Labs has a board and HAL that seems to provide a full environment for the Pi. $159 for the board is a bit more than buying a $22 DC motor board, but counting the time to make the software work, it might be a more practical approach.

I just apt-get installed the vmxpi-hal.

Any chance this would work with RoboPy? (Shot in the dark!):ahh:


I think I’ve figured out how I’m going to do this. I’ve tested RobotPy on the Raspberry Pi, and except for motor controllers based on the RoboRio HAL, it can work with networktables.

I think I accidentally started following in the footsteps of team 2733 (Pigmice) who developed a driver station in Python. *(http://www.capnetix.com/index.php/blogs/mentor-on-a-mission/item/5-need-driver-station). I then just called a Python library provided by Adafruit (for their MotorHAT motor control board). So far so good. Should have a little mobile teleoperated bot shortly.

So far, so good. Looking forward to getting deeper into RobotPy. We’re looking at doing a hackathon using the Pi for some new incoming students, to prep them for FRC competition next season.

Thanks for your work!*

Good luck! If anything you’re working on would be useful to the greater FRC community, please let us know and/or submit a pull request to one of the RobotPy repos. More community involvement is key to the continued growth of python usage in FRC.

WPILib distributes an excellent tool called OutlineViewer which also allows you to view everything stored in NetworkTables. It’s distributed with the Eclipse plugins, or you can download it separately at http://first.wpi.edu/FRC/roborio/maven/release/edu/wpi/first/wpilib/OutlineViewer

I’m sure you’ve seen this already, but there is documentation about how NetworkTables works also.

One thing that I’m working on at the moment is more realistic physics simulations of the robot via the pyfrc simulator, you may find them useful. I’m hoping to put together a working elevator example that will have ‘gravity’ and such.

We’re working on something very similar, porting WPI Library to work w/the VMX-pi which is a Raspberry Pi HAT that has CAN, lots of IO and a navX-sensor on it. Send me a PM if you want to trade notes.

I have been thinking about getting the VMX-pi for weeks now. I wanted to do a summer project that would be fun for new students coming up from the Lego world (cough and for me cough).

I realize I needed to upgrade the mechanicals (I’m using legacy Legos now), and didn’t want to spend a lot of money. I started thinking about the low cost Radio Control (RC) world. I ended up ordering a VMX-pi from Kauai labs, and a $40 RC 4WD rock climber from Amazon.

My goal will be to blend the two. Because the 4WD can go outside, it should be able to exercise all the navigational and IMU capabilities of the VMX-pi.

One of the tricks will be to bring a mobile Wifi hotspot outdoors under battery power, so the driver can use networktables instead of RC.

I’m assuming it should not be hard to retrofit the wiring for the steering servo and the speed control for the (I’m assuming) DC motors for the drive. I’ll need to modify the body to be able to hold the electronics and camera (could be a good Solidworks/3d printing project for a student). The offroader already has a spring suspension, so much of the shock/vibration should be dampened, but we may have to add some additional dampening for the electronics enclosure (or drive slowly ;-).

I should end up with a low cost mobile platform to which I can add additional sensors, and the kids and I should have fun with it.

It’ll take me a bit to get all that working, but if I can mesh that with the software work to mesh the VMX pi HAL with with wpilib, pretty much all the skills developed should be transferable to the next FRC season.

What robot bases are people looking at for use with Raspberry Pi? I’m looking at the GoPiGo and the Bogie Runt Rover. What else is worth looking at?

I ordered a $30 4WD Rock Crawler off of Amazon. My plan is to reverse engineer the motors (DC for drive and servo for steering), and RC receiver, and retrofit them with a VMX-pi, Pi combo.

Pretty low cost, and by inserting the robot control system in between the receiver and the motors (drive and steering), its a great platform for testing out IMU, pitch/roll/yaw (as you crawl over rocks), and in a networked environment, drive it with a base station and networktables. Have some fun with the kids at the same time!

I’m trying to port WPILib to a BeagleBone Blue, which has nice motor/servo outputs, encoder inputs, and an IMU on board:

Pretty challenging so far, but I’m enjoying the wild ride.