Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using multiple cameras efficiently #60

Open
msadowski opened this issue Apr 16, 2019 · 9 comments
Open

Using multiple cameras efficiently #60

msadowski opened this issue Apr 16, 2019 · 9 comments

Comments

@msadowski
Copy link

Hi!

I've been trying to figure out this one for quite a while now. I have 3 cameras (same manufacturer and model), when checking the settings the 3 parameters of vendor, product and serial are the same. The only way I can launch different cameras is by modifying the index parameter.

Is there any way I can have a control of the camera index? Ideally I would like to prefix my camera names according to the robot placement (forward, left, right). If the driver used the device path (/dev/video0 etc) then I would create a symlink based on the USB port the device is connected to.

Any tips how could I solve this particular problem? I know uvc_camera node can take a device path but I would prefer to stick with libuvc_ros if possible.

@7675t
Copy link
Contributor

7675t commented Apr 22, 2019

Why don't you try serial parameter to specify the serial number of the device? See Wiki and dynamic config.

In addition, I'm sure it is possible to specify device number corresponding to the serial number using udev settings.

@msadowski
Copy link
Author

@7675t thanks a lot for your feedback. I just came back to working on this!

I was just testing it a bit. Here is my launch file:

<launch>
  <arg name="node_name" default="camera_elp_1" />
  <arg name="frame_id" default="camera" />
  <arg name="index" default="-1" />

  <group ns="$(arg node_name)">
    <node pkg="libuvc_camera" type="camera_node" name="elp_camera">
      <!-- Set the frame id-->
      <param name="frame_id" value="$(arg frame_id)" />
      <param name="device" value="/dev/video3" />
      <!-- Parameters used to find the camera -->
      <param name="vendor" value="0x05a3"/>
      <param name="product" value="0x9422"/>
      <!-- <param name="serial" value="/dev/video2"/> -->
      <!-- If the above parameters aren't unique, choose the first match: -->
      <param name="index" value="$(arg index)"/>

      <!-- Image size and type -->
      <!-- 2592x1944, 1920,1080, 1600,1200, ... /-->
      <param name="width" value="640"/>
      <param name="height" value="480"/>
      <!-- choose whichever uncompressed format the camera supports: -->
      <param name="video_mode" value="mjpeg"/> <!-- or yuyv/nv12/mjpeg -->
      <param name="frame_rate" value="15"/>

      <param name="timestamp_method" value="start"/> <!-- start of frame -->

      <param name="auto_exposure" value="3"/> <!-- use aperture_priority auto exposure -->
      <!-- <param name="absolute_exposure" value="0"/>  -->
      <param name="auto_white_balance" value="true"/>
      <param name="brightness" value="120"/>
      <param name="contrast" value="160"/>
      <param name="saturation" value="128"/>

    </node>

  </group>

</launch>

What I noticed is that if I don't add the serial parameter the node starts just fine. When I specify the serial as "/dev/video2", where my camera is the node dies with the error:

process[camera_elp_1/elp_camera-2]: started with pid [21267]
uvc_find_device: No such device (-4)
[camera_elp_1/elp_camera-2] process has died [pid 21267, exit code 255, cmd /opt/ros/melodic/lib/libuvc_camera/camera_node __name:=elp_camera __log:=/home/mat/.ros/log/63b391d0-8903-11e9-8754-a0c589a0e934/camera_elp_1-elp_camera-2.log].
log file: /home/mat/.ros/log/63b391d0-8903-11e9-8754-a0c589a0e934/camera_elp_1-elp_camera-2*.log

I tested the uvc_node with /dev/video2 and it worked just fine.

When running rqt_dynamic_reconfigure and selecting "elp_camera" the rqt_reconfigure dies with an error:

Traceback (most recent call last):
  File "/opt/ros/melodic/lib/python2.7/dist-packages/rqt_reconfigure/node_selector_widget.py", line 275, in _selection_changed_slot
    self._selection_selected(index_current, rosnode_name_selected)
  File "/opt/ros/melodic/lib/python2.7/dist-packages/rqt_reconfigure/node_selector_widget.py", line 225, in _selection_selected
    item_widget = item_child.get_dynreconf_widget()
  File "/opt/ros/melodic/lib/python2.7/dist-packages/rqt_reconfigure/treenode_qstditem.py", line 154, in get_dynreconf_widget
    self._param_name_raw)
  File "/opt/ros/melodic/lib/python2.7/dist-packages/rqt_reconfigure/dynreconf_client_widget.py", line 90, in __init__
    self.reconf.config_callback = self.config_callback
  File "/opt/ros/melodic/lib/python2.7/dist-packages/dynamic_reconfigure/client.py", line 276, in set_config_callback
    self._config_callback(self.config)
  File "/opt/ros/melodic/lib/python2.7/dist-packages/rqt_reconfigure/dynreconf_client_widget.py", line 113, in config_callback
    widget.update_value(config[widget.param_name])
  File "/opt/ros/melodic/lib/python2.7/dist-packages/rqt_reconfigure/param_editors.py", line 439, in update_value
    self._update_signal.emit(self.values.index(value))
ValueError: -1732753462 is not in list
Aborted

I'll see if I can find a source of the error. If I make any discoveries I'm happy to update the docs!

@7675t
Copy link
Contributor

7675t commented Jun 7, 2019

'/dev/video2' is the name of the device file, not a serial number. You can check the serial number with lsusb command (iSerialNumber). Some USB device doesn't have it, so please check it.

@msadowski
Copy link
Author

@7675t I see, thanks for clarifying that! Unfortunately all the cameras that I have report the same serial number.

It seems to me that the only way forward is using a library that works directly with device files. Thanks for all the help!

@msadowski
Copy link
Author

@7675t a final question - maybe you will know the answer!

What exactly is the index parameter? and where is it coming from? I noticed that when I specify indices of 4 of my cameras to 0, 1, 2 and 3 I always access the same camera when launching all 4 of them.

I tried plugging the cameras in random order to the same USB ports and as long as I plug them to the same port the configuration seems consistent. If the index is by any chance tied to the serial device index in the system this would most probably solve all my problems!

Happy to update the docs to make this param function clearer if my suspicion is right!

@7675t
Copy link
Contributor

7675t commented Jun 17, 2019

Wiki says the index is the order number of devices which have same vid and pid. Code is here. I'm not sure the order is always same, sorry. But in my experience, if we plug the devices into same USB port at boot time, they are assigned to same bus and same port and assigned same device number in same order, so you may be able to use index.

And as I mentioned before, you may be able to use udev.rules to fix the device name corresponding to the port number etc. (Please search the way in the web). There is even a bit tricky way to use external program in udev.rules to identify the devices.
https://www.clearpathrobotics.com/assets/guides/ros/Udev%20Rules.html

Good luck.

@ridhwankamil
Copy link

@msadowski have u got a workaround for this issue, im also facing the same problem connecting 2 identical camera

@msadowski
Copy link
Author

msadowski commented Jan 11, 2021 via email

@fettahyildizz
Copy link

In my case, usb camera devices which I always plug in ports in same order, are assigned to different indexes by libuvc each time I reboot robot's computer so this creates a mess in my workspace. I couldn't find other way than working with usb_cam package.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants