Two Cameras and switching

Hello,
I am sorry for posting another two camera post, but we are close to figuring out what we want to accomplish, however, we hit a snag translating the ideas put forth on other posts here and on wpilib to python.

We have cameras working on our robot currently, but want to be able to use our joystick to switch between the two on the robot before sending the signal out.

We have the example vision.py working.

from cscore import CameraServer

def main():
    cs1 = CameraServer.getInstance()
    cs1.enableLogging()
    cs2 = CameraServer.getInstance()
    cs2.enableLogging()
    

    usb1 = cs1.startAutomaticCapture(dev=0)
    usb2 = cs2.startAutomaticCapture(dev=1)

    cs1.waitForever()
    cs2.waitForever()

This is run from our robot.py file using…

wpilib.CameraServer.launch('vision.py:main')

The issue is, we are confused as to how to limit the output stream to one camera, and in which file (robot.py or vision.py)
to implement the chooser.

server = frc::CameraServer::GetInstance()->GetServer();

does not seem to be implemented in robotpy (at least not in the same way).

As you’ve noticed, this is difficult in RobotPy because cscore stuff resides in a different process (vision.py).

The easiest way to deal with this is to have your joystick code to set a value in NetworkTables, and then have your vision code use a NetworkTables callback to change it when signaled.

1 Like

Thank you,
That makes sense. How do I create only one output stream to the dashboard? With the above code, we set two streams. How do we enable both cameras, but create only one output stream (I think we can figure out how to then use the network tables to switch between the two cameras)?

On a totally unrelated note, we are also working on using a Pigeon IMU. Is there a way to disable the test for sim when we build and push our code? We are relying on the py -3 robot.py test to validate our code. I know we should wrap Pigeon (and rev) code in conditional statements to ensure stability and usability in the simulator, but in order to keep our code as streamlined as possible, we may skip it.

Thanks again for developing this. We would not have as many student developers on the team without Python support. It is incredible.

Sorry, missed that part of your question. I added an example earlier in the season: https://github.com/robotpy/robotpy-cscore/blob/master/examples/switched_cameraserver.py

There is a --skip-tests option for deploy. I’ve been meaning to implement some minimal pigeon support… which APIs are you missing? Comment on https://github.com/robotpy/robotpy-ctre/issues/104 and maybe I’ll do that tomorrow.

1 Like

That seemed to work (at least in the simulator). I will test on a Rio tomorrow.

I saw that you pushed a new commit to a new Pigeon branch of the CTRE library. I do not mind testing it, but how would we go about installing the branch? I assume we would need to compile it correct?

The simulator doesn’t actually test vision code.

To run the branch I pushed, you would need to build it, correct (but not compile it). I’ll probably push a release later today, I generally try to keep PR’s open for a period of time in case there are any code review related comments.

1 Like

Thanks.
While I know the simulator does not check vision code (especially in Windows), it does test the network tables piece, and though the addresses will change, I was able to verify that the camera stream would switch with a button press.

Thank you. The recent update allows us to use sim again without commenting out our gyro. So, with those changes, is it possible to add a Pigeon to our physics.py? If so, any advice as to how to add it?

I added it to the documentation when I made the changes :slight_smile:

https://robotpy.readthedocs.io/projects/ctre/en/latest/api_pigeonimu.html#ctre.pigeonimu.PigeonIMU

1 Like

Thanks, I cannot believe I missed it. By the way, it works perfectly.