Rehost Camera Stream on DS

We would like to view the camera from the robot in 2 different windows on our driverstation. I assume for example using smart dashboard and shuffleboard to display the camera will utilize twice the bandwith from the robot, so if this is correct, has anyone managed to rehost or proxy (or something) the stream on the DS? Preferably low latency.

Yes, unless you serve it from the DS, each stream will be separate from the robot, doubling the bandwidth.

It’s possible to compile a desktop wpilib-based CameraServer program that rehosts the streams. The bare-bones Java main code for this looks something like: (replace TEAM / TE.AM as appropriate)

// rehost robot camera to localhost port 1181
HttpCamera camera = new HttpCamera("robot camera", "http://10.TE.AM.2:1181/?action=stream");
MjpegServer server = new MjpegServer("robot camera copy server", 1181);
server.setSource(camera);

// start NetworkTables
NetworkTableInstance ntinst = NetworkTableInstance.getDefault();
ntinst.startClientTeam(TEAM);

// publish camera information to NetworkTables so it's visible to dashboards
NetworkTable table = ntinst.getTable("/CameraPublisher/robot camera copy");
table.getEntry("source").setString("http");
table.getEntry("description").setString("copy of robot camera");
table.getEntry("streams").setStringArray(new String[] {"mjpg:http://127.0.0.1:1181/?action=stream"});

// sleep forever
for (;;) { try { Thread.sleep(10000); } catch (InterruptedException ex) { return; }}

This will show up as a “robot camera copy” camera in Shuffleboard.

I’m not well versed in gradle, but @SamCarlberg or @Thad_House can provide the right bits to actually build this.

As Peter posted above, you can use the code he posted in order to build a forwarder on desktop. As for the project build setup, the easiest way is to create a new Java project in VS Code, and then replace the build.gradle file with the desktop one located at the link below. You’ll need to replace the ###GRADLERIOREPLACE### with the gradlerio version generated by your project (if you have the newest version it should be 2019.4.1). You then need to replace ###ROBOTCLASSREPLACE### With the main class where you want your main function to be. You’ll then have all access to the desktop versions of the libraries, and can use the simulate functionality in vscode to run it.

Alright, I’ll give that a go.
Is there a way to compile it and run without VSCode?

You need enough of a Java boilerplate project to actually run “.\gradlew build”. The easiest way to do that is with vscode, but you could probably copy your robot project and edit it like the above…

You might want to check the latency once you have a prototype. Any intermediate server is going to add some. I don’t have a feel for how much, but certainly it won’t be milliseconds, I would guess more like 50 ms.

An alternative would be to write a new viewer app. You could steal the code from one of the existing dashboards, and write a program which opens 2 separate windows and puts the camera image on both. But that would mean 2 displays running from a single computer.

Thinking about it, I could just use OpenCV to throw up a pair of windows. Do you see an issue with that?

If that works for your DS, then it is probably the better solution.

Alright, thankyou.

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.