python-module.cc
Go to the documentation of this file.
1 #include <sot/core/device.hh>
2 #include <sot/core/flags.hh>
3 #include <sot/core/integrator.hh>
4 
7 
8 namespace dg = dynamicgraph;
9 namespace dgs = dynamicgraph::sot;
10 
11 typedef bp::return_value_policy<bp::reference_existing_object>
13 
15  bp::import("dynamic_graph");
16 
17  using dgs::PeriodicCall;
18  bp::class_<PeriodicCall, boost::noncopyable>("PeriodicCall", bp::no_init)
19  .def("addSignal",
20  static_cast<void (PeriodicCall::*)(const std::string &,
23  "Add the signal to the refresh list", (bp::arg("name"), "signal"))
24  .def("addSignal",
25  static_cast<void (PeriodicCall::*)(const std::string &)>(
27  "Add the signal to the refresh list", (bp::arg("signal_name")))
28 
29  .def("addDownsampledSignal",
30  static_cast<void (PeriodicCall::*)(
31  const std::string &, dg::SignalBase<int> &,
32  const unsigned int &)>(&PeriodicCall::addDownsampledSignal),
33  "Add the signal to the refresh list\n"
34  "The downsampling factor: 1 means every time, "
35  "2 means every other time, etc...",
36  (bp::arg("name"), "signal", "factor"))
37  .def("addDownsampledSignal",
38  static_cast<void (PeriodicCall::*)(const std::string &,
39  const unsigned int &)>(
41  "Add the signal to the refresh list\n"
42  "The downsampling factor: 1 means every time, "
43  "2 means every other time, etc...",
44  (bp::arg("signal_name"), "factor"))
45 
46  .def("rmSignal", &PeriodicCall::rmSignal,
47  "Remove the signal to the refresh list", bp::arg("name"))
48  .def("clear", &PeriodicCall::clear,
49  "Clear all signals and commands from the refresh list.")
50  .def(
51  "__str__", +[](const PeriodicCall &e) {
52  std::ostringstream os;
53  e.display(os);
54  return os.str();
55  });
56 
57  dynamicgraph::python::exposeEntity<dgs::Device>().def(
58  "getControlSize", &dgs::Device::getControlSize,
59  "Get number of joints controlled by the device.");
60 
61  using dgs::Flags;
62  bp::class_<Flags>("Flags", bp::init<>())
63  .def(bp::init<const char *>())
64  .def("__init__", bp::make_constructor(+[](bp::list bools) {
65  std::vector<bool> flags(bp::len(bools));
66  for (std::size_t i = 0; i < flags.size(); ++i)
67  flags[i] = bp::extract<bool>(bools[i]);
68  return new Flags(flags);
69  }))
70  .def("__init__", bp::make_constructor(+[](bp::tuple bools) {
71  std::vector<bool> flags(bp::len(bools));
72  for (std::size_t i = 0; i < flags.size(); ++i)
73  flags[i] = bp::extract<bool>(bools[i]);
74  return new Flags(flags);
75  }))
76  .def("add", &Flags::add)
77  .def("set", &Flags::set)
78  .def("unset", &Flags::unset)
79 
80  .def(bp::self & bp::self)
81  .def(bp::self | bp::self)
82  .def(bp::self &= bp::self)
83  .def(bp::self |= bp::self)
84 
85  .def("__call__", &Flags::operator())
86  .def("__bool__", &Flags::operator bool)
87  .def("reversed", &Flags::operator!)
88 
89  .def(
90  "set",
91  +[](Flags &f, const std::string &s) {
92  std::istringstream is(s);
93  is >> f;
94  })
95  .def(
96  "__str__", +[](const Flags &f) {
97  std::ostringstream os;
98  os << f;
99  return os.str();
100  });
101 
102  dg::python::exposeSignalsOfType<Flags, int>("Flags");
103  dg::python::exposeEntity<dgs::Integrator, bp::bases<dg::Entity>,
104  dg::python::AddCommands>()
105  .add_property("after",
106  bp::make_function(&dgs::Integrator::periodicCallAfter,
108  .add_property("before",
109  bp::make_function(&dgs::Integrator::periodicCallBefore,
111  .add_property("model",
112  bp::make_function(&dgs::Integrator::getModel,
114  bp::make_function(&dgs::Integrator::setModel))
115  .def("setModel", &dgs::Integrator::setModel)
116  .def("setInitialConfig", &dgs::Integrator::setInitialConfig);
117 
118  typedef dgs::internal::Signal S_t;
119  bp::class_<S_t, bp::bases<dg::Signal<dg::Vector, int> >, boost::noncopyable>
120  obj("SignalIntegratorVector", bp::init<std::string>());
121  obj.add_property(
122  "value",
123  bp::make_function(&S_t::accessCopy,
124  bp::return_value_policy<bp::copy_const_reference>()),
125  &S_t::setConstant, // TODO check the setter
126  "the signal value.\n"
127  "warning: for Eigen objects, sig.value[0] = 1. may not work).");
128 }
void set(bool ownStorage, Vec3f *points_, unsigned int num_points_)
void addDownsampledSignal(const std::string &name, dynamicgraph::SignalBase< int > &sig, const unsigned int &downsamplingFactor)
bp::return_value_policy< bp::reference_existing_object > reference_existing_object
s
PeriodicCall & periodicCallBefore()
Definition: integrator.hh:127
void setModel(::pinocchio::Model *model)
Definition: integrator.cpp:152
int i
::pinocchio::Model * getModel()
Definition: integrator.cpp:150
void def(const char *name, Func func)
PeriodicCall & periodicCallAfter()
Definition: integrator.hh:128
void rmSignal(const std::string &name)
void add(const bool &b)
Definition: flags.cpp:69
int getControlSize() const
Definition: device.cpp:261
void f(void)
BOOST_PYTHON_MODULE(wrap)
void addSignal(const std::string &name, dynamicgraph::SignalBase< int > &sig)
void unset(const unsigned int &i)
Definition: flags.cpp:76
void setInitialConfig(const Vector &initConfig)
Definition: integrator.cpp:158


sot-core
Author(s): Olivier Stasse, ostasse@laas.fr
autogenerated on Wed Jun 21 2023 02:51:26