Multicamera switching not working

I am from team 7034 TBD and we are currently trying to use multiple cameras for our robot in order to help the drivers. To use the multiple cameras we have used camera switching using python to create a switch and change between each camera based on a networktable value. We are currently having problems with the switching as at seemingly random times the switching will stop working and the feed would freeze on the last image until switched to the same camera or sometimes both stop. After the frame freezes in order for us to get it back we need to unplug the frozen camera(s) from the Raspberry pi and then plug them back in. We are using a Raspberry pi getting power from the PDP with a power converter because at first we thought that the Raspberry pi may not be getting enough power. We had also tried running the robot and sometimes the voltage would drop to even around 8 volts (on the Driver Station) and the cameras would be fine, but at other times we would still have 12 volts and the cameras would crash. We are currently using two Logitech c615 cameras. The code that we are using is the default camera switching code given by First on the FRC WPILib dashboard for Raspberry pi.

Is the rPi code written in Python or your robot code? Did you customize the Python code on the rPi at all? If so, can you post it somewhere? If not, have you tried the builtin code instead of the Python version? What version of the FRCVision image are you using? What dashboard are you using?

we have been having a similar issue. usually, if i just wait a few seconds the picture will come back, but only sometimes. i usually have to switch back and forth a couple times first for some reason. let me know if you are able to find a solution to this issue, id be very interested. sorry for not being able to offer any help.

Are you using the kKeepOpen feature? What FRCVision version and what dashboard are you using?

id have to ask our programmer, ill let you know

I know we aren’t using the kKeepOpen feature and we currently are on version 2019.3.1 for the dashboard. The code is written in Python. This is the code here.
from cscore import CameraServer, UsbCamera
import networktables

def main():
cs = CameraServer.getInstance()
cs.enableLogging()

usb0 = UsbCamera("front_cam", 0)
usb1 = UsbCamera("rear_cam", 1)

server = cs.addSwitchedCamera("TEST_STREAM")
server.setSource(usb0)

# Use networktables to switch the source
# -> obviously, you can switch them however you'd like
def _listener(source, key, value, isNew):
    if str(value) == "0":
        server.setSource(usb0)
    elif str(value) == "1":
        server.setSource(usb1)

table = networktables.NetworkTables.getTable("/SmartDashboard")
table.putString("switching", "0")
table.addEntryListener(_listener, key="switching")

cs.waitForever()

if name == “main”:

# To see messages from networktables, you must setup logging
import logging

logging.basicConfig(level=logging.DEBUG)

# You should change this to connect to the RoboRIO
networktables.NetworkTables.initialize(server="10.70.34.2")

main()

Are you using python for programming the robot or just camera switching? Because it works fine for me in Java.

Use it. It will fix the issue you are describing regarding delays/occasional breakage in switching between the cameras. The default behavior is to close the camera when it’s not in use. That saves USB bandwidth and a bit of CPU (neither of which are a concern on the Pi), but many cameras are glitchy or take a long time to reconnect. Setting the connection strategy to “keep open” means that the camera stays connected even if the collected frames aren’t actually being used; this will make switching basically instantaneous. In retrospect I probably should have changed the default to “keep open” this year, but water under the bridge…

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