diff --git a/src/ros_publish-python-module-py.cc b/src/ros_publish-python-module-py.cc index 1d952594976d93c99b5928e68865dddc940e6f27..a50e445c4ff6a4bc5a10250ad3f8ef9d67f675cd 100644 --- a/src/ros_publish-python-module-py.cc +++ b/src/ros_publish-python-module-py.cc @@ -8,5 +8,10 @@ BOOST_PYTHON_MODULE(wrap) { bp::import("dynamic_graph"); - dg::python::exposeEntity<dg::RosPublish, bp::bases<dg::Entity>, dg::python::AddCommands>() ; + dg::python::exposeEntity<dg::RosPublish, bp::bases<dg::Entity>, dg::python::AddCommands>() + .def("clear", &dg::RosPublish::clear, "Remove all signals writing data to a ROS topic") + .def("rm", &dg::RosPublish::rm, "Remove a signal writing data to a ROS topic", + bp::args("signal_name")) + .def("list", &dg::RosPublish::list, "List signals writing data to a ROS topic") + ; } diff --git a/src/ros_publish.cpp b/src/ros_publish.cpp index dd5a134ca30330dcec1417dce72c9007007fd5fe..407d7145b366ad1427f6bf5ab74e181a84e7d65f 100644 --- a/src/ros_publish.cpp +++ b/src/ros_publish.cpp @@ -28,23 +28,6 @@ const double RosPublish::ROS_JOINT_STATE_PUBLISHER_RATE = 0.01; namespace command { namespace rosPublish { -Clear::Clear(RosPublish& entity, const std::string& docstring) - : Command(entity, std::vector<Value::Type>(), docstring) {} - -Value Clear::doExecute() { - RosPublish& entity = static_cast<RosPublish&>(owner()); - - entity.clear(); - return Value(); -} - -List::List(RosPublish& entity, const std::string& docstring) - : Command(entity, std::vector<Value::Type>(), docstring) {} - -Value List::doExecute() { - RosPublish& entity = static_cast<RosPublish&>(owner()); - return Value(entity.list()); -} Add::Add(RosPublish& entity, const std::string& docstring) : Command(entity, boost::assign::list_of(Value::STRING)(Value::STRING)(Value::STRING), docstring) {} @@ -88,16 +71,6 @@ Value Add::doExecute() { return Value(); } -Rm::Rm(RosPublish& entity, const std::string& docstring) - : Command(entity, boost::assign::list_of(Value::STRING), docstring) {} - -Value Rm::doExecute() { - RosPublish& entity = static_cast<RosPublish&>(owner()); - std::vector<Value> values = getParameterValues(); - const std::string& signal = values[0].value(); - entity.rm(signal); - return Value(); -} } // namespace rosPublish } // end of namespace command. @@ -143,29 +116,6 @@ RosPublish::RosPublish(const std::string& n) " - topic: the topic name in ROS.\n" "\n"; addCommand("add", new command::rosPublish::Add(*this, docstring)); - docstring = - "\n" - " Remove a signal writing data to a ROS topic\n" - "\n" - " Input:\n" - " - name of the signal to remove (see method list for the list of " - "signals).\n" - "\n"; - addCommand("rm", new command::rosPublish::Rm(*this, docstring)); - docstring = - "\n" - " Remove all signals writing data to a ROS topic\n" - "\n" - " No input:\n" - "\n"; - addCommand("clear", new command::rosPublish::Clear(*this, docstring)); - docstring = - "\n" - " List signals writing data to a ROS topic\n" - "\n" - " No input:\n" - "\n"; - addCommand("list", new command::rosPublish::List(*this, docstring)); } RosPublish::~RosPublish() { aofs_.close(); } @@ -187,13 +137,10 @@ void RosPublish::rm(const std::string& signal) { bindedSignal_.erase(signal); } -std::string RosPublish::list() const { - std::string result("["); - for (std::map<std::string, bindedSignal_t>::const_iterator it = bindedSignal_.begin(); it != bindedSignal_.end(); - it++) { - result += "'" + it->first + "',"; - } - result += "]"; +std::vector<std::string> RosPublish::list() const { + std::vector<std::string> result(bindedSignal_.size()); + std::transform(bindedSignal_.begin(), bindedSignal_.end(), + result.begin(), [](const auto& pair) { return pair.first; }); return result; } diff --git a/src/ros_publish.hh b/src/ros_publish.hh index 9b73716c772c97eb91f3ee5531d496959640e9ac..31b8cceede21b5c53fa6bbef15ee3f55678db4f4 100644 --- a/src/ros_publish.hh +++ b/src/ros_publish.hh @@ -34,9 +34,6 @@ using ::dynamicgraph::command::Value; } ROS_PUBLISH_MAKE_COMMAND(Add); -ROS_PUBLISH_MAKE_COMMAND(Clear); -ROS_PUBLISH_MAKE_COMMAND(List); -ROS_PUBLISH_MAKE_COMMAND(Rm); #undef ROS_PUBLISH_MAKE_COMMAND @@ -62,7 +59,7 @@ class RosPublish : public dynamicgraph::Entity { void add(const std::string& signal, const std::string& topic); void rm(const std::string& signal); - std::string list() const; + std::vector<std::string> list() const; void clear(); int& trigger(int&, int); diff --git a/src/ros_queued_subscribe-python-module-py.cc b/src/ros_queued_subscribe-python-module-py.cc new file mode 100644 index 0000000000000000000000000000000000000000..00f2fb93f260f3712c2b167dabfe436523a515b9 --- /dev/null +++ b/src/ros_queued_subscribe-python-module-py.cc @@ -0,0 +1,25 @@ +#include <dynamic-graph/python/module.hh> +#include "ros_queued_subscribe.hh" + +namespace dg = dynamicgraph; + + +BOOST_PYTHON_MODULE(wrap) +{ + bp::import("dynamic_graph"); + + dg::python::exposeEntity<dg::RosQueuedSubscribe, bp::bases<dg::Entity>, dg::python::AddCommands>() + .def("clear", &dg::RosQueuedSubscribe::clear, "Remove all signals reading data from a ROS topic") + .def("rm", &dg::RosQueuedSubscribe::rm, "Remove a signal reading data from a ROS topic", + bp::args("signal_name")) + .def("list", &dg::RosQueuedSubscribe::list, "List signals reading data from a ROS topic") + + .def("clearQueue", &dg::RosQueuedSubscribe::clearQueue, + "Empty the queue of a given signal", bp::args("signal_name")) + .def("queueSize", &dg::RosQueuedSubscribe::queueSize, + "Return the queue size of a given signal", bp::args("signal_name")) + .def("readQueue", &dg::RosQueuedSubscribe::queueSize, + "Whether signals should read values from the queues, and when.", + bp::args("start_time")) + ; +} diff --git a/src/ros_queued_subscribe-python.hh b/src/ros_queued_subscribe-python.hh deleted file mode 100644 index e6880f8daf1c0b5447e9ec0cb92c1c8390fdd52b..0000000000000000000000000000000000000000 --- a/src/ros_queued_subscribe-python.hh +++ /dev/null @@ -1,3 +0,0 @@ -#include "ros_queued_subscribe.hh" - -typedef boost::mpl::vector< dynamicgraph::RosQueuedSubscribe > entities_t; diff --git a/src/ros_queued_subscribe.cpp b/src/ros_queued_subscribe.cpp index 779d9d6c67e704748d05fba99f2ab3f8d17ef7df..f9ecaf5a2a03b1420285c7d0a7ad30b837d72cd1 100644 --- a/src/ros_queued_subscribe.cpp +++ b/src/ros_queued_subscribe.cpp @@ -24,37 +24,6 @@ DYNAMICGRAPH_FACTORY_ENTITY_PLUGIN(RosQueuedSubscribe, "RosQueuedSubscribe"); namespace command { namespace rosQueuedSubscribe { -Clear::Clear(RosQueuedSubscribe& entity, const std::string& docstring) - : Command(entity, std::vector<Value::Type>(), docstring) {} - -Value Clear::doExecute() { - RosQueuedSubscribe& entity = static_cast<RosQueuedSubscribe&>(owner()); - - entity.clear(); - return Value(); -} - -ClearQueue::ClearQueue(RosQueuedSubscribe& entity, const std::string& docstring) - : Command(entity, boost::assign::list_of(Value::STRING), docstring) {} - -Value ClearQueue::doExecute() { - RosQueuedSubscribe& entity = static_cast<RosQueuedSubscribe&>(owner()); - - std::vector<Value> values = getParameterValues(); - const std::string& signal = values[0].value(); - entity.clearQueue(signal); - - return Value(); -} - -List::List(RosQueuedSubscribe& entity, const std::string& docstring) - : Command(entity, std::vector<Value::Type>(), docstring) {} - -Value List::doExecute() { - RosQueuedSubscribe& entity = static_cast<RosQueuedSubscribe&>(owner()); - return Value(entity.list()); -} - Add::Add(RosQueuedSubscribe& entity, const std::string& docstring) : Command(entity, boost::assign::list_of(Value::STRING)(Value::STRING)(Value::STRING), docstring) {} @@ -84,42 +53,6 @@ Value Add::doExecute() { throw std::runtime_error("bad type"); return Value(); } - -Rm::Rm(RosQueuedSubscribe& entity, const std::string& docstring) - : Command(entity, boost::assign::list_of(Value::STRING), docstring) {} - -Value Rm::doExecute() { - RosQueuedSubscribe& entity = static_cast<RosQueuedSubscribe&>(owner()); - std::vector<Value> values = getParameterValues(); - const std::string& signal = values[0].value(); - entity.rm(signal); - return Value(); -} - -QueueSize::QueueSize(RosQueuedSubscribe& entity, const std::string& docstring) - : Command(entity, boost::assign::list_of(Value::STRING), docstring) {} - -Value QueueSize::doExecute() { - RosQueuedSubscribe& entity = static_cast<RosQueuedSubscribe&>(owner()); - - std::vector<Value> values = getParameterValues(); - const std::string& signal = values[0].value(); - - return Value((unsigned)entity.queueSize(signal)); -} - -ReadQueue::ReadQueue(RosQueuedSubscribe& entity, const std::string& docstring) - : Command(entity, boost::assign::list_of(Value::INT), docstring) {} - -Value ReadQueue::doExecute() { - RosQueuedSubscribe& entity = static_cast<RosQueuedSubscribe&>(owner()); - - std::vector<Value> values = getParameterValues(); - int read = values[0].value(); - entity.readQueue(read); - - return Value(); -} } // namespace rosQueuedSubscribe } // end of namespace command. @@ -141,53 +74,6 @@ RosQueuedSubscribe::RosQueuedSubscribe(const std::string& n) " - topic: the topic name in ROS.\n" "\n"; addCommand("add", new command::rosQueuedSubscribe::Add(*this, docstring)); - docstring = - "\n" - " Remove a signal reading data from a ROS topic\n" - "\n" - " Input:\n" - " - name of the signal to remove (see method list for the list of " - "signals).\n" - "\n"; - addCommand("rm", new command::rosQueuedSubscribe::Rm(*this, docstring)); - docstring = - "\n" - " Remove all signals reading data from a ROS topic\n" - "\n" - " No input:\n" - "\n"; - addCommand("clear", new command::rosQueuedSubscribe::Clear(*this, docstring)); - docstring = - "\n" - " List signals reading data from a ROS topic\n" - "\n" - " No input:\n" - "\n"; - addCommand("list", new command::rosQueuedSubscribe::List(*this, docstring)); - docstring = - "\n" - " Empty the queue of a given signal\n" - "\n" - " Input is:\n" - " - name of the signal (see method list for the list of signals).\n" - "\n"; - addCommand("clearQueue", new command::rosQueuedSubscribe::ClearQueue(*this, docstring)); - docstring = - "\n" - " Return the queue size of a given signal\n" - "\n" - " Input is:\n" - " - name of the signal (see method list for the list of signals).\n" - "\n"; - addCommand("queueSize", new command::rosQueuedSubscribe::QueueSize(*this, docstring)); - docstring = - "\n" - " Whether signals should read values from the queues, and when.\n" - "\n" - " Input is:\n" - " - int (dynamic graph time at which the reading begin).\n" - "\n"; - addCommand("readQueue", new command::rosQueuedSubscribe::ReadQueue(*this, docstring)); } RosQueuedSubscribe::~RosQueuedSubscribe() {} @@ -206,13 +92,10 @@ void RosQueuedSubscribe::rm(const std::string& signal) { } } -std::string RosQueuedSubscribe::list() { - std::string result("["); - for (std::map<std::string, bindedSignal_t>::const_iterator it = bindedSignal_.begin(); it != bindedSignal_.end(); - it++) { - result += "'" + it->first + "',"; - } - result += "]"; +std::vector<std::string> RosQueuedSubscribe::list() { + std::vector<std::string> result(bindedSignal_.size()); + std::transform(bindedSignal_.begin(), bindedSignal_.end(), + result.begin(), [](const auto& pair) { return pair.first; }); return result; } diff --git a/src/ros_queued_subscribe.hh b/src/ros_queued_subscribe.hh index 72c36a31e26a77c5b357ef3a9f3c47aa45c9be5a..ff0eb9f4437b425005fe64545e0286cadb80af8a 100644 --- a/src/ros_queued_subscribe.hh +++ b/src/ros_queued_subscribe.hh @@ -38,12 +38,6 @@ using ::dynamicgraph::command::Value; } ROS_QUEUED_SUBSCRIBE_MAKE_COMMAND(Add); -ROS_QUEUED_SUBSCRIBE_MAKE_COMMAND(Clear); -ROS_QUEUED_SUBSCRIBE_MAKE_COMMAND(List); -ROS_QUEUED_SUBSCRIBE_MAKE_COMMAND(Rm); -ROS_QUEUED_SUBSCRIBE_MAKE_COMMAND(ClearQueue); -ROS_QUEUED_SUBSCRIBE_MAKE_COMMAND(QueueSize); -ROS_QUEUED_SUBSCRIBE_MAKE_COMMAND(ReadQueue); #undef ROS_QUEUED_SUBSCRIBE_MAKE_COMMAND @@ -142,7 +136,7 @@ class RosQueuedSubscribe : public dynamicgraph::Entity { void display(std::ostream& os) const; void rm(const std::string& signal); - std::string list(); + std::vector<std::string> list(); void clear(); void clearQueue(const std::string& signal); void readQueue(int beginReadingAt); diff --git a/src/ros_subscribe-python-module-py.cc b/src/ros_subscribe-python-module-py.cc new file mode 100644 index 0000000000000000000000000000000000000000..cbe164e5b46937607d1787c6e60913f26cbadcdb --- /dev/null +++ b/src/ros_subscribe-python-module-py.cc @@ -0,0 +1,17 @@ +#include <dynamic-graph/python/module.hh> +#include "ros_subscribe.hh" + +namespace dg = dynamicgraph; + + +BOOST_PYTHON_MODULE(wrap) +{ + bp::import("dynamic_graph"); + + dg::python::exposeEntity<dg::RosSubscribe, bp::bases<dg::Entity>, dg::python::AddCommands>() + .def("clear", &dg::RosSubscribe::clear, "Remove all signals reading data from a ROS topic") + .def("rm", &dg::RosSubscribe::rm, "Remove a signal reading data from a ROS topic", + bp::args("signal_name")) + .def("list", &dg::RosSubscribe::list, "List signals reading data from a ROS topic") + ; +} diff --git a/src/ros_subscribe-python.hh b/src/ros_subscribe-python.hh deleted file mode 100644 index 4a0bb03afa8c34ef1bf178534179698ea40e91b7..0000000000000000000000000000000000000000 --- a/src/ros_subscribe-python.hh +++ /dev/null @@ -1,3 +0,0 @@ -#include "ros_subscribe.hh" - -typedef boost::mpl::vector< dynamicgraph::RosSubscribe > entities_t; diff --git a/src/ros_subscribe.cpp b/src/ros_subscribe.cpp index f046af6dc30e08bd90b341e81806f2ec19eded30..cfa01a201002db721842351a21227276b8404b27 100644 --- a/src/ros_subscribe.cpp +++ b/src/ros_subscribe.cpp @@ -18,24 +18,6 @@ DYNAMICGRAPH_FACTORY_ENTITY_PLUGIN(RosSubscribe, "RosSubscribe"); namespace command { namespace rosSubscribe { -Clear::Clear(RosSubscribe& entity, const std::string& docstring) - : Command(entity, std::vector<Value::Type>(), docstring) {} - -Value Clear::doExecute() { - RosSubscribe& entity = static_cast<RosSubscribe&>(owner()); - - entity.clear(); - return Value(); -} - -List::List(RosSubscribe& entity, const std::string& docstring) - : Command(entity, std::vector<Value::Type>(), docstring) {} - -Value List::doExecute() { - RosSubscribe& entity = static_cast<RosSubscribe&>(owner()); - return Value(entity.list()); -} - Add::Add(RosSubscribe& entity, const std::string& docstring) : Command(entity, boost::assign::list_of(Value::STRING)(Value::STRING)(Value::STRING), docstring) {} @@ -73,17 +55,6 @@ Value Add::doExecute() { throw std::runtime_error("bad type"); return Value(); } - -Rm::Rm(RosSubscribe& entity, const std::string& docstring) - : Command(entity, boost::assign::list_of(Value::STRING), docstring) {} - -Value Rm::doExecute() { - RosSubscribe& entity = static_cast<RosSubscribe&>(owner()); - std::vector<Value> values = getParameterValues(); - const std::string& signal = values[0].value(); - entity.rm(signal); - return Value(); -} } // namespace rosSubscribe } // end of namespace command. @@ -106,29 +77,6 @@ RosSubscribe::RosSubscribe(const std::string& n) : dynamicgraph::Entity(n), nh_( " - topic: the topic name in ROS.\n" "\n"; addCommand("add", new command::rosSubscribe::Add(*this, docstring)); - docstring = - "\n" - " Remove a signal reading data from a ROS topic\n" - "\n" - " Input:\n" - " - name of the signal to remove (see method list for the list of " - "signals).\n" - "\n"; - addCommand("rm", new command::rosSubscribe::Rm(*this, docstring)); - docstring = - "\n" - " Remove all signals reading data from a ROS topic\n" - "\n" - " No input:\n" - "\n"; - addCommand("clear", new command::rosSubscribe::Clear(*this, docstring)); - docstring = - "\n" - " List signals reading data from a ROS topic\n" - "\n" - " No input:\n" - "\n"; - addCommand("list", new command::rosSubscribe::List(*this, docstring)); } RosSubscribe::~RosSubscribe() {} @@ -147,13 +95,10 @@ void RosSubscribe::rm(const std::string& signal) { } } -std::string RosSubscribe::list() { - std::string result("["); - for (std::map<std::string, bindedSignal_t>::const_iterator it = bindedSignal_.begin(); it != bindedSignal_.end(); - it++) { - result += "'" + it->first + "',"; - } - result += "]"; +std::vector<std::string> RosSubscribe::list() { + std::vector<std::string> result(bindedSignal_.size()); + std::transform(bindedSignal_.begin(), bindedSignal_.end(), + result.begin(), [](const auto& pair) { return pair.first; }); return result; } diff --git a/src/ros_subscribe.hh b/src/ros_subscribe.hh index c5fd7dbb976cbb7b1050fbe2e79174cb81f66618..1928e486bb4ec60793811b5228208b6d5be912bb 100644 --- a/src/ros_subscribe.hh +++ b/src/ros_subscribe.hh @@ -31,9 +31,6 @@ using ::dynamicgraph::command::Value; } ROS_SUBSCRIBE_MAKE_COMMAND(Add); -ROS_SUBSCRIBE_MAKE_COMMAND(Clear); -ROS_SUBSCRIBE_MAKE_COMMAND(List); -ROS_SUBSCRIBE_MAKE_COMMAND(Rm); #undef ROS_SUBSCRIBE_MAKE_COMMAND @@ -62,7 +59,7 @@ class RosSubscribe : public dynamicgraph::Entity { void add(const std::string& signal, const std::string& topic); void rm(const std::string& signal); - std::string list(); + std::vector<std::string> list(); void clear(); template <typename T> diff --git a/src/ros_tf_listener-python-module-py.cc b/src/ros_tf_listener-python-module-py.cc new file mode 100644 index 0000000000000000000000000000000000000000..3815f4530df6fe81bc1f273b3bdc777dca061f6a --- /dev/null +++ b/src/ros_tf_listener-python-module-py.cc @@ -0,0 +1,18 @@ +#include <dynamic-graph/python/module.hh> +#include "ros_tf_listener.hh" + +namespace dg = dynamicgraph; + +BOOST_PYTHON_MODULE(wrap) +{ + bp::import("dynamic_graph"); + + dg::python::exposeEntity<dg::RosTfListener, bp::bases<dg::Entity>, dg::python::AddCommands>() + .def("add", &dg::RosTfListener::add, + "Add a signal containing the transform between two frames.", + bp::args( "to_frame_name", "from_frame_name", "out_signal_name")) + .def("setMaximumDelay", &dg::RosTfListener::setMaximumDelay, + "Set the maximum time delay of the transform obtained from tf.", + bp::args("signal_name", "delay_seconds")) + ; +} diff --git a/src/ros_tf_listener-python.hh b/src/ros_tf_listener-python.hh deleted file mode 100644 index 492d61ffbcaa383d36ecc7d7fd56a89f1bbcf56c..0000000000000000000000000000000000000000 --- a/src/ros_tf_listener-python.hh +++ /dev/null @@ -1,3 +0,0 @@ -#include "ros_tf_listener.hh" - -typedef boost::mpl::vector< dynamicgraph::RosTfListener > entities_t; diff --git a/src/ros_tf_listener.hh b/src/ros_tf_listener.hh index a95907a097aa2d5d732476ecebba5c270bb68b83..778c812a1bfd42b67a6c95687000e568a162e8e2 100644 --- a/src/ros_tf_listener.hh +++ b/src/ros_tf_listener.hh @@ -72,31 +72,11 @@ class RosTfListener : public Entity { : Entity(_name) , buffer() , listener(buffer, rosInit(), false) - { - std::string docstring = - "\n" - " Add a signal containing the transform between two frames.\n" - "\n" - " Input:\n" - " - to : frame name\n" - " - from: frame name,\n" - " - signalName: the signal name in dynamic-graph" - "\n"; - addCommand("add", command::makeCommandVoid3(*this, &RosTfListener::add, docstring)); - docstring = - "\n" - " Set the maximum time delay of the transform obtained from tf.\n" - "\n" - " Input:\n" - " - signalName: the signal name,\n" - " - delay : in seconds\n" - "\n"; - addCommand("setMaximumDelay", command::makeCommandVoid2(*this, &RosTfListener::setMaximumDelay, docstring)); - } + {} ~RosTfListener() { - for (Map_t::const_iterator _it = listenerDatas.begin(); _it != listenerDatas.end(); ++_it) delete _it->second; + for (const auto& pair : listenerDatas) delete pair.second; } void add(const std::string& to, const std::string& from, const std::string& signame)