diff --git a/.gitignore b/.gitignore index 17c239880a67bad805ad0d4d4fdf28eeb7a27e0d..0061e71ff5abd9bc6cf69472e9c44e23c6a7d15f 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,5 @@ lib/ msg/lisp/ msg_gen/ -src/hueblob/ +src/dynamic_graph/ bin/ diff --git a/CMakeLists.txt b/CMakeLists.txt index 2dd9b2d3e7841137a1a1386df4832b10c72e1605..95802ed6d0cca1b5729433a06b18be85f9912bdf 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -17,7 +17,7 @@ set(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin) set(LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/lib) #uncomment if you have defined messages -#rosbuild_genmsg() +rosbuild_genmsg() #uncomment if you have defined services #rosbuild_gensrv() diff --git a/manifest.xml b/manifest.xml index 251f60fc4d475cb71290b53aaa0e39f04805dabf..afb07d0729950685a2b1abb0e931a9ede94cdab0 100644 --- a/manifest.xml +++ b/manifest.xml @@ -12,5 +12,6 @@ <depend package="std_msgs"/> <depend package="roscpp"/> + <rosdep name="jrl-mal"/> <rosdep name="dynamic-graph"/> </package> diff --git a/msg/Matrix.msg b/msg/Matrix.msg new file mode 100644 index 0000000000000000000000000000000000000000..323f50b09c87b76903cf036fca05838088e9e978 --- /dev/null +++ b/msg/Matrix.msg @@ -0,0 +1,2 @@ +float64[] data +uint32 width diff --git a/msg/Vector.msg b/msg/Vector.msg new file mode 100644 index 0000000000000000000000000000000000000000..922220faa2b2c8f511536b11f3068be40e6fb576 --- /dev/null +++ b/msg/Vector.msg @@ -0,0 +1 @@ +float64[] data diff --git a/src/ros_import.cpp b/src/ros_import.cpp index c24c5dab4c5ded4bf8e0a5f17ed56cd0df60638e..38e236ecad3aebc87198fc9fd0841ab79936baeb 100644 --- a/src/ros_import.cpp +++ b/src/ros_import.cpp @@ -56,8 +56,15 @@ namespace dynamicgraph } else if (cmdLine == "add") { - cmdArgs >> signal >> topic; - add<double> (signal, topic); + cmdArgs >> type >> signal >> topic; + if (type == "double") + add<double> (signal, topic); + else if (type == "matrix") + add<ml::Matrix> (signal, topic); + else if (type == "vector") + add<ml::Vector> (signal, topic); + else + throw "bad type"; } else if (cmdLine == "rm") { diff --git a/src/ros_import.hh b/src/ros_import.hh index 75afcc34bf7111d93f43b302be0377ff36238131..6d5352901569e7a92a67ce596d1a88aa452ecedf 100644 --- a/src/ros_import.hh +++ b/src/ros_import.hh @@ -1,6 +1,7 @@ #ifndef DYNAMIC_GRAPH_ROS_IMPORT_HH # define DYNAMIC_GRAPH_ROS_IMPORT_HH # include <iostream> +# include <map> # include <boost/shared_ptr.hpp> diff --git a/src/ros_import.hxx b/src/ros_import.hxx index f49a270f5871cc43559e4946cfab1212a1a467f4..f4f4656eaee0cebe97d083dbc2ce68d3339e735a 100644 --- a/src/ros_import.hxx +++ b/src/ros_import.hxx @@ -1,6 +1,13 @@ #ifndef DYNAMIC_GRAPH_ROS_IMPORT_HXX # define DYNAMIC_GRAPH_ROS_IMPORT_HXX +# include <vector> +# include <jrl/mal/boost.hh> # include <std_msgs/Float64.h> +# include "dynamic_graph/Matrix.h" +# include "dynamic_graph/Vector.h" + + +namespace ml = maal::boost; namespace dynamicgraph { @@ -13,6 +20,25 @@ namespace dynamicgraph typedef boost::function<sot_t& (sot_t&, int)> callback_t; }; + template <> + struct SotToRos<ml::Matrix> + { + typedef ml::Matrix sot_t; + typedef dynamic_graph::Matrix ros_t; + typedef dynamicgraph::SignalTimeDependent<sot_t, int> signal_t; + typedef boost::function<sot_t& (sot_t&, int)> callback_t; + }; + + template <> + struct SotToRos<ml::Vector> + { + typedef ml::Vector sot_t; + typedef dynamic_graph::Vector ros_t; + typedef dynamicgraph::SignalTimeDependent<sot_t, int> signal_t; + typedef boost::function<sot_t& (sot_t&, int)> callback_t; + }; + + template <> void converter (SotToRos<double>::ros_t& dst, const SotToRos<double>::sot_t& src) @@ -20,6 +46,26 @@ namespace dynamicgraph dst.data = src; } + template <> + void converter (SotToRos<ml::Matrix>::ros_t& dst, + const SotToRos<ml::Matrix>::sot_t& src) + { + dst.width = src.nbRows (); + dst.data.resize (src.nbCols () * src.nbRows ()); + for (unsigned i = 0; i < src.nbCols () * src.nbRows (); ++i) + dst.data[i] = src.elementAt (i); + } + + template <> + void converter (SotToRos<ml::Vector>::ros_t& dst, + const SotToRos<ml::Vector>::sot_t& src) + { + dst.data.resize (src.size ()); + for (unsigned i = 0; i < src.size (); ++i) + dst.data[i] = src.elementAt (i); + } + + template <typename T> T& RosImport::sendData (boost::shared_ptr<ros::Publisher> publisher,