Skip to content

Commit becb1fc

Browse files
florent-lamirauxOlivier Stasse
authored andcommitted
Enable publication and subscription of signals of type std::string.
1 parent 7918f75 commit becb1fc

File tree

5 files changed

+42
-0
lines changed

5 files changed

+42
-0
lines changed

src/converter.hh

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,17 @@ namespace dynamicgraph
8888
dst = src.data;
8989
}
9090

91+
// String
92+
SOT_TO_ROS_IMPL(std::string)
93+
{
94+
dst.data = src;
95+
}
96+
97+
ROS_TO_SOT_IMPL(std::string)
98+
{
99+
dst = src.data;
100+
}
101+
91102
// Vector
92103
SOT_TO_ROS_IMPL(Vector)
93104
{
@@ -242,6 +253,7 @@ namespace dynamicgraph
242253
DG_BRIDGE_MAKE_SHPTR_IMPL(double);
243254
DG_BRIDGE_MAKE_SHPTR_IMPL(int);
244255
DG_BRIDGE_MAKE_SHPTR_IMPL(unsigned int);
256+
DG_BRIDGE_MAKE_SHPTR_IMPL(std::string);
245257
DG_BRIDGE_MAKE_SHPTR_IMPL(Vector);
246258
DG_BRIDGE_MAKE_SHPTR_IMPL(specific::Vector3);
247259
DG_BRIDGE_MAKE_SHPTR_IMPL(Matrix);

src/ros_publish.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,8 @@ namespace dynamicgraph
107107
entity.add<specific::Twist> (signal, topic);
108108
else if (type == "twistStamped")
109109
entity.add<std::pair<specific::Twist, Vector> > (signal, topic);
110+
else if (type == "string")
111+
entity.add<std::string> (signal, topic);
110112
else
111113
throw std::runtime_error("bad type");
112114
return Value ();

src/ros_subscribe.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,8 @@ namespace dynamicgraph
9494
else if (type == "twistStamped")
9595
entity.add<std::pair<specific::Twist, dg::Vector> >
9696
(signal, topic);
97+
else if (type == "string")
98+
entity.add<std::string> (signal, topic);
9799
else
98100
throw std::runtime_error("bad type");
99101
return Value ();

src/sot_to_ros.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ namespace dynamicgraph
66
const char* SotToRos<bool>::signalTypeName = "bool";
77
const char* SotToRos<double>::signalTypeName = "Double";
88
const char* SotToRos<int>::signalTypeName = "int";
9+
const char* SotToRos<std::string>::signalTypeName = "string";
910
const char* SotToRos<unsigned int>::signalTypeName = "Unsigned";
1011
const char* SotToRos<Matrix>::signalTypeName = "Matrix";
1112
const char* SotToRos<Vector>::signalTypeName = "Vector";

src/sot_to_ros.hh

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
# include <std_msgs/Float64.h>
1010
# include <std_msgs/UInt32.h>
1111
# include <std_msgs/Int32.h>
12+
# include <std_msgs/String.h>
1213
# include "dynamic_graph_bridge_msgs/Matrix.h"
1314
# include "dynamic_graph_bridge_msgs/Vector.h"
1415

@@ -146,6 +147,30 @@ namespace dynamicgraph
146147
}
147148
};
148149

150+
template <>
151+
struct SotToRos<std::string>
152+
{
153+
typedef std::string sot_t;
154+
typedef std_msgs::String ros_t;
155+
typedef std_msgs::StringConstPtr ros_const_ptr_t;
156+
typedef dynamicgraph::Signal<sot_t, int> signal_t;
157+
typedef dynamicgraph::SignalPtr<sot_t, int> signalIn_t;
158+
typedef boost::function<sot_t& (sot_t&, int)> callback_t;
159+
160+
static const char* signalTypeName;
161+
162+
template <typename S>
163+
static void setDefault(S& s)
164+
{
165+
s.setConstant ("");
166+
}
167+
168+
static void setDefault(sot_t& s)
169+
{
170+
s = std::string ();
171+
}
172+
};
173+
149174
template <>
150175
struct SotToRos<Matrix>
151176
{

0 commit comments

Comments
 (0)