Sending MjpegServer to Smart Dashboard

I have code (in Java) I’m planning to use in order to be able to switch between two (or more) UsbCameras.

As of now, the code I have is posted here. Besides the possible existing errors (should be error-free however), I don’t know how to display the MJEG Server in SmartDashboard.

I have attempted to “Add MJPG Server” along with “Add CameraServer”, and have also tried various ways to edit the properties, including changing it to the name of Mjpeg, changing to port number, etc.

Help would be appreciated. Thanks!

As you’ve discovered, SmartDashboard has two methods for showing MJPG streams. “Add MJPG Server” requires you to enter the URL manually (e.g. http://roborio-XX-frc.local:1181/stream.mjpg, or :5800 based on your current code). “Add CameraServer” is smarter–it uses NetworkTables to enumerate the available cameras, as well as get the correct URL to get the selected camera’s stream. The latter requires the use of the WPILib CameraServer class rather than using the cscore classes directly (as the CameraServer class is what publishes the camera information to NetworkTables).

I would recommend using the CameraServer approach unless you have a strong reason to do something different, because it is much more robust in our dynamic networking environment–it will round-robin between multiple IP address options as well as get the robot IP from the DS (only if running on the same computer).

1 Like

We’re trying to use CameraServer with a camera that does 640x480 at 120fps. We tried to set the fps via the Dashboard to 30, but the stream still seems to be coming in at 90-120fps, causing our bandwidth to exceed 14mbps.

Any tips on how to limit CameraServer to 30fps?

Are you setting the camera to a VideoMode that it supports? If you have wpilib 2017.3.1, you can look at the cscore webserver to see the modes that the camera supports. You can also use the enumerateVideoModes on the camera to get an arrray of all video modes that it supports. You can do this with any 2017 version of wpilib.