first commit

parents
build/
bin/
lib/
msg_gen/
srv_gen/
msg/*Action.msg
msg/*ActionFeedback.msg
msg/*ActionGoal.msg
msg/*ActionResult.msg
msg/*Feedback.msg
msg/*Goal.msg
msg/*Result.msg
msg/_*.py
# Generated by dynamic reconfigure
*.cfgc
/cfg/cpp/
/cfg/*.py
# Ignore generated docs
*.dox
*.wikidoc
# eclipse stuff
.project
.cproject
# qcreator stuff
CMakeLists.txt.user
srv/_*.py
*.pcd
*.pyc
qtcreator-*
*.user
/planning/cfg
/planning/docs
/planning/src
*~
# Emacs
.#*
# Catkin custom files
CATKIN_IGNORE
cmake_minimum_required(VERSION 2.8.7)
project(ros_depthsense_camera)
###############################################################################
## Note by Myzhar ##
## =============== ##
## ##
## If you get an exception error of the type: ##
## "ERROR: no enumerator found, some dll files are missing" ##
## ##
## you must run this command in a terminal: ##
## ##
## 64 bit systems: ##
## $ sudo ln -s /lib/x86_64-linux-gnu/libudev.so.1.3.5 /usr/lib/libudev.so.0 ##
## 32 bit systems: ##
## $ sudo ln –s /lib/i386-linux-gnu/libudev.so.1 /usr/lib/libudev.so.0 ##
## ##
## To be able to access the video streams you need to add your user to the ##
## "video" usergroup entering the following commands: ##
## ##
## $ sudo adduser ubuntu video [replace "ubuntu" with your current username] ##
## $ sudo chmod g+rw /dev/video* ##
## ##
## REMEMBER TO DELETE "CMakeCache.txt" if you want to change compilation ##
## options ##
###############################################################################
###############################################################################
## Options
option( DEBUG_ACTIVE "Enable Debug build" ON )
if(DEBUG_ACTIVE)
MESSAGE( "Debug compilation active" )
set(ROS_BUILD_TYPE Debug)
set(CMAKE_BUILD_TYPE Debug)
else()
MESSAGE( "Release compilation active" )
set(ROS_BUILD_TYPE Release)
set(CMAKE_BUILD_TYPE Release)
endif()
###############################################################################
###############################################################################
## CUDA
find_package(CUDA)
if(CUDA_FOUND)
try_run(RUN_RESULT_VAR COMPILE_RESULT_VAR
${CMAKE_BINARY_DIR}
${CMAKE_CURRENT_SOURCE_DIR}/cuda_test/has_cuda_gpu.c
CMAKE_FLAGS
-DINCLUDE_DIRECTORIES:STRING=${CUDA_TOOLKIT_INCLUDE}
-DLINK_LIBRARIES:STRING=${CUDA_CUDART_LIBRARY}
COMPILE_OUTPUT_VARIABLE COMPILE_OUTPUT_VAR
RUN_OUTPUT_VARIABLE RUN_OUTPUT_VAR)
message("${RUN_OUTPUT_VAR}") # Display number of GPUs found
# COMPILE_RESULT_VAR is TRUE when compile succeeds
# RUN_RESULT_VAR is zero when a GPU is found
if(COMPILE_RESULT_VAR AND NOT RUN_RESULT_VAR)
set(CUDA_HAVE_GPU TRUE CACHE BOOL "Whether CUDA-capable GPU is present")
else()
set(CUDA_HAVE_GPU FALSE CACHE BOOL "Whether CUDA-capable GPU is present")
endif()
endif(CUDA_FOUND)
###############################################################################
find_package(catkin REQUIRED COMPONENTS
image_transport
roscpp
std_msgs
tf
)
catkin_package(
CATKIN_DEPENDS
std_msgs
sensor_msgs
geometry_msgs
image_transport
)
###############################################################################
# INCLUDES
set(depthsense_INC_DIRS
src/
src/driver/include/
/opt/softkinetic/DepthSenseSDK/include
)
# Specify locations of header files.
include_directories(
${catkin_INCLUDE_DIRS}
${depthsense_INC_DIRS}
)
###############################################################################
###############################################################################
# CUDA SOURCES
if(CUDA_HAVE_GPU)
add_definitions(-DWITH_CUDA)
set(cuda_SRC_DIR src/driver/cuda)
set(cuda_SRC ${cuda_SRC_DIR}/)
SET(CUDA_NVCC_FLAGS "-arch=sm_13" CACHE STRING "nvcc flags" FORCE)
#HW capability 1.3
SET (CUDA_VERBOSE_BUILD ON CACHE BOOL "nvcc verbose" FORCE)
SET(LIB_TYPE STATIC) #set the lib type
CUDA_ADD_LIBRARY(Cuda2Dscan ${LIB_TYPE} ${cuda_SRC} )
endif(CUDA_HAVE_GPU)
###############################################################################
###############################################################################
# SOURCES
set(depthsense_SRC
src/depthsense_camera_node.cpp
src/driver/src/depthsense_camera_driver.cpp
)
###############################################################################
###############################################################################
# EXECUTABLE
add_executable(
depthsense_camera_node
${depthsense_SRC}
)
find_library(DEPTHSENSE_LIBRARY DepthSense DepthSensePlugins turbojpeg /opt/softkinetic/DepthSenseSDK/lib/)
if(CUDA_HAVE_GPU)
add_dependencies(depthsense_camera_node Cuda2Dscan)
target_link_libraries(depthsense_camera_node
${catkin_LIBRARIES} ${DEPTHSENSE_LIBRARY} Cuda2Dscan)
else()
target_link_libraries(
depthsense_camera_node
${catkin_LIBRARIES} ${DEPTHSENSE_LIBRARY}
)
endif(CUDA_HAVE_GPU)
###############################################################################
GNU LESSER GENERAL PUBLIC LICENSE
Version 3, 29 June 2007
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
This version of the GNU Lesser General Public License incorporates
the terms and conditions of version 3 of the GNU General Public
License, supplemented by the additional permissions listed below.
0. Additional Definitions.
As used herein, "this License" refers to version 3 of the GNU Lesser
General Public License, and the "GNU GPL" refers to version 3 of the GNU
General Public License.
"The Library" refers to a covered work governed by this License,
other than an Application or a Combined Work as defined below.
An "Application" is any work that makes use of an interface provided
by the Library, but which is not otherwise based on the Library.
Defining a subclass of a class defined by the Library is deemed a mode
of using an interface provided by the Library.
A "Combined Work" is a work produced by combining or linking an
Application with the Library. The particular version of the Library
with which the Combined Work was made is also called the "Linked
Version".
The "Minimal Corresponding Source" for a Combined Work means the
Corresponding Source for the Combined Work, excluding any source code
for portions of the Combined Work that, considered in isolation, are
based on the Application, and not on the Linked Version.
The "Corresponding Application Code" for a Combined Work means the
object code and/or source code for the Application, including any data
and utility programs needed for reproducing the Combined Work from the
Application, but excluding the System Libraries of the Combined Work.
1. Exception to Section 3 of the GNU GPL.
You may convey a covered work under sections 3 and 4 of this License
without being bound by section 3 of the GNU GPL.
2. Conveying Modified Versions.
If you modify a copy of the Library, and, in your modifications, a
facility refers to a function or data to be supplied by an Application
that uses the facility (other than as an argument passed when the
facility is invoked), then you may convey a copy of the modified
version:
a) under this License, provided that you make a good faith effort to
ensure that, in the event an Application does not supply the
function or data, the facility still operates, and performs
whatever part of its purpose remains meaningful, or
b) under the GNU GPL, with none of the additional permissions of
this License applicable to that copy.
3. Object Code Incorporating Material from Library Header Files.
The object code form of an Application may incorporate material from
a header file that is part of the Library. You may convey such object
code under terms of your choice, provided that, if the incorporated
material is not limited to numerical parameters, data structure
layouts and accessors, or small macros, inline functions and templates
(ten or fewer lines in length), you do both of the following:
a) Give prominent notice with each copy of the object code that the
Library is used in it and that the Library and its use are
covered by this License.
b) Accompany the object code with a copy of the GNU GPL and this license
document.
4. Combined Works.
You may convey a Combined Work under terms of your choice that,
taken together, effectively do not restrict modification of the
portions of the Library contained in the Combined Work and reverse
engineering for debugging such modifications, if you also do each of
the following:
a) Give prominent notice with each copy of the Combined Work that
the Library is used in it and that the Library and its use are
covered by this License.
b) Accompany the Combined Work with a copy of the GNU GPL and this license
document.
c) For a Combined Work that displays copyright notices during
execution, include the copyright notice for the Library among
these notices, as well as a reference directing the user to the
copies of the GNU GPL and this license document.
d) Do one of the following:
0) Convey the Minimal Corresponding Source under the terms of this
License, and the Corresponding Application Code in a form
suitable for, and under terms that permit, the user to
recombine or relink the Application with a modified version of
the Linked Version to produce a modified Combined Work, in the
manner specified by section 6 of the GNU GPL for conveying
Corresponding Source.
1) Use a suitable shared library mechanism for linking with the
Library. A suitable mechanism is one that (a) uses at run time
a copy of the Library already present on the user's computer
system, and (b) will operate properly with a modified version
of the Library that is interface-compatible with the Linked
Version.
e) Provide Installation Information, but only if you would otherwise
be required to provide such information under section 6 of the
GNU GPL, and only to the extent that such information is
necessary to install and execute a modified version of the
Combined Work produced by recombining or relinking the
Application with a modified version of the Linked Version. (If
you use option 4d0, the Installation Information must accompany
the Minimal Corresponding Source and Corresponding Application
Code. If you use option 4d1, you must provide the Installation
Information in the manner specified by section 6 of the GNU GPL
for conveying Corresponding Source.)
5. Combined Libraries.
You may place library facilities that are a work based on the
Library side by side in a single library together with other library
facilities that are not Applications and are not covered by this
License, and convey such a combined library under terms of your
choice, if you do both of the following:
a) Accompany the combined library with a copy of the same work based
on the Library, uncombined with any other library facilities,
conveyed under the terms of this License.
b) Give prominent notice with the combined library that part of it
is a work based on the Library, and explaining where to find the
accompanying uncombined form of the same work.
6. Revised Versions of the GNU Lesser General Public License.
The Free Software Foundation may publish revised and/or new versions
of the GNU Lesser General Public License from time to time. Such new
versions will be similar in spirit to the present version, but may
differ in detail to address new problems or concerns.
Each version is given a distinguishing version number. If the
Library as you received it specifies that a certain numbered version
of the GNU Lesser General Public License "or any later version"
applies to it, you have the option of following the terms and
conditions either of that published version or of any later version
published by the Free Software Foundation. If the Library as you
received it does not specify a version number of the GNU Lesser
General Public License, you may choose any version of the GNU Lesser
General Public License ever published by the Free Software Foundation.
If the Library as you received it specifies that a proxy can decide
whether future versions of the GNU Lesser General Public License shall
apply, that proxy's public statement of acceptance of any version is
permanent authorization for you to choose that version for the
Library.
# depthdense_camera_ros
ROS node to acquire RGB and 3D data from SoftKinetic DepthSense cameras
## Note by Myzhar
If you get an exception error of the type:
```
ERROR: no enumerator found, some dll files are missing"
```
you must run this command in a terminal:
###64 bit systems:
```
$ sudo ln -s /lib/x86_64-linux-gnu/libudev.so.1.3.5 /usr/lib/libudev.so.0
```
###32 bit systems:
```
$ sudo ln –s /lib/i386-linux-gnu/libudev.so.1 /usr/lib/libudev.so.0
```
To be able to access the video streams you need to add your user to the
video" usergroup entering the following commands:
```
$ sudo adduser ubuntu video [replace "ubuntu" with your current username]
$ sudo chmod g+rw /dev/video*
```
<?xml version="1.0"?>
<package>
<name>ros_depthsense_camera</name>
<version>0.1.0</version>
<description>ROS Package to connect to SoftKinetic DepthSense cameras</description>
<author email="myzhar@robot-home.it">Walter 'Myzhar' Lucetti</author>
<maintainer email="myzhar@robot-home.it">Walter 'Myzhar' Lucetti</maintainer>
<license>LGPL v3</license>
<buildtool_depend>catkin</buildtool_depend>
<build_depend>std_msgs</build_depend>
<build_depend>geometry_msgs</build_depend>
<build_depend>sensor_msgs</build_depend>
<build_depend>tf</build_depend>
<build_depend>image_transport</build_depend>
<run_depend>std_msgs</run_depend>
<run_depend>geometry_msgs</run_depend>
<run_depend>sensor_msgs</run_depend>
<run_depend>tf</run_depend>
<run_depend>image_transport</run_depend>
</package>
#include <stdio.h>
#include <cuda_runtime.h>
int main()
{
int deviceCount, device;
int gpuDeviceCount = 0;
struct cudaDeviceProp properties;
cudaError_t cudaResultCode = cudaGetDeviceCount(&deviceCount);
if (cudaResultCode != cudaSuccess)
deviceCount = 0;
/* machines with no GPUs can still report one emulation device */
for (device = 0; device < deviceCount; ++device)
{
cudaGetDeviceProperties(&properties, device);
if (properties.major != 9999) /* 9999 means emulation only */
++gpuDeviceCount;
}
printf("%d GPU CUDA device(s) found\n", gpuDeviceCount);
/* don't just return the number of gpus, because other runtime cuda
errors can also yield non-zero return values */
if (gpuDeviceCount > 0)
return 0; /* success */
else
return 1; /* failure */
}
#include <stdlib.h>
#include <ros/ros.h>
#include <depthsense_camera_driver.h>
int main(int argc, char** argv)
{
ros::init(argc, argv, "depthsense_camera_node");
ROS_INFO_STREAM("-----------------------------------\r");
ROS_INFO_STREAM(" SoftKinetic DepthSense Node \r");
ROS_INFO_STREAM("-----------------------------------\r");
DepthSenseDriver cameraDriver;
cameraDriver.run();
ros::spin();
ROS_INFO_STREAM( "... shutting down complete." );
return(EXIT_SUCCESS);
}
#include <DepthSense.hxx>
#include <ros/ros.h>
#include <csignal>
#include <list>
#include <image_transport/image_transport.h>
#include <std_msgs/Header.h>
#include <sensor_msgs/Image.h>
#include <sensor_msgs/PointCloud2.h>
using namespace std;
class DepthSenseDriver
{
public:
struct NodeInfo
{
DepthSense::Node node;
int32_t sampleCount;
int32_t totalSampleCount;
int32_t droppedSampleCount;
int32_t width;
int32_t height;
float range;
};
DepthSenseDriver();
~DepthSenseDriver();
bool init();
void release();
void run();
private:
void onDeviceAdded(DepthSense::Context context, DepthSense::Device device);
void onDeviceRemoved(DepthSense::Context context, DepthSense::Device device);
void onNodeAdded(DepthSense::Device device, DepthSense::Node node);
void onNodeRemoved(DepthSense::Device device, DepthSense::Node node);
bool addDepthNode(DepthSense::Device device, DepthSense::Node node, int32_t& width, int32_t& height , float& range);
bool addColorNode(DepthSense::Device device, DepthSense::Node node, int32_t& width, int32_t& height );
bool addAudioNode(DepthSense::Device device, DepthSense::Node node);
NodeInfo* findInfo(DepthSense::Node node);
void onNewDepthNodeSampleReceived(DepthSense::DepthNode node, DepthSense::DepthNode::NewSampleReceivedData data);
void onNewColorNodeSampleReceived(DepthSense::ColorNode node, DepthSense::ColorNode::NewSampleReceivedData data);
void contextQuit();
// >>>>> Ctrl+C handler
/*! Ctrl+C handler
*/
static void sighandler(int signo)
{
DepthSenseDriver::_stopping = (signo == SIGINT);
}
// <<<<< Ctrl+C handler
private:
ros::NodeHandle _nh;
ros::Publisher _vertex_pub;
// Image transportation
image_transport::ImageTransport _imgTr;
image_transport::CameraPublisher _rgb_pub;
DepthSense::Context _context; ///< DepthSense context
std::list<DepthSense::Device> _devices;
std::list<NodeInfo*> _nodeInfos;
bool _initialized;
bool _streaming;
bool _error;
static bool _stopping;
bool _publish_tf;
// >>>>> Camera parameters
DepthSense::IntrinsicParameters _depthIntrinsics;
DepthSense::IntrinsicParameters _colorIntrinsics;
DepthSense::ExtrinsicParameters _extrinsics;
// <<<<< Camera parameters
// >>>>> RGB ROS Message
std_msgs::Header _lastRgbMsgHeader;
sensor_msgs::Image _lastRgbMsg;
// <<<<< RGB ROS Message
// >>>>> Pointcloud ROS Message
std_msgs::Header _lastPtCloudMsgHeader;
sensor_msgs::PointCloud2 _lastPtCloud;
// <<<<< Pointcloud ROS Message
};
#include "depthsense_camera_driver.h"
#include <sensor_msgs/image_encodings.h>
#include <sensor_msgs/CameraInfo.h>
#include <sensor_msgs/distortion_models.h>
#include <tf/tf.h>
#include <tf/transform_broadcaster.h>
#include <sensor_msgs/point_cloud2_iterator.h>
#ifndef DEG2RAD
#define DEG2RAD 0.017444444
#define RAD2DEG 57.324842225
#endif
#ifndef RAD2DEG
#define RAD2DEG 57.324842225
#endif
bool DepthSenseDriver::_stopping = false;
typedef sensor_msgs::PointCloud2 PointCloud;
DepthSenseDriver::DepthSenseDriver()
: _initialized(false)
, _streaming(false)
, _error(false)
, _imgTr(_nh)
{
struct sigaction sigAct;
memset( &sigAct, 0, sizeof(sigAct) );
sigAct.sa_handler = DepthSenseDriver::sighandler;
sigaction(SIGINT, &sigAct, 0);
_vertex_pub = _nh.advertise<sensor_msgs::PointCloud2>("vertex_data", 1, false);
_rgb_pub = _imgTr.advertiseCamera("rgb_image", 1, false);
_publish_tf = true;
}
DepthSenseDriver::~DepthSenseDriver()
{
release();
}
void DepthSenseDriver::contextQuit()
{
do
{
try
{
_context.quit();
}
catch (DepthSense::InvalidOperationException& e)
{
ROS_ERROR_STREAM( "Error quitting context: " << e.what() );
}
} while (0);
}
bool DepthSenseDriver::init()
{
if( _initialized )
{
return true;
}
_context = DepthSense::Context::createStandalone();
std::vector<DepthSense::Device> devices = _context.getDevices();
int noDeviceCount = 0;
do
{
devices = _context.getDevices();
if( devices.size() == 0 )
{
if( noDeviceCount>60 || _stopping )
{
ROS_WARN_STREAM( "Aborting node... ");
_error = true;
return false;
}
noDeviceCount++;
ROS_WARN_STREAM( "#" << noDeviceCount << " No connected device found... ");
ros::Duration(1.0).sleep(); // sleep for 1 seconds
}
} while( devices.size()==0 );
_context.deviceAddedEvent().connect(this, &DepthSenseDriver::onDeviceAdded);
_context.deviceRemovedEvent().connect(this, &DepthSenseDriver::onDeviceRemoved);
for (unsigned int i = 0; i < devices.size(); i++)
{
onDeviceAdded(_context, devices[i]);
std::vector<DepthSense::Node> nodes = devices[i].getNodes();
for (unsigned int j = 0; j < nodes.size(); j++)
{
onNodeAdded(devices[i], nodes[j]);
}
}
<