Skip to content

Commit ab05904

Browse files
committed
Expose entity Device and class PeriodicCall
1 parent e532936 commit ab05904

File tree

4 files changed

+44
-4
lines changed

4 files changed

+44
-4
lines changed

include/sot/core/device.hh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,9 @@ public:
9797
void setTorqueBounds(const Vector &lower, const Vector &upper);
9898
/// \}
9999

100+
PeriodicCall& periodicCallBefore() { return periodicCallBefore_; }
101+
PeriodicCall& periodicCallAfter() { return periodicCallAfter_; }
102+
100103
public: /* --- DISPLAY --- */
101104
virtual void display(std::ostream &os) const;
102105
virtual void cmdDisplay();

src/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,10 @@ FOREACH(plugin ${plugins})
117117
ENDFOREACH(plugin)
118118

119119
IF(BUILD_PYTHON_INTERFACE)
120+
DYNAMIC_GRAPH_PYTHON_MODULE("${PYTHON_DIR}"
121+
${PROJECT_NAME} ${PROJECT_NAME}-wrap
122+
SOURCE_PYTHON_MODULE "${CMAKE_CURRENT_SOURCE_DIR}/python-module.cc")
123+
120124
INSTALL(FILES
121125
${CMAKE_CURRENT_SOURCE_DIR}/dynamic_graph/sot/__init__.py
122126
DESTINATION ${PYTHON_SITELIB}/dynamic_graph/sot)

src/python-module.cc

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#include "dynamic-graph/python/module.hh"
2+
3+
#include <sot/core/device.hh>
4+
5+
namespace dg = dynamicgraph;
6+
namespace dgs = dynamicgraph::sot;
7+
8+
typedef bp::return_value_policy<bp::reference_existing_object> reference_existing_object;
9+
10+
BOOST_PYTHON_MODULE(wrap)
11+
{
12+
bp::import("dynamic_graph");
13+
14+
using dgs::PeriodicCall;
15+
bp::class_<PeriodicCall, boost::noncopyable>("PeriodicCall", bp::no_init)
16+
.def("addSignal", static_cast<void (PeriodicCall::*)(const std::string &, dg::SignalBase<int> &)> (&PeriodicCall::addSignal))
17+
.def("addSignal", static_cast<void (PeriodicCall::*)(const std::string &)> (&PeriodicCall::addSignal))
18+
19+
.def("addDownsampledSignal", static_cast<void (PeriodicCall::*)(const std::string &, dg::SignalBase<int> &, const unsigned int &)> (&PeriodicCall::addDownsampledSignal))
20+
.def("addDownsampledSignal", static_cast<void (PeriodicCall::*)(const std::string &, const unsigned int &)> (&PeriodicCall::addDownsampledSignal))
21+
22+
.def("rmSignal", &PeriodicCall::rmSignal)
23+
.def("clear", &PeriodicCall::clear)
24+
.def("__str__", +[](const PeriodicCall& e) {
25+
std::ostringstream os;
26+
e.display(os);
27+
return os.str();
28+
})
29+
;
30+
31+
dynamicgraph::python::exposeEntity<dgs::Device>()
32+
.add_property("after",
33+
bp::make_function(&dgs::Device::periodicCallAfter, reference_existing_object()))
34+
.def_readonly("before",
35+
bp::make_function(&dgs::Device::periodicCallBefore, reference_existing_object()))
36+
;
37+
}

src/tools/device.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -202,10 +202,6 @@ Device::Device(const std::string &n)
202202
command::makeDirectGetter(
203203
*this, &this->timestep_,
204204
command::docDirectGetter("Time step", "double")));
205-
206-
// Handle commands and signals called in a synchronous way.
207-
periodicCallBefore_.addSpecificCommands(*this, commandMap, "before.");
208-
periodicCallAfter_.addSpecificCommands(*this, commandMap, "after.");
209205
}
210206
}
211207

0 commit comments

Comments
 (0)