Skip to content

Commit

Permalink
Merge pull request #80 from plusone-robotics/add_roswtf/indigo_devel
Browse files Browse the repository at this point in the history
Add a simple roswtf plugin that checks the number of connected devices
  • Loading branch information
130s committed Jul 18, 2018
2 parents 93794e4 + 506b0d0 commit 9851f78
Show file tree
Hide file tree
Showing 9 changed files with 225 additions and 6 deletions.
11 changes: 6 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,21 @@ env:
- ROS_DISTRO="indigo" ROS_REPO=ros
- ROS_DISTRO="indigo" ROS_REPO=ros-shadow-fixed
- ROS_DISTRO="indigo" PRERELEASE=true
- ROS_DISTRO="jade" ROS_REPO=ros
- ROS_DISTRO="kinetic" ROS_REPO=ros ABICHECK_URL='github:ros-drivers/openni2_camera#indigo-devel'
- ROS_DISTRO="kinetic" ROS_REPO=ros-shadow-fixed ABICHECK_URL='github:ros-drivers/openni2_camera#indigo-devel'
- ROS_DISTRO="kinetic" PRERELEASE=true
- ROS_DISTRO="lunar" ROS_REPO=ros ABICHECK_URL='github:ros-drivers/openni2_camera#indigo-devel'
- ROS_DISTRO="lunar" ROS_REPO=ros-shadow-fixed ABICHECK_URL='github:ros-drivers/openni2_camera#indigo-devel'
- ROS_DISTRO="lunar" ROS_REPO=ros
- ROS_DISTRO="lunar" ROS_REPO=ros-shadow-fixed
- ROS_DISTRO="lunar" PRERELEASE=true
- ROS_DISTRO="melodic" ROS_REPO=ros ABICHECK_URL='github:ros-drivers/openni2_camera#indigo-devel'
- ROS_DISTRO="melodic" ROS_REPO=ros-shadow-fixed ABICHECK_URL='github:ros-drivers/openni2_camera#indigo-devel'
- ROS_DISTRO="melodic" PRERELEASE=true
matrix:
allow_failures:
- env: ROS_DISTRO="indigo" PRERELEASE=true # Run docker-based ROS prerelease test http://wiki.ros.org/bloom/Tutorials/PrereleaseTest Because we might not want to run prerelease test for all PRs, it's omitted from pass-fail criteria.
- env: ROS_DISTRO="indigo" PRERELEASE=true
- env: ROS_DISTRO="jade" ROS_REPO=ros
- env: ROS_DISTRO="kinetic" PRERELEASE=true
- env: ROS_DISTRO="lunar" PRERELEASE=true
- env: ROS_DISTRO="melodic" PRERELEASE=true
install:
- git clone https://github.com/ros-industrial/industrial_ci.git .ci_config
script:
Expand Down
2 changes: 1 addition & 1 deletion openni2_launch/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 2.8.3)
project(openni2_launch)

find_package(catkin)

catkin_python_setup()
catkin_package()

install(DIRECTORY launch
Expand Down
72 changes: 72 additions & 0 deletions openni2_launch/doc/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,78 @@ E.g. When 2 openni2-based cameras are connected and `lsusb -t` returns the follo

TBD

Support tools
==========

Check the number of devices plugged in by `roswtf plugin <http://wiki.ros.org/roswtf/Plugins>`_.
Change the number of devices to expect by setting the number in ROS parameter "``openni2_num_sensors_expected``".

Example: ::

$ lsusb
:
Bus 005 Device 002: ID 1d27:0601 ASUS
Bus 003 Device 002: ID 1d27:0601 ASUS
term-1$ roscore
term-2$ roswtf
Loaded plugin tf.tfwtf
Loaded plugin openni2_launch.wtf_plugin
No package or stack in context
================================================================================
Static checks summary:
Found 1 error(s).
ERROR Different number of openni2 sensors found.
* 2 openni2 sensors found (expected: 1).
================================================================================
Beginning tests of your ROS graph. These may take awhile...
analyzing graph...
... done analyzing graph
running graph rules...
... done running graph rules
Online checks summary:
Found 1 warning(s).
Warnings are things that may be just fine, but are sometimes at fault
WARNING The following node subscriptions are unconnected:
* /rosout:
* /rosout

After setting `openni2_num_sensors_expected` param with 2, no error occurs. ::

term-2$ rosparam set openni2_num_sensors_expected 2
$ roswtf
Loaded plugin tf.tfwtf
Loaded plugin openni2_launch.wtf_plugin
No package or stack in context
================================================================================
Static checks summary:
No errors or warnings
================================================================================
Beginning tests of your ROS graph. These may take awhile...
analyzing graph...
... done analyzing graph
running graph rules...
... done running graph rules

Online checks summary:
Found 1 warning(s).
Warnings are things that may be just fine, but are sometimes at fault
WARNING The following node subscriptions are unconnected:
* /rosout:
* /rosout

Indices and tables
==================

Expand Down
4 changes: 4 additions & 0 deletions openni2_launch/launch/includes/device.launch.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

<!-- Driver parameters -->
<arg name="device_id" />
<arg name="id_manufacturer" />
<arg name="id_product" />
<arg name="rgb_frame_id" />
<arg name="depth_frame_id" />
<arg name="rgb_camera_info_url" />
Expand Down Expand Up @@ -34,6 +36,8 @@
args="load openni2_camera/OpenNI2DriverNodelet $(arg manager) $(arg bond)"
respawn="$(arg respawn)">
<param name="device_id" type="str" value="$(arg device_id)" />
<param name="id_manufacturer" type="str" value="$(arg id_manufacturer)" />
<param name="id_product" type="str" value="$(arg id_product)" />
<param name="rgb_camera_info_url" value="$(arg rgb_camera_info_url)" />
<param name="depth_camera_info_url" value="$(arg depth_camera_info_url)" />
<param name="rgb_frame_id" value="$(arg rgb_frame_id)" />
Expand Down
7 changes: 7 additions & 0 deletions openni2_launch/launch/openni2.launch
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@
'#1' : the first device found
'2@X' : the Xth device on USB bus 2"/>

<arg name="id_manufacturer" default="1d27"
doc="Vendor ID of the sensor (maintained at http://www.linux-usb.org/usb-ids.html). Default: ASUS."/>
<arg name="id_product" default="0601"
doc="Product ID of the sensor. Default: Xtion."/>

<arg name="rgb_camera_info_url" default=""
doc="By default, calibrations are stored to file://${ROS_HOME}/camera_info/${NAME}.yaml,
where ${NAME} is of the form '[rgb|depth]_[serial#]', e.g. 'depth_B00367707227042B'.
Expand Down Expand Up @@ -72,6 +77,8 @@
file="$(find openni2_launch)/launch/includes/device.launch.xml">
<arg name="manager" value="$(arg manager)" />
<arg name="device_id" value="$(arg device_id)" />
<arg name="id_manufacturer" value="$(arg id_manufacturer)" />
<arg name="id_product" value="$(arg id_product)" />
<arg name="rgb_frame_id" value="$(arg rgb_frame_id)" />
<arg name="depth_frame_id" value="$(arg depth_frame_id)" />
<arg name="rgb_camera_info_url" value="$(arg rgb_camera_info_url)" />
Expand Down
3 changes: 3 additions & 0 deletions openni2_launch/package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,11 @@
<run_depend>image_proc</run_depend>
<run_depend>nodelet</run_depend>
<run_depend>openni2_camera</run_depend>
<run_depend>rospy</run_depend>
<run_depend>roswtf</run_depend>
<run_depend>tf</run_depend>
<export>
<rosdoc config="rosdoc.yaml"/>
<roswtf plugin="openni2_launch.wtf_plugin" />
</export>
</package>
11 changes: 11 additions & 0 deletions openni2_launch/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
## ! DO NOT MANUALLY INVOKE THIS setup.py, USE CATKIN INSTEAD

from distutils.core import setup
from catkin_pkg.python_setup import generate_distutils_setup

# fetch values from package.xml
setup_args = generate_distutils_setup(
packages=["openni2_launch"],
package_dir={'': 'src'})

setup(**setup_args)
Empty file.
121 changes: 121 additions & 0 deletions openni2_launch/src/openni2_launch/wtf_plugin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
# Software License Agreement (BSD License)
#
# Copyright (c) 2018, PlusOne Robotics, Inc. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
#
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above
# copyright notice, this list of conditions and the following
# disclaimer in the documentation and/or other materials provided
# with the distribution.
# * Neither the name of Plus One Robotics, Inc. nor the names of its
# contributors may be used to endorse or promote products derived
# from this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.

from __future__ import print_function
import logging
import re
import subprocess

import rospy
from roswtf.rules import warning_rule, error_rule


def _device_notfound_subproc(id_manufacturer, id_product):
"""
@rtype: [dict]
@return: Example:
[{'device': '/dev/bus/usb/002/004', 'tag': 'Lenovo ', 'id': '17ef:305a'},
{'device': '/dev/bus/usb/002/001', 'tag': 'Linux Foundation 3.0 root hub', 'id': '1d6b:0003'},
{'device': '/dev/bus/usb/001/006', 'tag': 'Validity Sensors, Inc. ', 'id': '138a:0090'},,,]
@note: This method depends on Linux command (via subprocess), which makes
this command platform-dependent. Ubuntu Xenial onward, a Python module
that encapsulate platform operation becomes available so this method
can be wiped out. See https://github.com/ros-drivers/openni2_camera/pull/80#discussion_r193295442
"""
device_re = re.compile("Bus\s+(?P<bus>\d+)\s+Device\s+(?P<device>\d+).+ID\s(?P<id>\w+:\w+)\s(?P<tag>.+)$", re.I)
df = subprocess.check_output("lsusb")
devices = []
for i in df.split('\n'):
if i:
info = device_re.match(i)
if info:
dinfo = info.groupdict()
logging.debug("dinfo: {}, dinfo.id: {}".format(dinfo, dinfo["id"]))
if dinfo["id"] == "{}:{}".format(id_manufacturer, id_product):
dinfo['device'] = "/dev/bus/usb/{}/{}".format(dinfo.pop('bus'), dinfo.pop('device'))
devices.append(dinfo)
logging.info("#devices: {}\ndevices: {}".format(len(devices), devices))
return devices


def sensor_notfound(ctx):
"""
@summary: Check if expected number of sensors are found.
Expected number of sensors can be set by
ROS Parameter 'openni2_num_sensors_expected'.
@note: Technically this can be static check, but because of the
need for connecting to ROS Param server, this needs
to be online check.
"""
errors = []
num_sensors_expected = rospy.get_param("openni2_num_sensors_expected", 1)
# The set of manufacture id and prod id. Default: Asus Xtion.
id_manufacturer = rospy.get_param("id_manufacturer", "1d27")
id_product = rospy.get_param("id_product", "0601")
devices = _device_notfound_subproc(
id_manufacturer=id_manufacturer, id_product=id_product)
num_sensors = len(devices)
if num_sensors != num_sensors_expected:
errors.append("{} openni2 sensors found (expected: {}).".format(
num_sensors, num_sensors_expected))
return errors


# app_warnings and app_errors declare the rules that we actually check
app_warnings_online = [
]

app_warnings_static = [
]

app_errors_online = [
(sensor_notfound, "Different number of openni2 sensors found."),
]

app_errors_static = [
]


# roswtf entry point for online checks
def roswtf_plugin_online(ctx):
for r in app_warnings_online:
warning_rule(r, r[0](ctx), ctx)
for r in app_errors_online:
error_rule(r, r[0](ctx), ctx)


def roswtf_plugin_static(ctx):
for r in app_warnings_static:
warning_rule(r, r[0](ctx), ctx)
for r in app_errors_static:
error_rule(r, r[0](ctx), ctx)

0 comments on commit 9851f78

Please sign in to comment.