Skip to content

Commit 0951b1a

Browse files
jmirabelolivier-stasse
authored andcommitted
RosPublish can publish booleans
1 parent f1be540 commit 0951b1a

File tree

4 files changed

+41
-1
lines changed

4 files changed

+41
-1
lines changed

src/converter.hh

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,17 @@ namespace dynamicgraph
4444
template <typename D, typename S>
4545
void converter (D& dst, const S& src);
4646

47+
// Boolean
48+
SOT_TO_ROS_IMPL(bool)
49+
{
50+
dst.data = src;
51+
}
52+
53+
ROS_TO_SOT_IMPL(bool)
54+
{
55+
dst = src.data;
56+
}
57+
4758
// Double
4859
SOT_TO_ROS_IMPL(double)
4960
{
@@ -216,6 +227,7 @@ namespace dynamicgraph
216227
} \
217228
struct e_n_d__w_i_t_h__s_e_m_i_c_o_l_o_n
218229

230+
DG_BRIDGE_MAKE_SHPTR_IMPL(bool);
219231
DG_BRIDGE_MAKE_SHPTR_IMPL(double);
220232
DG_BRIDGE_MAKE_SHPTR_IMPL(unsigned int);
221233
DG_BRIDGE_MAKE_SHPTR_IMPL(Vector);

src/ros_publish.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,9 @@ namespace dynamicgraph
7878
const std::string& signal = values[1].value ();
7979
const std::string& topic = values[2].value ();
8080

81-
if (type == "double")
81+
if (type == "boolean")
82+
entity.add<bool> (signal, topic);
83+
else if (type == "double")
8284
entity.add<double> (signal, topic);
8385
else if (type == "unsigned")
8486
entity.add<unsigned int> (signal, topic);

src/sot_to_ros.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace dynamicgraph
44
{
55

6+
const char* SotToRos<bool>::signalTypeName = "bool";
67
const char* SotToRos<double>::signalTypeName = "Double";
78
const char* SotToRos<unsigned int>::signalTypeName = "Unsigned";
89
const char* SotToRos<Matrix>::signalTypeName = "Matrix";

src/sot_to_ros.hh

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
# include <boost/format.hpp>
77

8+
# include <std_msgs/Bool.h>
89
# include <std_msgs/Float64.h>
910
# include <std_msgs/UInt32.h>
1011
# include "dynamic_graph_bridge_msgs/Matrix.h"
@@ -48,6 +49,30 @@ namespace dynamicgraph
4849
template <typename SotType>
4950
class SotToRos;
5051

52+
template <>
53+
struct SotToRos<bool>
54+
{
55+
typedef bool sot_t;
56+
typedef std_msgs::Bool ros_t;
57+
typedef std_msgs::BoolConstPtr ros_const_ptr_t;
58+
typedef dynamicgraph::Signal<sot_t, int> signal_t;
59+
typedef dynamicgraph::SignalPtr<sot_t, int> signalIn_t;
60+
typedef boost::function<sot_t& (sot_t&, int)> callback_t;
61+
62+
static const char* signalTypeName;
63+
64+
template <typename S>
65+
static void setDefault(S& s)
66+
{
67+
s.setConstant (false);
68+
}
69+
70+
static void setDefault(sot_t& s)
71+
{
72+
s = false;
73+
}
74+
};
75+
5176
template <>
5277
struct SotToRos<double>
5378
{

0 commit comments

Comments
 (0)