Java Dual Camera Code Help

code

#1

I transferred/converted the example c++ code from the FIRST page for switching cameras into java. I have changed a few things to make it easier to read and I cannot get rid of this one error. “Cannot make a static reference to the non-static method getSubTable(String) from the type NetworkTable” I have been experimenting with the code and browsing the Internet for hours trying to find a solution. Our goal is to be able to switch between two cameras on the FRC Dashboard with one button. If anyone could help, or point me in the correct direction. I would really appreciate it.

Thanks,
4125


#2

I haven’t looked at the example code in a while, but you would need a NetworkTable instance most likely. You would get one by calling NetworkTable.getTable. there was likely a similar call in the c++ example.

One thing I did notice is you are still using eclipse with the old 2018 build setup. The eclipse setup does not work anymore, and when you try to install the 2019 image you’ll notice that will no longer work anymore. The new setup using vscode and Gradle. You can find steps to set up and install the new setup here.
https://wpilib.screenstepslive.com/s/currentCS/m/getting_started/l/999999-installing-c-and-java-development-tools-for-frc


#3

Those NetworkTable lines aren’t important to what you’re trying to do, so you can simply remove them. Or alternatively, those lines should read:

NetworkTableInstance.getTable("").getEntry("CameraSelection").setString(_camera2.getName());

and similarly for camera1.getName().

You should also remove the portion where you initialize the UsbCamera objects with new UsbCamera(null, 0);

Your functions are private so I don’t know how you’re going to call them, but if they were in the main robot class they should be robotInit() and teleopPeriodic().

One other tip: add to the initialization code the following for each camera:
_camera1.setConnectionStrategy(VideoSource.ConnectionStrategy.kKeepOpen);
This will keep both cameras open so switching between them is fast.

The article on screensteps is a bit out of date, we’ll work on updating it.


#4

In regards to still using eclipse, I did this because after installing vscode I could not figure out how to add the Phoenix Framework from CTRE into it. I need this because we use SRX’s and hope to use some others in the future. How do I add such things into visual studio?


#5

General documentation for how to install third party libraries into vscode is here: http://wpilib.screenstepslive.com/s/currentCS/m/getting_started/l/682619-3rd-party-libraries

CTRE also has documentation for their libraries, which includes installation instructions: https://phoenix-documentation.readthedocs.io/en/latest/index.html


#6

Are you trying to use the USBCamera class? That would make your life significantly easier. If not, that’s the limit of my expertise :grin: