Permalink
Browse files

sample ROS driver using libuvc

  • Loading branch information...
0 parents commit 4ba26a40b40f75fb5c9a7c039be0e989cbe26198 @ktossell committed Feb 8, 2012
@@ -0,0 +1,17 @@
+cmake_minimum_required(VERSION 2.4.6)
+include($ENV{ROS_ROOT}/core/rosbuild/rosbuild.cmake)
+
+# Append to CPACK_SOURCE_IGNORE_FILES a semicolon-separated list of
+# directories (or patterns, but directories should suffice) that should
+# be excluded from the distro. This is not the place to put things that
+# should be ignored everywhere, like "build" directories; that happens in
+# rosbuild/rosbuild.cmake. Here should be listed packages that aren't
+# ready for inclusion in a distro.
+#
+# This list is combined with the list in rosbuild/rosbuild.cmake. Note
+# that CMake 2.6 may be required to ensure that the two lists are combined
+# properly. CMake 2.4 seems to have unpredictable scoping rules for such
+# variables.
+#list(APPEND CPACK_SOURCE_IGNORE_FILES /core/experimental)
+
+rosbuild_make_distribution(0.1.0)
@@ -0,0 +1 @@
+include $(shell rospack find mk)/cmake_stack.mk
@@ -0,0 +1,18 @@
+#include $(shell rospack find mk)/cmake.mk
+.PHONY: clean download
+
+CMAKE=cmake
+CMAKE_ARGS=-DCMAKE_BUILD_TYPE=Release \
+ -DCMAKE_INSTALL_PREFIX=`rospack find libuvc`/libuvc
+
+all:
+ mkdir -p build
+ @git clone git://github.com/ktossell/libuvc.git build/git || (echo "INFO: skipping clone"; true)
+ cd build/git && git pull
+ mkdir -p build/build
+ cd build/build && $(CMAKE) ../git $(CMAKE_ARGS)
+ cd build/build && make && make install
+
+clean:
+ rm -rf build libuvc
+
@@ -0,0 +1,18 @@
+<package>
+ <description brief="libuvc">
+
+ Device driver library for USB Video Class devices.
+
+ </description>
+ <author>Ken Tossell</author>
+ <license>BSD</license>
+ <review status="unreviewed" notes=""/>
+ <url>http://ros.org/wiki/libuvc</url>
+ <export>
+ <cpp cflags="-I${prefix}/libuvc/include" lflags="-L${prefix}/libuvc/lib -Wl,-rpath,-L${prefix}/libuvc/lib -lros"/>
+ <cpp os="osx" cflags="-I${prefix}/libuvc/include" lflags="-L${prefix}/libuvc/lib -Wl,-rpath,-L${prefix}/libuvc/lib -lrosthread -framework CoreServices"/>
+ </export>
+ <rosdep name="libusb-1.0"/>
+</package>
+
+
@@ -0,0 +1,34 @@
+cmake_minimum_required(VERSION 2.4.6)
+include($ENV{ROS_ROOT}/core/rosbuild/rosbuild.cmake)
+
+# Set the build type. Options are:
+# Coverage : w/ debug symbols, w/o optimization, w/ code-coverage
+# Debug : w/ debug symbols, w/o optimization
+# Release : w/o debug symbols, w/ optimization
+# RelWithDebInfo : w/ debug symbols, w/ optimization
+# MinSizeRel : w/o debug symbols, w/ optimization, stripped binaries
+#set(ROS_BUILD_TYPE RelWithDebInfo)
+
+rosbuild_init()
+
+#set the default path for built executables to the "bin" directory
+set(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin)
+#set the default path for built libraries to the "lib" directory
+set(LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/lib)
+
+#uncomment if you have defined messages
+#rosbuild_genmsg()
+#uncomment if you have defined services
+#rosbuild_gensrv()
+
+#common commands for building c++ executables and libraries
+#rosbuild_add_library(${PROJECT_NAME} src/example.cpp)
+#target_link_libraries(${PROJECT_NAME} another_library)
+#rosbuild_add_boost_directories()
+#rosbuild_link_boost(${PROJECT_NAME} thread)
+#rosbuild_add_executable(example examples/example.cpp)
+#target_link_libraries(example ${PROJECT_NAME})
+
+rosbuild_add_executable(libuvc_camera src/libuvc_camera.cpp)
+
+
@@ -0,0 +1 @@
+include $(shell rospack find mk)/cmake.mk
@@ -0,0 +1,26 @@
+/**
+\mainpage
+\htmlinclude manifest.html
+
+\b uvc_camera_experimental is ...
+
+<!--
+Provide an overview of your package.
+-->
+
+
+\section codeapi Code API
+
+<!--
+Provide links to specific auto-generated API documentation within your
+package that is of particular interest to a reader. Doxygen will
+document pretty much every part of your code, so do your best here to
+point the reader to the actual API.
+
+If your codebase is fairly large or has different sets of APIs, you
+should use the doxygen 'group' tag to keep these APIs together. For
+example, the roscpp documentation has 'libros' group.
+-->
+
+
+*/
@@ -0,0 +1,16 @@
+<package>
+ <description brief="libuvc_camera">
+
+ ROS camera driver using libusb
+
+ </description>
+ <author></author>
+ <license>BSD</license>
+ <review status="unreviewed" notes=""/>
+ <url>http://ros.org/wiki/libuvc_camera</url>
+ <depend package="roscpp"/>
+ <depend package="sensor_msgs"/>
+ <depend package="libuvc"/>
+</package>
+
+
@@ -0,0 +1,101 @@
+/** @file test_ros_ctrls.cpp Example/test usage of libuvc */
+#include <ros/ros.h>
+#include <sensor_msgs/Image.h>
+#include "libuvc/libuvc.h"
+
+ros::Publisher pub;
+
+void cb(uvc_frame_t *frame) {
+ static uvc_frame_t *rgb_frame = NULL;
+ uvc_error_t uvc_ret;
+
+ if (!rgb_frame)
+ rgb_frame = uvc_allocate_frame(frame->width * frame->height * 3);
+
+ uvc_ret = uvc_any2rgb(frame, rgb_frame);
+
+ if (uvc_ret) {
+ uvc_perror(uvc_ret, "Couldn't convert frame to RGB");
+ return;
+ }
+
+ sensor_msgs::Image image;
+ image.width = rgb_frame->width;
+ image.height = rgb_frame->height;
+ image.encoding = "rgb8";
+ image.step = image.width * 3;
+ image.data.resize(image.step * image.height);
+ memcpy(&(image.data[0]), rgb_frame->data, rgb_frame->data_bytes);
+
+ pub.publish(image);
+}
+
+int main (int argc, char **argv) {
+ ros::init(argc, argv, "libuvc_camera");
+ ros::NodeHandle nh;
+
+ pub = nh.advertise<sensor_msgs::Image>("image_raw", 1);
+
+ uvc_context_t *ctx;
+ uvc_error_t res;
+ uvc_device_t *dev;
+ uvc_device_handle_t *devh;
+ uvc_stream_ctrl_t ctrl;
+
+ res = uvc_init(&ctx, NULL);
+
+ if (res < 0) {
+ uvc_perror(res, "uvc_init");
+ return res;
+ }
+
+ puts("UVC initialized");
+
+ res = uvc_find_device(
+ ctx, &dev,
+ 0, // vendor
+ 0, // product
+ NULL); // serial number (string)
+
+ if (res < 0) {
+ uvc_perror(res, "uvc_find_device");
+ } else {
+ res = uvc_open(dev, &devh);
+ if (res < 0) {
+ uvc_perror(res, "uvc_open");
+ } else {
+ puts("Device opened");
+
+ uvc_print_diag(devh, stderr);
+
+ res = uvc_get_stream_ctrl_format_size(
+ devh, &ctrl,
+ UVC_COLOR_FORMAT_UNCOMPRESSED, 640, 480, 30);
+
+ uvc_print_stream_ctrl(&ctrl, stderr);
+
+ if (res < 0) {
+ uvc_perror(res, "get_mode");
+ } else {
+ res = uvc_start_iso_streaming(devh, &ctrl, cb);
+
+ if (res < 0) {
+ uvc_perror(res, "start_streaming");
+ } else {
+ puts("Streaming...");
+ ros::spin();
+ uvc_stop_streaming(devh);
+ }
+ }
+
+ uvc_close(devh);
+ puts("Device closed");
+ }
+ }
+
+ uvc_exit(ctx);
+ puts("UVC exited");
+
+ return 0;
+}
+
@@ -0,0 +1,9 @@
+<stack>
+ <description brief="libuvc_ros">libuvc in ROS</description>
+ <author>Maintained by Ken Tossell</author>
+ <license></license>
+ <review status="unreviewed" notes=""/>
+ <url>http://ros.org/wiki/libuvc_ros</url>
+ <depend stack="ros" />
+
+</stack>

0 comments on commit 4ba26a4

Please sign in to comment.