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.
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.)
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).
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.
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.
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.
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.
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.
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!