How to map USB inputs in Docker?

I'm having trouble mapping USB input for use in the Docker cointeiner. I want to use my KinectV2 which is connected to the USB port, I've tried :

xhost +

docker run --rm -it --user ros -v /dev:/dev --device-cgroup-rule='c *:* rmw' -v /run/udev:/run/udev --ipc=host pu:v4 bash

and inside Docker when I run lsusb

Bus 002 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub

Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub

The Kinect, outside the docker when I run lsusb, is seen as:

Bus 004 Device 002: ID 045e:02c4 Microsoft Corp. Xbox NUI Sensor

Below is my Dockerfile:

FROM osrf/ros:noetic-desktop

ARG ROS_DISTRO=noetic

ARG USERNAME=ros
ARG USER_UID=1000
ARG USER_GID=$USER_UID

RUN groupadd --gid $USER_GID $USERNAME \
 && useradd -s /bin/bash --uid $USER_UID --gid $USER_GID -m $USERNAME \
 && mkdir /home/$USERNAME/.config && chown $USER_UID:$USER_GID /home/$USERNAME/.config


# Set up sudo
RUN apt-get update \
 && apt-get install -y sudo \
 && echo $USERNAME ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/$USERNAME\
 && chmod 0440 /etc/sudoers.d/$USERNAME \
 && rm -rf /var/lib/apt/lists/*



# install ros packages
RUN apt-get update && apt-get install -y &&\
   apt-get install python3-pip -y && \
   rm -rf /var/lib/apt/lists/*

RUN apt-get update && \
   apt-get install build-essential cmake pkg-config  -y && \
   apt-get install libusb-1.0-0-dev -y && \        
   apt-get install libturbojpeg0-dev -y && \ 
   apt-get install libglfw3-dev -y && \         
   apt-get install libopenni2-dev -y && \
   apt-get install git -y && \
   apt-get install ros-noetic-catkin -y
        
RUN apt update && apt upgrade -y \
   && apt install -y \
   libusb-1.0-0-dev \
   libturbojpeg \
   libturbojpeg0-dev \
   libjpeg-turbo8-dev \
   libglfw3-dev \
   libopenni2-dev \
   freeglut3-dev \
   uuid-dev \
   libsdl2-dev \
   usbutils \
   python3-catkin-tools \
   python3-rosdep \
   alsa-utils \
   ros-${ROS_DISTRO}-ros-core \
   ros-${ROS_DISTRO}-vision-opencv \
   ros-${ROS_DISTRO}-nodelet-core \
   ros-${ROS_DISTRO}-perception-pcl \
   ros-${ROS_DISTRO}-compressed-depth-image-transport \
   ros-${ROS_DISTRO}-compressed-image-transport \
   ros-${ROS_DISTRO}-geometry \
   ros-${ROS_DISTRO}-depth-image-proc \
   python3-opencv \
   udev \
   nano \
   && apt-get clean

WORKDIR /home

RUN git clone https://github.com/OpenKinect/libfreenect2.git

WORKDIR /home/libfreenect2

RUN mkdir build &&\
   cd build && \
   cmake .. \
   -DCMAKE_INSTALL_PREFIX=$HOME/freenect2 \
   -DENABLE_CXX11=ON && \
   make && \
   make install && \
   mkdir -p /etc/udev/rules.d/ && \
   cp /home/libfreenect2/platform/linux/udev/90-kinect2.rules /etc/udev/rules.d/

WORKDIR /home

RUN mkdir -p kinect_ws/src

WORKDIR /home/kinect_ws/src

RUN git clone https://github.com/paul-shuvo/iai_kinect2_opencv4.git

WORKDIR /home/kinect_ws/src/iai_kinect2_opencv4

RUN rosdep install -r -y --from-paths .

WORKDIR /home/kinect_ws

I'm having trouble mapping USB input for use in the Docker cointeiner. I want to use my KinectV2 which is connected to the USB port, I've tried

xhost +

`docker run --rm -it --user ros -v /dev:/dev --device-cgroup-rule='c : rmw' -v /run/udev:/run/udev --ipc=host pu:v4 bash

Upvotes: 0

Views: 43

Answers (0)

Related Questions