1 |
|
|
#include <sot/core/device.hh> |
2 |
|
|
#include <sot/core/flags.hh> |
3 |
|
|
|
4 |
|
|
#include "dynamic-graph/python/module.hh" |
5 |
|
|
#include "dynamic-graph/python/signal.hh" |
6 |
|
|
|
7 |
|
|
namespace dg = dynamicgraph; |
8 |
|
|
namespace dgs = dynamicgraph::sot; |
9 |
|
|
|
10 |
|
|
typedef bp::return_value_policy<bp::reference_existing_object> |
11 |
|
|
reference_existing_object; |
12 |
|
|
|
13 |
✓✗✓✗
|
28 |
BOOST_PYTHON_MODULE(wrap) { |
14 |
✓✗ |
14 |
bp::import("dynamic_graph"); |
15 |
|
|
|
16 |
|
|
using dgs::PeriodicCall; |
17 |
|
14 |
bp::class_<PeriodicCall, boost::noncopyable>("PeriodicCall", bp::no_init) |
18 |
|
|
.def("addSignal", |
19 |
|
|
static_cast<void (PeriodicCall::*)(const std::string &, |
20 |
|
|
dg::SignalBase<int> &)>( |
21 |
|
|
&PeriodicCall::addSignal), |
22 |
✓✗✓✗
|
28 |
"Add the signal to the refresh list", (bp::arg("name"), "signal")) |
23 |
|
|
.def("addSignal", |
24 |
|
|
static_cast<void (PeriodicCall::*)(const std::string &)>( |
25 |
|
|
&PeriodicCall::addSignal), |
26 |
✓✗✓✗
|
28 |
"Add the signal to the refresh list", (bp::arg("signal_name"))) |
27 |
|
|
|
28 |
|
|
.def("addDownsampledSignal", |
29 |
|
|
static_cast<void (PeriodicCall::*)( |
30 |
|
|
const std::string &, dg::SignalBase<int> &, |
31 |
|
|
const unsigned int &)>(&PeriodicCall::addDownsampledSignal), |
32 |
|
|
"Add the signal to the refresh list\n" |
33 |
|
|
"The downsampling factor: 1 means every time, " |
34 |
|
|
"2 means every other time, etc...", |
35 |
✓✗✓✗ ✓✗✓✗
|
28 |
(bp::arg("name"), "signal", "factor")) |
36 |
|
|
.def("addDownsampledSignal", |
37 |
|
|
static_cast<void (PeriodicCall::*)(const std::string &, |
38 |
|
|
const unsigned int &)>( |
39 |
|
|
&PeriodicCall::addDownsampledSignal), |
40 |
|
|
"Add the signal to the refresh list\n" |
41 |
|
|
"The downsampling factor: 1 means every time, " |
42 |
|
|
"2 means every other time, etc...", |
43 |
✓✗✓✗ ✓✗ |
28 |
(bp::arg("signal_name"), "factor")) |
44 |
|
|
|
45 |
|
|
.def("rmSignal", &PeriodicCall::rmSignal, |
46 |
✓✗✓✗ ✓✗ |
28 |
"Remove the signal to the refresh list", bp::arg("name")) |
47 |
|
|
.def("clear", &PeriodicCall::clear, |
48 |
✓✗ |
14 |
"Clear all signals and commands from the refresh list.") |
49 |
|
|
.def( |
50 |
|
|
"__str__", +[](const PeriodicCall &e) { |
51 |
|
|
std::ostringstream os; |
52 |
|
|
e.display(os); |
53 |
|
|
return os.str(); |
54 |
✓✗ |
14 |
}); |
55 |
|
|
|
56 |
|
14 |
dynamicgraph::python::exposeEntity<dgs::Device>() |
57 |
✓✗ |
14 |
.add_property("after", bp::make_function(&dgs::Device::periodicCallAfter, |
58 |
✓✗ |
28 |
reference_existing_object())) |
59 |
|
|
.add_property("before", |
60 |
✓✗ |
28 |
bp::make_function(&dgs::Device::periodicCallBefore, |
61 |
✓✗ |
28 |
reference_existing_object())); |
62 |
|
|
|
63 |
|
|
using dgs::Flags; |
64 |
✓✗ |
14 |
bp::class_<Flags>("Flags", bp::init<>()) |
65 |
✓✗✓✗
|
14 |
.def(bp::init<const char *>()) |
66 |
✓✗ |
28 |
.def("__init__", bp::make_constructor(+[](bp::list bools) { |
67 |
|
|
std::vector<bool> flags(bp::len(bools)); |
68 |
|
|
for (std::size_t i = 0; i < flags.size(); ++i) |
69 |
|
|
flags[i] = bp::extract<bool>(bools[i]); |
70 |
|
|
return new Flags(flags); |
71 |
✓✗ |
14 |
})) |
72 |
✓✗ |
28 |
.def("__init__", bp::make_constructor(+[](bp::tuple bools) { |
73 |
|
|
std::vector<bool> flags(bp::len(bools)); |
74 |
|
|
for (std::size_t i = 0; i < flags.size(); ++i) |
75 |
|
|
flags[i] = bp::extract<bool>(bools[i]); |
76 |
|
|
return new Flags(flags); |
77 |
✓✗ |
14 |
})) |
78 |
✓✗ |
14 |
.def("add", &Flags::add) |
79 |
✓✗ |
14 |
.def("set", &Flags::set) |
80 |
✓✗ |
14 |
.def("unset", &Flags::unset) |
81 |
|
|
|
82 |
✓✗ |
14 |
.def(bp::self & bp::self) |
83 |
✓✗ |
14 |
.def(bp::self | bp::self) |
84 |
✓✗ |
14 |
.def(bp::self &= bp::self) |
85 |
✓✗ |
14 |
.def(bp::self |= bp::self) |
86 |
|
|
|
87 |
✓✗ |
14 |
.def("__call__", &Flags::operator()) |
88 |
✓✗ |
14 |
.def("__bool__", &Flags::operator bool) |
89 |
✓✗ |
14 |
.def("reversed", &Flags::operator!) |
90 |
|
|
|
91 |
|
|
.def( |
92 |
|
|
"set", |
93 |
|
|
+[](Flags &f, const std::string &s) { |
94 |
|
|
std::istringstream is(s); |
95 |
|
|
is >> f; |
96 |
✓✗ |
14 |
}) |
97 |
|
|
.def( |
98 |
|
|
"__str__", +[](const Flags &f) { |
99 |
|
|
std::ostringstream os; |
100 |
|
|
os << f; |
101 |
|
|
return os.str(); |
102 |
✓✗ |
14 |
}); |
103 |
|
|
|
104 |
✓✗✓✗
|
14 |
dg::python::exposeSignalsOfType<Flags, int>("Flags"); |
105 |
|
14 |
} |