Skip to content
Snippets Groups Projects
Commit becb1fc0 authored by Florent Lamiraux's avatar Florent Lamiraux Committed by olivier stasse
Browse files

Enable publication and subscription of signals of type std::string.

parent 7918f75a
No related branches found
No related tags found
No related merge requests found
...@@ -88,6 +88,17 @@ namespace dynamicgraph ...@@ -88,6 +88,17 @@ namespace dynamicgraph
dst = src.data; dst = src.data;
} }
// String
SOT_TO_ROS_IMPL(std::string)
{
dst.data = src;
}
ROS_TO_SOT_IMPL(std::string)
{
dst = src.data;
}
// Vector // Vector
SOT_TO_ROS_IMPL(Vector) SOT_TO_ROS_IMPL(Vector)
{ {
...@@ -242,6 +253,7 @@ namespace dynamicgraph ...@@ -242,6 +253,7 @@ namespace dynamicgraph
DG_BRIDGE_MAKE_SHPTR_IMPL(double); DG_BRIDGE_MAKE_SHPTR_IMPL(double);
DG_BRIDGE_MAKE_SHPTR_IMPL(int); DG_BRIDGE_MAKE_SHPTR_IMPL(int);
DG_BRIDGE_MAKE_SHPTR_IMPL(unsigned int); DG_BRIDGE_MAKE_SHPTR_IMPL(unsigned int);
DG_BRIDGE_MAKE_SHPTR_IMPL(std::string);
DG_BRIDGE_MAKE_SHPTR_IMPL(Vector); DG_BRIDGE_MAKE_SHPTR_IMPL(Vector);
DG_BRIDGE_MAKE_SHPTR_IMPL(specific::Vector3); DG_BRIDGE_MAKE_SHPTR_IMPL(specific::Vector3);
DG_BRIDGE_MAKE_SHPTR_IMPL(Matrix); DG_BRIDGE_MAKE_SHPTR_IMPL(Matrix);
......
...@@ -107,6 +107,8 @@ namespace dynamicgraph ...@@ -107,6 +107,8 @@ namespace dynamicgraph
entity.add<specific::Twist> (signal, topic); entity.add<specific::Twist> (signal, topic);
else if (type == "twistStamped") else if (type == "twistStamped")
entity.add<std::pair<specific::Twist, Vector> > (signal, topic); entity.add<std::pair<specific::Twist, Vector> > (signal, topic);
else if (type == "string")
entity.add<std::string> (signal, topic);
else else
throw std::runtime_error("bad type"); throw std::runtime_error("bad type");
return Value (); return Value ();
......
...@@ -94,6 +94,8 @@ namespace dynamicgraph ...@@ -94,6 +94,8 @@ namespace dynamicgraph
else if (type == "twistStamped") else if (type == "twistStamped")
entity.add<std::pair<specific::Twist, dg::Vector> > entity.add<std::pair<specific::Twist, dg::Vector> >
(signal, topic); (signal, topic);
else if (type == "string")
entity.add<std::string> (signal, topic);
else else
throw std::runtime_error("bad type"); throw std::runtime_error("bad type");
return Value (); return Value ();
......
...@@ -6,6 +6,7 @@ namespace dynamicgraph ...@@ -6,6 +6,7 @@ namespace dynamicgraph
const char* SotToRos<bool>::signalTypeName = "bool"; const char* SotToRos<bool>::signalTypeName = "bool";
const char* SotToRos<double>::signalTypeName = "Double"; const char* SotToRos<double>::signalTypeName = "Double";
const char* SotToRos<int>::signalTypeName = "int"; const char* SotToRos<int>::signalTypeName = "int";
const char* SotToRos<std::string>::signalTypeName = "string";
const char* SotToRos<unsigned int>::signalTypeName = "Unsigned"; const char* SotToRos<unsigned int>::signalTypeName = "Unsigned";
const char* SotToRos<Matrix>::signalTypeName = "Matrix"; const char* SotToRos<Matrix>::signalTypeName = "Matrix";
const char* SotToRos<Vector>::signalTypeName = "Vector"; const char* SotToRos<Vector>::signalTypeName = "Vector";
......
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
# include <std_msgs/Float64.h> # include <std_msgs/Float64.h>
# include <std_msgs/UInt32.h> # include <std_msgs/UInt32.h>
# include <std_msgs/Int32.h> # include <std_msgs/Int32.h>
# include <std_msgs/String.h>
# include "dynamic_graph_bridge_msgs/Matrix.h" # include "dynamic_graph_bridge_msgs/Matrix.h"
# include "dynamic_graph_bridge_msgs/Vector.h" # include "dynamic_graph_bridge_msgs/Vector.h"
...@@ -146,6 +147,30 @@ namespace dynamicgraph ...@@ -146,6 +147,30 @@ namespace dynamicgraph
} }
}; };
template <>
struct SotToRos<std::string>
{
typedef std::string sot_t;
typedef std_msgs::String ros_t;
typedef std_msgs::StringConstPtr ros_const_ptr_t;
typedef dynamicgraph::Signal<sot_t, int> signal_t;
typedef dynamicgraph::SignalPtr<sot_t, int> signalIn_t;
typedef boost::function<sot_t& (sot_t&, int)> callback_t;
static const char* signalTypeName;
template <typename S>
static void setDefault(S& s)
{
s.setConstant ("");
}
static void setDefault(sot_t& s)
{
s = std::string ();
}
};
template <> template <>
struct SotToRos<Matrix> struct SotToRos<Matrix>
{ {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment