I’m interested in learning how to get the driver station to interact with the robot and vice versa, and I’ve been through tons of threads describing how the server code (the robot) should be written and how the client code (the laptop) should be written.
However, there is one crucial detail that I haven’t been able to grasp yet: when and how exactly is the client code supposed to be run? Is it supposed to be built in WindRiver as an .exe (is that even possible)? Can I use another IDE such as VC++? Do I have to start running the client code before activating the robot code, and does the client code just run in the background of the driver station? I feel like the solution is extremely simple because no one has brought up this question yet in the multiple threads I’ve browsed. Any help would be appreciated!
First, I’ll give the bigger abstract answer, then I’ll give a practical one.
Network Tables clients and servers are mostly the same. They store name/value pairs that the local program writes and return them when a read operation is performed. They support Booleans, double precision numbers, strings, and arrays of these types. The next feature of them is that multiple computer/robots/camera processors can be kept in synch. One of these is designated the server, and the rest are clients. They are much the same except that the server knows who everyone else is and replicates data out to keep everyone in synch. If we have three NT participants, S, C1, and C2, A variable change made on C1 is stored and sent to S. S then sends the new value to C2 as well.
In practice, the robot will typically be the server, the dashboard a client. Some teams will have an onboard processor which is a client. Some will also run NT on their programming laptop so that when it is connected, their tools can see the variables.
The NT clients are often the same code compiled for the DS laptop. However the only thing that matters is that they implement the protocol that shares. In reality, the clients and servers can be written in different languages and it won’t affect things.
Does NetworkTables utilize some sort of class serialization algorithm? I’ve always been confused as to how it can send stuff like “Commands” to SmartDashboard or motor actuators.
I believe the commands are simply some data fields with special names. The WPI code binds to those values so that you can affect them simply by updating values. This is the way the PID object works as well.
Oh okay I see. The PID object makes more sense to me because P, I, and D are just values whereas stuff like motor actuators and subsystems are objects. I suppose that object serialization is sort of the same thing because the goal is to send critical data fields from the object over a network not necessarily the whole object. I suppose NetworkTables is a work-around for Java ME which doesn’t support object serialization. I would expect with the new control system, NetworkTables for Java at least will not be as complex seeing as Java SE has a native serializing interface. I think it is still relevant in the C++ version of the library because C++ has no built-in serialization interface so one needs to implement one in order to send data fields from objects over a network.
Since the protocol is intended to be used across multiple languages, it will not necessarily shift to using native Java serialization. LV has native serialization as well, and this was used in the initial DB protocol for LV to LV comms. The serialization is just a small portion of the SD codebase.
Thanks! I’m still slightly unclear about the other part of my question though: how am I supposed to compile the client code? Should I make it into an exe and run it separately? Am I supposed to build it inside or outside of WindRiver? Once I build the client code for the driver station, when and how do I run it so that it will communicate with the robot?
If you wanted to write a java client, you would link against the desktop-lib
etworktables-desktop.jar . Should be easy.
If you want to write a python client, you would install the pynetworktables binary for your version of python, and run the sample code. Should be easy.
If you want to write a C++ client, you need to extract the right pieces out of WPILib, fix them so they compile on a desktop, and then link all of that together. Not easy. You can use the NetworkTables components from RobotPy patched version of wpilib which (together with pynetworktables-specific patches can be compiled on a desktop), but it’s still not going to be trivial.