Skip to content

Commit

Permalink
Added ROS support
Browse files Browse the repository at this point in the history
  • Loading branch information
joaocgreis committed Oct 20, 2014
1 parent 34a308f commit 08094bd
Show file tree
Hide file tree
Showing 2 changed files with 119 additions and 0 deletions.
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ sudo apt-get install build-essential cmake libboost-all-dev libprotoc-dev protob
This was tested with Ubuntu 12.04.5 LTS (Precise Pangolin) and
14.04.1 LTS (Trusty Tahr).


## Compiling

To compile, use:
Expand All @@ -41,6 +42,7 @@ lib/libroah_rsbb_msgs.a
lib/libprotobuf_comm.a
```


## Using roah_rsbb.h

This C++ header file provides a small decorator on top of
Expand All @@ -50,3 +52,12 @@ provide a pooling interface for the last messages of the allowed
types received on each channel as well as a specific signal for each
one. Be careful with synchronization, the callbacks will be called
from different threads.


## Using ros_roah_rsbb.h

The classes `RosPublicChannel` and `RosPrivateChannel` provide
a way to use `PublicChannel` and `PrivateChannel` with error output
done by ROS. Include this file only if your project uses ROS.
If your project uses some other framework, you can use this file
as a base to adapt to your framework.
108 changes: 108 additions & 0 deletions include/ros_roah_rsbb.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
/*
* Copyright 2014 Instituto de Sistemas e Robotica, Instituto Superior Tecnico
*
* This file is part of RoAH RSBB Comm.
*
* RoAH RSBB Comm is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* RoAH RSBB Comm is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with RoAH RSBB Comm. If not, see <http://www.gnu.org/licenses/>.
*/

#ifndef __ROS_ROAH_RSBB_H__
#define __ROS_ROAH_RSBB_H__

#include <string>

#include <ros/console.h>
#include <ros/param.h>

#include "roah_rsbb.h"



namespace roah_rsbb
{
class RosErrorHandler
{
public:
RosErrorHandler (std::string const& name,
protobuf_comm::ProtobufBroadcastPeer& channel) :
name_ (name)
{
channel.signal_recv_error().connect (boost::bind (&RosErrorHandler::recv_error, this, _1, _2));
channel.signal_send_error().connect (boost::bind (&RosErrorHandler::send_error, this, _1));
}

void
unknown_msg (boost::asio::ip::udp::endpoint& endpoint,
uint16_t comp_id,
uint16_t msg_type,
std::shared_ptr<google::protobuf::Message> msg)
{
ROS_ERROR_STREAM ("On channel " << name_
<< ": Unknown message from " << endpoint.address().to_string()
<< ":" << endpoint.port()
<< ", COMP_ID " << comp_id
<< ", MSG_TYPE " << msg_type
<< ", of type " << typeid (*msg).name());
}

private:
std::string name_;

void
recv_error (boost::asio::ip::udp::endpoint& endpoint,
std::string msg)
{
ROS_ERROR_STREAM ("On channel " << name_
<< ": Receive error from " << endpoint.address().to_string()
<< ":" << endpoint.port()
<< ": " << msg);
}

void
send_error (std::string msg)
{
ROS_ERROR_STREAM ("On channel " << name_
<< ": Send error: " << msg);
}
};

typedef PublicChannel<RosErrorHandler> RosPublicChannel;
typedef PrivateChannel<RosErrorHandler> RosPrivateChannel;
}



template<typename T> inline void
param_direct (std::string const& name,
T const& def_value,
T& var)
{
if (! ros::param::getCached (name, var)) {
var = def_value;
ros::param::set (name, var);
}
}



template<typename T> inline T
param_direct (std::string const& name,
T const& def_value)
{
T tmp;
param_direct<T> (name, def_value, tmp);
return tmp;
}

#endif

0 comments on commit 08094bd

Please sign in to comment.