Commit 4ba26a40 authored by Ken Tossell's avatar Ken Tossell
Browse files

sample ROS driver using libuvc

cmake_minimum_required(VERSION 2.4.6)
# 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)
include $(shell rospack find mk)/
\ No newline at end of file
#include $(shell rospack find mk)/
.PHONY: clean download
-DCMAKE_INSTALL_PREFIX=`rospack find libuvc`/libuvc
mkdir -p build
@git clone 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
rm -rf build libuvc
<description brief="libuvc">
Device driver library for USB Video Class devices.
<author>Ken Tossell</author>
<review status="unreviewed" notes=""/>
<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"/>
<rosdep name="libusb-1.0"/>
cmake_minimum_required(VERSION 2.4.6)
# 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)
#set the default path for built executables to the "bin" directory
#set the default path for built libraries to the "lib" directory
#uncomment if you have defined messages
#uncomment if you have defined services
#common commands for building c++ executables and libraries
#rosbuild_add_library(${PROJECT_NAME} src/example.cpp)
#target_link_libraries(${PROJECT_NAME} another_library)
#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)
include $(shell rospack find mk)/
\ No newline at end of file
\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.
<description brief="libuvc_camera">
ROS camera driver using libusb
<review status="unreviewed" notes=""/>
<depend package="roscpp"/>
<depend package="sensor_msgs"/>
<depend package="libuvc"/>
/** @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");
sensor_msgs::Image image;
image.width = rgb_frame->width;
image.height = rgb_frame->height;
image.encoding = "rgb8";
image.step = image.width * 3; * image.height);
memcpy(&([0]), rgb_frame->data, rgb_frame->data_bytes);
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_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("Device closed");
puts("UVC exited");
return 0;
<description brief="libuvc_ros">libuvc in ROS</description>
<author>Maintained by Ken Tossell</author>
<review status="unreviewed" notes=""/>
<depend stack="ros" />
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment