Go WPILib #2982
-
Hi, I'm a member of FRC team 5340 @fairmingos, and I've been looking into potentially writing a Golang implementation of WPILib, but I'm having some trouble figuring out where to start. I've been combing the C++ source looking for some hint at what the actual underlying process is that allows the robot to communicate with the driver station, but no luck. Furthermore, I realized that I don't know the first thing about how the RoboRIO performs this task on startup. I'm guessing that a fair amount of this nitty gritty is baked into the RoboRIO image, and is therefore under National Instruments' jurisdiction, but that doesn't really clarify how one can interface with it. It also really doesn't help that half of C++ syntax looks like gibberish to me (I've only done Java and Kotlin for FRC programming). My question is, is there anyone who'd be willing to sort of give a brief overview of the inner workings of WPILib?I'm particularly concerned with what goes on at the boundaries. In other words, it's not terribly difficult to figure out how to implement the IterativeRobot class, for example, on the surface. As I dive deeper down the source code rabbit hole, however, I encounter dead ends and obscure syntax that make it extremely difficult for me to figure out how this code is interacting with the Driver Station on even the most basic level. My general perplexments:
I think it would be really cool to implement this stuff in Go. It's an awesome language that, in my opinion, provides the best of both worlds in terms of being both high level and low level. It is extremely type safe (if you're not using hacky unsafe features), functions are first class objects, there are no 'classes' in the traditional Java-esque sense, but you can attach methods to types, which allows for the same kind of state encapsulation, and it's garbage collected. But you don't have to care about Go to understand why I want to write my own implementation. It's just fun. What better way to learn about robotic software than to pick apart WPILib? I know that @auscompgeek has experience in the robotpy project and has tried a Rust implementation, so their input, if available, would be most appreciated. I hope this isn't too much of a bother or an unreasonable request 😂 |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 3 replies
-
Lots of questions to go over, so I'll start with the simple ones and where to go from there. To start with, for interfacing with the roborio hardware and DS directly, all the headers for doing that are found at https://github.com/wpilibsuite/ni-libraries/tree/master/src/include But, even that is pretty low level, and the FPGA is even trickier as its C++ exports and not C exports, which are much harder to interface with. The DS interface itself is not documented, and also all the ports are already attached to by the netcomm daemon, so you can't directly interface with them anyway. Its custom UDP packets. Instead of starting at that level, I would recommend looking at the HAL interface we have in WPILib. This is an object like C API for interacting with all the hardware functionality. That is deployed with any WPILib code, and all the interfaces can be found at Basically, to use that, you need to call HAL_Initialize(500, 0), and then any other functions can be called to get anything else you need. The headers there have function documents for what each thing does, and has access to all the hardware and the DS. Its definitely the best place to start, as its a simple API that gets rid of much of the complexity, especially in the IO. For starting programs, at startup the robot runs a file called |
Beta Was this translation helpful? Give feedback.
-
I had forgotten about this, but you might find this useful: https://github.com/qhdwight/frc-go .. not sure how far they got |
Beta Was this translation helpful? Give feedback.
Lots of questions to go over, so I'll start with the simple ones and where to go from there.
To start with, for interfacing with the roborio hardware and DS directly, all the headers for doing that are found at https://github.com/wpilibsuite/ni-libraries/tree/master/src/include
But, even that is pretty low level, and the FPGA is even trickier as its C++ exports and not C exports, which are much harder to interface with. The DS interface itself is not documented, and also all the ports are already attached to by the netcomm daemon, so you can't directly interface with them anyway. Its custom UDP packets.
Instead of starting at that level, I would recommend looking at the HAL interface we h…