first commit

This commit is contained in:
andre neto
2024-01-15 12:27:47 +00:00
commit e230795cd9
364 changed files with 39952 additions and 0 deletions
+45
View File
@@ -0,0 +1,45 @@
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Changelog for package laser_proc
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
0.1.6 (2020-04-24)
------------------
* Update required cmake version
* Contributors: Jon Binney
0.1.5 (2018-08-09)
------------------
* update to use non deprecated pluginlib macro
* Contributors: Jonathan Binney, Mikael Arguedas
0.1.4 (2014-03-30)
------------------
* Install fix for Android.
* Contributors: Chad Rockey
0.1.3 (2013-08-21)
------------------
* No more Willow Garage email.
* Contributors: Chad Rockey
0.1.2 (2013-03-14)
------------------
* Uncaught except when subscribing to most_intense on non-intensity scans.
* Updated function to be const.
* Contributors: chadrockey
0.1.1 (2013-03-08)
------------------
* Merge pull request `#1 <https://github.com/ros-perception/laser_proc/issues/1>`_ from ros-perception/fix_pluginlib_depend
Add missing dependency on pluginlib
* Add missing dependency on pluginlib
* Contributors: Chad Rockey, William Woodall
0.1.0 (2013-03-04)
------------------
* Minor fixes.
* Added ROS nodelet/node.
* Adjusted advertiseLaser to be more standard. Fixed seg fault with first and laser publishers.
* Preparing to test with urg_node
* Initial commit
* Contributors: Chad Rockey, chadrockey
+88
View File
@@ -0,0 +1,88 @@
cmake_minimum_required(VERSION 3.0.2)
project(laser_proc)
## Find catkin macros and libraries
## if COMPONENTS list like find_package(catkin REQUIRED COMPONENTS xyz)
## is used, also find other catkin packages
find_package(catkin REQUIRED COMPONENTS roscpp sensor_msgs rosconsole nodelet pluginlib)
###################################################
## Declare things to be passed to other projects ##
###################################################
## LIBRARIES: libraries you create in this project that dependent projects also need
## CATKIN_DEPENDS: catkin_packages dependent projects also need
## DEPENDS: system dependencies of this project that dependent projects also need
catkin_package(
INCLUDE_DIRS include
LIBRARIES laser_proc_library laser_publisher laser_transport laser_proc_ROS LaserProcNodelet
CATKIN_DEPENDS roscpp sensor_msgs rosconsole nodelet
DEPENDS
)
###########
## Build ##
###########
## Specify additional locations of header files
include_directories(include ${catkin_INCLUDE_DIRS})
## Library that does actual conversion
add_library(laser_proc_library src/LaserProc.cpp)
target_link_libraries(laser_proc_library ${catkin_LIBRARIES})
## Publisher library
add_library(laser_publisher src/LaserPublisher.cpp)
target_link_libraries(laser_publisher laser_proc_library ${catkin_LIBRARIES})
## Factory for making LaserPublishers
add_library(laser_transport src/LaserTransport.cpp)
target_link_libraries(laser_transport laser_publisher ${catkin_LIBRARIES})
## ROS Library
add_library(laser_proc_ROS src/LaserProcROS.cpp)
target_link_libraries(laser_proc_ROS laser_transport ${catkin_LIBRARIES})
## Nodelet wrapper
add_library(LaserProcNodelet src/LaserProcNodelet.cpp)
target_link_libraries(LaserProcNodelet laser_proc_ROS ${catkin_LIBRARIES})
## Node wrapper
add_executable(laser_proc src/laser_proc.cpp)
target_link_libraries(laser_proc laser_proc_ROS ${catkin_LIBRARIES})
#############
## Install ##
#############
## Mark executables and/or libraries for installation
install(TARGETS laser_proc_library laser_publisher laser_transport laser_proc_ROS LaserProcNodelet laser_proc
ARCHIVE DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
LIBRARY DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
RUNTIME DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION}
)
## Mark cpp header files for installation
install(DIRECTORY include/${PROJECT_NAME}/
DESTINATION ${CATKIN_PACKAGE_INCLUDE_DESTINATION}
FILES_MATCHING PATTERN "*.h"
PATTERN ".svn" EXCLUDE
)
## Mark other files for installation (e.g. launch and bag files, etc.)
install(FILES nodelets.xml
DESTINATION ${CATKIN_PACKAGE_SHARE_DESTINATION}
)
#############
## Testing ##
#############
## Add gtest based cpp test target and link libraries
# catkin_add_gtest(${PROJECT_NAME}-test test/test.cpp)
# if(TARGET ${PROJECT_NAME}-test)
# target_link_libraries(${PROJECT_NAME}-test ${PROJECT_NAME})
# endif()
## Add folders to be run by python nosetests
# catkin_add_nosetests(test)
+4
View File
@@ -0,0 +1,4 @@
laser_proc
==========
Converts representations of sensor_msgs/LaserScan and sensor_msgs/MultiEchoLaserScan
@@ -0,0 +1,75 @@
/*
* Copyright (c) 2013, Willow Garage, 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 the Willow Garage, 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.
*/
/*
* Author: Chad Rockey
*/
#ifndef LASER_PROC_H
#define LASER_PROC_H
#include <sensor_msgs/LaserScan.h>
#include <sensor_msgs/MultiEchoLaserScan.h>
#include <sensor_msgs/LaserEcho.h>
#include <vector>
#include <algorithm>
#include <limits.h>
#include <stdexcept>
#include <sstream>
namespace laser_proc
{
class LaserProc
{
public:
static sensor_msgs::LaserScanPtr getFirstScan(const sensor_msgs::MultiEchoLaserScan& msg);
static sensor_msgs::LaserScanPtr getLastScan(const sensor_msgs::MultiEchoLaserScan& msg);
static sensor_msgs::LaserScanPtr getMostIntenseScan(const sensor_msgs::MultiEchoLaserScan& msg);
private:
static void fillLaserScan(const sensor_msgs::MultiEchoLaserScan& msg, sensor_msgs::LaserScan& out);
static size_t getFirstValue(const sensor_msgs::LaserEcho& ranges, float& range);
static size_t getLastValue(const sensor_msgs::LaserEcho& ranges, float& range);
static void getMostIntenseValue(const sensor_msgs::LaserEcho& ranges, const sensor_msgs::LaserEcho& intensities, float& range, float& intensity);
};
}; // laser_proc
#endif
@@ -0,0 +1,82 @@
/*
* Copyright (c) 2013, Willow Garage, 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 the Willow Garage, 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.
*/
/*
* Author: Chad Rockey
*/
#ifndef LASER_PROC_ROS_H
#define LASER_PROC_ROS_H
#include <ros/ros.h>
#include <laser_proc/LaserTransport.h>
#include <sensor_msgs/LaserScan.h>
#include <sensor_msgs/MultiEchoLaserScan.h>
#include <boost/thread/mutex.hpp>
namespace laser_proc
{
class LaserProcROS
{
public:
LaserProcROS(ros::NodeHandle& n, ros::NodeHandle& pnh);
~LaserProcROS();
private:
void scanCb(const sensor_msgs::MultiEchoLaserScanConstPtr& msg) const;
/**
* Callback that is called when there is a new subscriber.
*
* Will not subscribe until we have a subscriber for our LaserScans (lazy subscribing).
*
*/
void connectCb(const ros::SingleSubscriberPublisher& pub);
/**
* Callback called when a subscriber unsubscribes.
*
* If all current subscribers of our LaserScans stop listening, stop subscribing (lazy subscribing).
*
*/
void disconnectCb(const ros::SingleSubscriberPublisher& pub);
ros::NodeHandle nh_; ///< Nodehandle used to subscribe in the connectCb.
laser_proc::LaserPublisher pub_; ///< Publisher
ros::Subscriber sub_; ///< Multi echo subscriber
boost::mutex connect_mutex_; ///< Prevents the connectCb and disconnectCb from being called until everything is initialized.
};
}; // depthimage_to_laserscan
#endif
@@ -0,0 +1,111 @@
/*
* Copyright (c) 2013, Willow Garage, 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 the Willow Garage, 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.
*/
/*
* Author: Chad Rockey
*/
#ifndef IMAGE_PROC_LASER_PUBLISHER_H
#define IMAGE_PROC_LASER_PUBLISHER_H
#include <ros/ros.h>
#include <sensor_msgs/LaserScan.h>
#include <sensor_msgs/MultiEchoLaserScan.h>
#include <sensor_msgs/LaserEcho.h>
#include <laser_proc/LaserProc.h>
#include <vector>
#include <algorithm>
#include <limits.h>
#include <stdexcept>
#include <sstream>
namespace laser_proc
{
class LaserTransport;
class LaserPublisher
{
public:
LaserPublisher() {}
/*!
* \brief Returns the number of subscribers that are currently connected to
* this LaserPublisher.
*
* Returns sum of all child publishers.
*/
uint32_t getNumSubscribers() const;
/*!
* \brief Returns the topics of this LaserPublisher.
*/
std::vector<std::string> getTopics() const;
/*!
* \brief Publish a MultiEchoLaserScan on the topics associated with this LaserPublisher.
*/
void publish(const sensor_msgs::MultiEchoLaserScan& msg) const;
/*!
* \brief Publish a MultiEchoLaserScan on the topics associated with this LaserPublisher.
*/
void publish(const sensor_msgs::MultiEchoLaserScanConstPtr& msg) const;
/*!
* \brief Shutdown the advertisements associated with this Publisher.
*/
void shutdown();
operator void*() const;
bool operator< (const LaserPublisher& rhs) const { return impl_ < rhs.impl_; }
bool operator!=(const LaserPublisher& rhs) const { return impl_ != rhs.impl_; }
bool operator==(const LaserPublisher& rhs) const { return impl_ == rhs.impl_; }
private:
LaserPublisher(ros::NodeHandle& nh, uint32_t queue_size,
const ros::SubscriberStatusCallback& connect_cb,
const ros::SubscriberStatusCallback& disconnect_cb,
const ros::VoidPtr& tracked_object, bool latch, bool publish_echoes = true);
struct Impl;
typedef boost::shared_ptr<Impl> ImplPtr;
typedef boost::weak_ptr<Impl> ImplWPtr;
ImplPtr impl_;
friend class LaserTransport;
};
}; // laser_proc
#endif
@@ -0,0 +1,57 @@
/*
* Copyright (c) 2013, Willow Garage, 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 the Willow Garage, 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.
*/
/*
* Author: Chad Rockey
*/
#ifndef IMAGE_PROC_LASER_TRANSPORT_H
#define IMAGE_PROC_LASER_TRANSPORT_H
#include <ros/ros.h>
#include <laser_proc/LaserPublisher.h>
namespace laser_proc
{
class LaserTransport
{
public:
static LaserPublisher advertiseLaser(ros::NodeHandle& nh, uint32_t queue_size, bool latch=false);
static LaserPublisher advertiseLaser(ros::NodeHandle& nh, uint32_t queue_size,
const ros::SubscriberStatusCallback& connect_cb,
const ros::SubscriberStatusCallback& disconnect_cb=ros::SubscriberStatusCallback(),
const ros::VoidPtr& tracked_object=ros::VoidPtr(), bool latch=false, bool publish_echoes=true);
};
}; // laser_proc
#endif
+11
View File
@@ -0,0 +1,11 @@
<library path="lib/libLaserProcNodelet">
<class name="laser_proc/LaserProcNodelet"
type="laser_proc::LaserProcNodelet"
base_class_type="nodelet::Nodelet">
<description>
Nodelet to convert sensor_msgs/MultiEchoLaserScans to sensor_msgs/LaserScans.
</description>
</class>
</library>
+34
View File
@@ -0,0 +1,34 @@
<?xml version="1.0"?>
<package>
<name>laser_proc</name>
<version>0.1.6</version>
<description>laser_proc</description>
<maintainer email="chadrockey@willowgarage.com">Chad Rockey</maintainer>
<license>BSD</license>
<url type="website">http://ros.org/wiki/laser_proc</url>
<url type="bugtracker">https://github.com/ros-perception/laser_proc/issues</url>
<url type="repository">https://github.com/ros-perception/laser_proce</url>
<author email="chadrockey@willowgarage.com">Chad Rockey</author>
<buildtool_depend>catkin</buildtool_depend>
<build_depend>roscpp</build_depend>
<build_depend>rosconsole</build_depend>
<build_depend>sensor_msgs</build_depend>
<build_depend>pluginlib</build_depend>
<build_depend>nodelet</build_depend>
<run_depend>roscpp</run_depend>
<run_depend>rosconsole</run_depend>
<run_depend>sensor_msgs</run_depend>
<run_depend>pluginlib</run_depend>
<run_depend>nodelet</run_depend>
<export>
<nodelet plugin="${prefix}/nodelets.xml"/>
</export>
</package>
+149
View File
@@ -0,0 +1,149 @@
/*
* Copyright (c) 2013, Willow Garage, 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 the Willow Garage, 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.
*/
/*
* Author: Chad Rockey
*/
#include <laser_proc/LaserProc.h>
using namespace laser_proc;
sensor_msgs::LaserScanPtr LaserProc::getFirstScan(const sensor_msgs::MultiEchoLaserScan& msg){
sensor_msgs::LaserScanPtr out(new sensor_msgs::LaserScan());
fillLaserScan(msg, *out);
out->ranges.resize(msg.ranges.size());
if(msg.ranges.size() == msg.intensities.size()){
out->intensities.resize(msg.intensities.size());
}
for(size_t i = 0; i < out->ranges.size(); i++){
size_t index = getFirstValue(msg.ranges[i], out->ranges[i]);
if(out->intensities.size() > 0){
if(msg.intensities[i].echoes.size() > 0){
out->intensities[i] = msg.intensities[i].echoes[index];
} else {
out->intensities[i] = 0.0;
}
}
}
return out;
}
sensor_msgs::LaserScanPtr LaserProc::getLastScan(const sensor_msgs::MultiEchoLaserScan& msg){
sensor_msgs::LaserScanPtr out(new sensor_msgs::LaserScan());
fillLaserScan(msg, *out);
out->ranges.resize(msg.ranges.size());
if(msg.ranges.size() == msg.intensities.size()){
out->intensities.resize(msg.intensities.size());
}
for(size_t i = 0; i < out->ranges.size(); i++){
size_t index = getLastValue(msg.ranges[i], out->ranges[i]);
if(out->intensities.size() > 0){
if(msg.intensities[i].echoes.size() > 0){
out->intensities[i] = msg.intensities[i].echoes[index];
} else {
out->intensities[i] = 0.0;
}
}
}
return out;
}
sensor_msgs::LaserScanPtr LaserProc::getMostIntenseScan(const sensor_msgs::MultiEchoLaserScan& msg){
sensor_msgs::LaserScanPtr out(new sensor_msgs::LaserScan());
fillLaserScan(msg, *out);
if(msg.ranges.size() == msg.intensities.size()){
out->ranges.resize(msg.ranges.size());
out->intensities.resize(msg.intensities.size());
} else {
std::stringstream ss;
ss << "getMostIntenseScan::Size of ranges does not equal size of intensities, cannot create scan.";
throw std::runtime_error(ss.str());
}
for(size_t i = 0; i < out->intensities.size(); i++){
getMostIntenseValue(msg.ranges[i], msg.intensities[i], out->ranges[i], out->intensities[i]);
}
return out;
}
void LaserProc::fillLaserScan(const sensor_msgs::MultiEchoLaserScan& msg, sensor_msgs::LaserScan& out){
out.header = msg.header;
out.angle_min = msg.angle_min;
out.angle_max = msg.angle_max;
out.angle_increment = msg.angle_increment;
out.time_increment = msg.time_increment;
out.scan_time = msg.scan_time;
out.range_min = msg.range_min;
out.range_max = msg.range_max;
}
///< @TODO I'm assuming all laserscanners/drivers output the ranges in order received (shortest to longest). If this is not the case, please make an issue.
size_t LaserProc::getFirstValue(const sensor_msgs::LaserEcho& ranges, float& range){
if(ranges.echoes.size() > 0){
size_t index = 0;
range = ranges.echoes[index];
return index;
}
range = std::numeric_limits<float>::quiet_NaN();
return 0; // Value doesn't matter
}
///< @TODO I'm assuming all laserscanners/drivers output the ranges in order received (shortest to longest). If this is not the case, please make an issue.
size_t LaserProc::getLastValue(const sensor_msgs::LaserEcho& ranges, float& range){
if(ranges.echoes.size() > 0){
size_t index = ranges.echoes.size()-1;
range = ranges.echoes[index];
return index;
}
range = std::numeric_limits<float>::quiet_NaN();
return 0; // Value doesn't matter
}
void LaserProc::getMostIntenseValue(const sensor_msgs::LaserEcho& ranges, const sensor_msgs::LaserEcho& intensities, float& range, float& intensity){
if(intensities.echoes.size() == 0){
range = std::numeric_limits<float>::quiet_NaN();
intensity = 0.0;
return;
}
std::vector<float>::const_iterator max_iter = std::max_element(intensities.echoes.begin(), intensities.echoes.end());
size_t index = std::distance(intensities.echoes.begin(), max_iter);
if(ranges.echoes.size() > 0){
range = ranges.echoes[index];
intensity = *max_iter;
} else {
range = std::numeric_limits<float>::quiet_NaN();
intensity = 0.0;
return;
}
}
+61
View File
@@ -0,0 +1,61 @@
/*
* Copyright (c) 2013, Willow Garage, 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 the Willow Garage, 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.
*/
/*
* Author: Chad Rockey
*/
#include <laser_proc/LaserProcROS.h>
#include <nodelet/nodelet.h>
namespace laser_proc
{
class LaserProcNodelet : public nodelet::Nodelet
{
public:
LaserProcNodelet() {};
~LaserProcNodelet() {}
private:
virtual void onInit()
{
lp.reset(new LaserProcROS(getNodeHandle(), getPrivateNodeHandle()));
};
boost::shared_ptr<LaserProcROS> lp;
};
}
#include <pluginlib/class_list_macros.h>
PLUGINLIB_EXPORT_CLASS(laser_proc::LaserProcNodelet, nodelet::Nodelet)
+69
View File
@@ -0,0 +1,69 @@
/*
* Copyright (c) 2013, Willow Garage, 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 the Willow Garage, 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.
*/
/*
* Author: Chad Rockey
*/
#include <laser_proc/LaserProcROS.h>
using namespace laser_proc;
LaserProcROS::LaserProcROS(ros::NodeHandle& n, ros::NodeHandle& pnh):nh_(n){
boost::mutex::scoped_lock lock(connect_mutex_);
// Lazy subscription to multi echo topic
pub_ = laser_proc::LaserTransport::advertiseLaser(n, 10, boost::bind(&LaserProcROS::connectCb, this, _1), boost::bind(&LaserProcROS::disconnectCb, this, _1), ros::VoidPtr(), false, false);
}
LaserProcROS::~LaserProcROS(){
sub_.shutdown();
}
void LaserProcROS::scanCb(const sensor_msgs::MultiEchoLaserScanConstPtr& msg) const{
pub_.publish(msg);
}
void LaserProcROS::connectCb(const ros::SingleSubscriberPublisher& pub){
boost::mutex::scoped_lock lock(connect_mutex_);
if (!sub_ && pub_.getNumSubscribers() > 0) {
ROS_DEBUG("Connecting to multi echo topic.");
sub_ = nh_.subscribe("echoes", 10, &LaserProcROS::scanCb, this);
}
}
void LaserProcROS::disconnectCb(const ros::SingleSubscriberPublisher& pub){
boost::mutex::scoped_lock lock(connect_mutex_);
if (pub_.getNumSubscribers() == 0) {
ROS_DEBUG("Unsubscribing from multi echo topic.");
sub_.shutdown();
}
}
+179
View File
@@ -0,0 +1,179 @@
/*
* Copyright (c) 2013, Willow Garage, 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 the Willow Garage, 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.
*/
/*
* Author: Chad Rockey
*/
#include <laser_proc/LaserPublisher.h>
namespace laser_proc {
typedef sensor_msgs::LaserScanPtr (*PublishFunction)(const sensor_msgs::MultiEchoLaserScan& msg);
struct LaserPublisher::Impl
{
Impl()
: unadvertised_(false)
{
}
~Impl()
{
shutdown();
}
bool isValid() const
{
return !unadvertised_;
}
void shutdown()
{
if (!unadvertised_) {
unadvertised_ = true;
for(size_t i = 0; i < pubs_.size(); i++){
pubs_[i].shutdown();
}
}
}
ros::Publisher echo_pub_;
std::vector<ros::Publisher> pubs_;
std::vector<PublishFunction> functs_;
bool unadvertised_;
};
///< @TODO Make a static class that creates these
LaserPublisher::LaserPublisher(ros::NodeHandle& nh, uint32_t queue_size,
const ros::SubscriberStatusCallback& connect_cb,
const ros::SubscriberStatusCallback& disconnect_cb,
const ros::VoidPtr& tracked_object, bool latch, bool publish_echoes)
: impl_(new Impl)
{
if(publish_echoes){
impl_->echo_pub_ = nh.advertise<sensor_msgs::MultiEchoLaserScan>("echoes", queue_size, connect_cb, disconnect_cb, tracked_object, latch);
}
impl_->pubs_.push_back(nh.advertise<sensor_msgs::LaserScan>("first", queue_size, connect_cb, disconnect_cb, tracked_object, latch));
impl_->functs_.push_back(laser_proc::LaserProc::getFirstScan);
impl_->pubs_.push_back(nh.advertise<sensor_msgs::LaserScan>("last", queue_size, connect_cb, disconnect_cb, tracked_object, latch));
impl_->functs_.push_back(laser_proc::LaserProc::getLastScan);
impl_->pubs_.push_back(nh.advertise<sensor_msgs::LaserScan>("most_intense", queue_size, connect_cb, disconnect_cb, tracked_object, latch));
impl_->functs_.push_back(laser_proc::LaserProc::getMostIntenseScan);
}
uint32_t LaserPublisher::getNumSubscribers() const
{
if (impl_ && impl_->isValid()){
uint32_t num = impl_->echo_pub_.getNumSubscribers();
for(size_t i = 0; i < impl_->pubs_.size(); i++){
num = num + impl_->pubs_[i].getNumSubscribers();
}
return num;
}
return 0;
}
std::vector<std::string> LaserPublisher::getTopics() const
{
std::vector<std::string> topics;
topics.push_back(impl_->echo_pub_.getTopic());
if (impl_ && impl_->isValid()){
for(size_t i = 0; i < impl_->pubs_.size(); i++){
topics.push_back(impl_->pubs_[i].getTopic());
}
}
return topics;
}
void LaserPublisher::publish(const sensor_msgs::MultiEchoLaserScan& msg) const
{
if (!impl_ || !impl_->isValid()) {
ROS_ASSERT_MSG(false, "Call to publish() on an invalid image_transport::LaserPublisher");
return;
}
// Publish original MultiEchoLaserScan
if(impl_->echo_pub_){
if(impl_->echo_pub_.getNumSubscribers() > 0){
impl_->echo_pub_.publish(msg);
}
}
// If needed, publish LaserScans
for(size_t i = 0; i < impl_->pubs_.size(); i++){
if(impl_->pubs_[i].getNumSubscribers() > 0){
try{
impl_->pubs_[i].publish(impl_->functs_[i](msg));
} catch(std::runtime_error& e){
ROS_ERROR_THROTTLE(1.0, "Could not publish to topic %s: %s", impl_->pubs_[i].getTopic().c_str(), e.what());
}
}
}
}
void LaserPublisher::publish(const sensor_msgs::MultiEchoLaserScanConstPtr& msg) const
{
if (!impl_ || !impl_->isValid()) {
ROS_ASSERT_MSG(false, "Call to publish() on an invalid image_transport::LaserPublisher");
return;
}
// Publish original MultiEchoLaserScan
if(impl_->echo_pub_){
impl_->echo_pub_.publish(msg);
}
// If needed, publish LaserScans
for(size_t i = 0; i < impl_->pubs_.size(); i++){
if(impl_->pubs_[i].getNumSubscribers() > 0){
try{
impl_->pubs_[i].publish(impl_->functs_[i](*msg));
} catch(std::runtime_error& e){
ROS_ERROR_THROTTLE(1.0, "Could not publish to topic %s: %s", impl_->pubs_[i].getTopic().c_str(), e.what());
}
}
}
}
void LaserPublisher::shutdown()
{
if (impl_) {
impl_->shutdown();
impl_.reset();
}
}
LaserPublisher::operator void*() const
{
return (impl_ && impl_->isValid()) ? (void*)1 : (void*)0;
}
} //namespace laser_proc
+50
View File
@@ -0,0 +1,50 @@
/*
* Copyright (c) 2013, Willow Garage, 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 the Willow Garage, 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.
*/
/*
* Author: Chad Rockey
*/
#include <laser_proc/LaserTransport.h>
namespace laser_proc {
LaserPublisher LaserTransport::advertiseLaser(ros::NodeHandle& nh, uint32_t queue_size, bool latch){
return advertiseLaser(nh, queue_size, ros::SubscriberStatusCallback(), ros::SubscriberStatusCallback(), ros::VoidPtr(), latch);
}
LaserPublisher LaserTransport::advertiseLaser(ros::NodeHandle& nh, uint32_t queue_size,
const ros::SubscriberStatusCallback& connect_cb,
const ros::SubscriberStatusCallback& disconnect_cb,
const ros::VoidPtr& tracked_object, bool latch, bool publish_echoes){
return LaserPublisher(nh, queue_size, connect_cb, disconnect_cb, tracked_object, latch, publish_echoes);
}
} //namespace laser_proc
+46
View File
@@ -0,0 +1,46 @@
/*
* Copyright (c) 2013, Willow Garage, 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 the Willow Garage, 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.
*/
/*
* Author: Chad Rockey
*/
#include <laser_proc/LaserProcROS.h>
int main(int argc, char **argv){
ros::init(argc, argv, "laser_proc");
ros::NodeHandle n;
ros::NodeHandle pnh("~");
laser_proc::LaserProcROS lp(n, pnh);
ros::spin();
return 0;
}