From 0467c816c313774874367c06c9b54f33077acf04 Mon Sep 17 00:00:00 2001
From: Joseph Mirabel <jmirabel@laas.fr>
Date: Tue, 16 Oct 2018 12:12:29 +0200
Subject: [PATCH] RosPublish can publish integers

---
 src/converter.hh    | 12 ++++++++++++
 src/ros_publish.cpp |  2 ++
 src/sot_to_ros.cpp  |  1 +
 src/sot_to_ros.hh   | 25 +++++++++++++++++++++++++
 4 files changed, 40 insertions(+)

diff --git a/src/converter.hh b/src/converter.hh
index 9b94e52..968cde4 100644
--- a/src/converter.hh
+++ b/src/converter.hh
@@ -66,6 +66,17 @@ namespace dynamicgraph
     dst = src.data;
   }
 
+  // Int
+  SOT_TO_ROS_IMPL(int)
+  {
+    dst.data = src;
+  }
+
+  ROS_TO_SOT_IMPL(int)
+  {
+    dst = src.data;
+  }
+
   // Unsigned
   SOT_TO_ROS_IMPL(unsigned int)
   {
@@ -229,6 +240,7 @@ namespace dynamicgraph
 
   DG_BRIDGE_MAKE_SHPTR_IMPL(bool);
   DG_BRIDGE_MAKE_SHPTR_IMPL(double);
+  DG_BRIDGE_MAKE_SHPTR_IMPL(int);
   DG_BRIDGE_MAKE_SHPTR_IMPL(unsigned int);
   DG_BRIDGE_MAKE_SHPTR_IMPL(Vector);
   DG_BRIDGE_MAKE_SHPTR_IMPL(specific::Vector3);
diff --git a/src/ros_publish.cpp b/src/ros_publish.cpp
index 1120ed1..8646fe5 100644
--- a/src/ros_publish.cpp
+++ b/src/ros_publish.cpp
@@ -84,6 +84,8 @@ namespace dynamicgraph
 	  entity.add<double> (signal, topic);
 	else if (type == "unsigned")
 	  entity.add<unsigned int> (signal, topic);
+	else if (type == "int")
+	  entity.add<int> (signal, topic);
 	else if (type == "matrix")
 	  entity.add<Matrix> (signal, topic);
 	else if (type == "vector")
diff --git a/src/sot_to_ros.cpp b/src/sot_to_ros.cpp
index 87b1214..abc88e3 100644
--- a/src/sot_to_ros.cpp
+++ b/src/sot_to_ros.cpp
@@ -5,6 +5,7 @@ namespace dynamicgraph
 
   const char* SotToRos<bool>::signalTypeName = "bool";
   const char* SotToRos<double>::signalTypeName = "Double";
+  const char* SotToRos<int>::signalTypeName = "int";
   const char* SotToRos<unsigned int>::signalTypeName = "Unsigned";
   const char* SotToRos<Matrix>::signalTypeName = "Matrix";
   const char* SotToRos<Vector>::signalTypeName = "Vector";
diff --git a/src/sot_to_ros.hh b/src/sot_to_ros.hh
index 02673ec..46bdf4c 100644
--- a/src/sot_to_ros.hh
+++ b/src/sot_to_ros.hh
@@ -8,6 +8,7 @@
 # include <std_msgs/Bool.h>
 # include <std_msgs/Float64.h>
 # include <std_msgs/UInt32.h>
+# include <std_msgs/Int32.h>
 # include "dynamic_graph_bridge_msgs/Matrix.h"
 # include "dynamic_graph_bridge_msgs/Vector.h"
 
@@ -121,6 +122,30 @@ namespace dynamicgraph
     }
   };
 
+  template <>
+  struct SotToRos<int>
+  {
+    typedef int sot_t;
+    typedef std_msgs::Int32 ros_t;
+    typedef std_msgs::Int32ConstPtr 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 (0);
+    }
+
+    static void setDefault(sot_t& s)
+    {
+      s = 0;
+    }
+  };
+
   template <>
   struct SotToRos<Matrix>
   {
-- 
GitLab