UDP Server

Hi Guys,

I was wondering if anyone could help me understand how I would set up a udp server so I was able to process images on the laptop, than send that data to the robot.

So I was wondering if someone could explain to me how to:

send the images to the driverstation
process those images on the driverstation
send the processed data to the robot

Thanks in advance,
Dimitri

I would start by reading some of the information that has already been posted to CD:

If you have questions after that, feel free to post back.

Thanks for the link, and sorry for the late repley. But I would really appreciate it if you could explain to me how this worked. I open the file they uploaded in netBeans, and loaded the libraries, but I didn’t know what the classpath was and there was abunch of errors everywhere. Also if you could explain to me how the whole network thing worked I would greatly appreciate it. I know this is a lot to ask, so thanks in advance.

I fixed all the errors, but I still don’t know what any of the code does.

Thanks,
Dimitri

I assume you’re talking about the code the 341 posted (“DaisyCV”). I would suggest PMing Jared with questions, as he was the one who wrote it.

In terms of how sending images over the network works in general, most teams this year connected their cameras directly to the WiFi bridge on the robot, so the camera was part of the same network as the driver station and the cRIO. Thus, the driver station laptop can request images directly from the camera (the WPIlib libraries for all three languages contain code to do this), then the driver station can process these images. It’s possible to write programs in any of the three languages to run on the driver station, or you could even use a language not supported by FIRST if you are feeling adventurous.

You’ll want to do as much processing on the driver station as you can to get the information into as compressed a form as possible, which will reduce the amount of network traffic. Ideally, you should only be sending back (pan, tilt, distance) triplets, (pan, motorSpeed), or something similar (obviously, the required information will depend on your robot’s design).

The only challenge remaining, then, is how to send the results of the processing back to the cRIO. You can roll your own communication channel using a raw UDP connection, but you can also use the SmartDashboard facilities built into WPIlib, which is what 341 did, which give you an easy way to communicate data values between the driver station and the cRIO, which is what it looks like 341 did (you can see them writing the values on lines 285-289 of DaisyCVWidget.java).

I looked through the code again and I think I understand it, but what I don’t get is how to use smartdashboard to send data to the robot

You use the Robot.getTable() in your dashboard extension, which returns a NetworkTable that you can use to set individual data elements (using putInt(…), putDouble(…), etc).

Then on the robot, you use SmartDashboard (which, if you look at its source, is basically a thin wrapper around the same NetworkTable as the Robot class returns to the dashboard extension) to retrieve those values. You can also use these classes in the opposite direction. The NetworkTable does the work of transferring the values between the robot and the dashboard and vice versa.

So if my dashboard extension has

Robot.getTable().beginTransaction();
Robot.getTable().putBoolean("found", true);
Robot.getTable().putDouble("azimuth", azimuth);
Robot.getTable().putDouble("rpms", rpms);
Robot.getTable().endTransaction();

then, I just need to put

SmartDashboard().getDouble("azimuth");

in my robot code to get the value?

It would be

new SmartDashboard().getDouble("azimuth");

and I would store a SmartDashboard instance somewhere so you don’t have to keep recreating it, but otherwise I believe that should work. Keep in mind obvious issues of propagation delay

what is propagation delay?

In this case, the time it takes changes to values in the NetworkTable made on either the driver station or the cRIo to show up on the other end.

This will be non-zero because it takes time to encode the values, send them over the network, then decode them on the other side. In most cases this will be 10s or 100s of milliseconds, unless you’re sending a large amount of data.

I was looking online and I found another vision project from another team. This like has the youtube video about the tracker and the link for the code is in the description.

My problem however is that when I try to compile it is says there is no main class.

Thanks for all you help so far,
Dimitri

You shouldn’t be trying to compile it as a standalone program. First, it should be compiled as a library. Second, you’ll probably have to fix a whole bunch of reference problems by telling it where the SmartDashboard, WPIJavaCV, and a few javacv jars are (these should all be in C:\Program Files\SmartDashboard and its subdirectories). Then, once you get it compiled, put it in SmartDashboard’s extensions directory (C:\Program Files\SmartDashboard\extensions by default), then add it to your SmartDashboard by first enabling “Editable” mode (View -> Editable) then adding it (View -> Add…, select your extension). I can’t remember offhand whether you need to be in Editable mode to add extensions, but if you definitely do if you want to move them around on the panel, so I’d recommend doing it in Editable mode.