withrobot / oCam

oCam - USB 3.0 Board Camera
GNU General Public License v3.0
54 stars 61 forks source link

Launch multiple cameras by referencing serial number #28

Closed kololhe closed 1 year ago

kololhe commented 1 year ago

I have multiple oCam-1CGN-U-T cameras on my system, and I wanted to access them all, but the current version just selects one of the cameras and shows the output. Referencing the camera by serial number would make the driver device agnostic, meaning that the type of camera won't matter (except for oCam-1MGN-U-T2 and oCam-1CGN-U-T2 where flag0144 must be set to true). Attaching a possible solution below, since I don't have access to submit a PR.

    void enum_dev_list(std::vector<Withrobot::usb_device_info> dev_list, std::string serial)
    {
        /* enumerate device(UVC compatible devices) list */
        // std::vector<Withrobot::usb_device_info> dev_list;
        dev_num = Withrobot::get_usb_device_info_list(dev_list);

        if (dev_num < 1) {
            dev_list.clear();

            return;
        }

        for (unsigned int i=0; i < dev_list.size(); i++) {

            if (dev_list[i].serial == serial)
            {
                devPath_ = dev_list[i].dev_node;
                return;
            } 
        }
    }

With a few further modifications to source the appropriate calibration files, the code builds fine, and yields to following output.

kololhe@AxiomMeanMachine:~/BarCam_ws$ roslaunch ocam ocam_ros.launch 
... logging to /home/kololhe/.ros/log/add17f1a-c75d-11ed-9554-095d547f1c37/roslaunch-AxiomMeanMachine-23985.log
Checking log directory for disk usage. This may take a while.
Press Ctrl-C to interrupt
Done checking log file disk usage. Usage is <1GB.

started roslaunch server http://AxiomMeanMachine:43851/

SUMMARY
========

PARAMETERS
 * /first/auto_exposure: True
 * /first/camera_frame_id: first
 * /first/exposure: 100
 * /first/frame_rate: 30
 * /first/gain: 50
 * /first/resolution: 0
 * /first/serial: SN_35E27022
 * /first/show_image: False
 * /first/wb_blue: 200
 * /first/wb_red: 160
 * /rosdistro: noetic
 * /rosversion: 1.16.0
 * /second/auto_exposure: True
 * /second/camera_frame_id: second
 * /second/exposure: 100
 * /second/frame_rate: 30
 * /second/gain: 50
 * /second/resolution: 0
 * /second/serial: SN_35E27001
 * /second/show_image: False
 * /second/wb_blue: 200
 * /second/wb_red: 160

NODES
  /
    first (ocam/ocam)
    second (ocam/ocam)

auto-starting new master
process[master]: started with pid [24004]
ROS_MASTER_URI=http://localhost:11311

setting /run_id to add17f1a-c75d-11ed-9554-095d547f1c37
process[rosout-1]: started with pid [24025]
started core service [/rosout]
process[first-2]: started with pid [24032]
process[second-3]: started with pid [24033]
Pixel format: G, R, B, G
Width: 1280, Height: 720, Image size: 921600
Frame Rate : 1 / 30 (30.00 fps)
[ INFO] [1679344068.711970232]: Initialized the camera
[ INFO] [1679344068.776446204]: Loading from ROS calibration files
[ INFO] [1679344068.776824041]: camera calibration URL: package://ocam/config/SN_35E27001.yaml
[ INFO] [1679344068.776966185]: Unable to open camera calibration file [/home/kololhe/BarCam_ws/src/ocam/config/SN_35E27001.yaml]
[ WARN] [1679344068.776993685]: Camera calibration file /home/kololhe/BarCam_ws/src/ocam/config/SN_35E27001.yaml not found.
[ INFO] [1679344068.777014391]: Got camera calibration files
Pixel format: G, R, B, G
Width: 1280, Height: 720, Image size: 921600
Frame Rate : 1 / 30 (30.00 fps)
[ INFO] [1679344068.808915614]: Initialized the camera
[ INFO] [1679344068.827498129]: Success, found camera
[ INFO] [1679344068.860870276]: Loading from ROS calibration files
[ INFO] [1679344068.861179044]: camera calibration URL: package://ocam/config/SN_35E27022.yaml
[ INFO] [1679344068.861271352]: Unable to open camera calibration file [/home/kololhe/BarCam_ws/src/ocam/config/SN_35E27022.yaml]
[ WARN] [1679344068.861286993]: Camera calibration file /home/kololhe/BarCam_ws/src/ocam/config/SN_35E27022.yaml not found.
[ INFO] [1679344068.861307703]: Got camera calibration files
[ INFO] [1679344068.863593057]: Success, found camera