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<dg::sigtime_t> &,
32  const std::size_t &)>(&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 std::size_t &)>(
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, dg::sigtime_t>("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, dg::sigtime_t> >,
120  boost::noncopyable>
121  obj("SignalIntegratorVector", bp::init<std::string>());
122  obj.add_property(
123  "value",
124  bp::make_function(&S_t::accessCopy,
125  bp::return_value_policy<bp::copy_const_reference>()),
126  &S_t::setConstant, // TODO check the setter
127  "the signal value.\n"
128  "warning: for Eigen objects, sig.value[0] = 1. may not work).");
129 }
dynamicgraph::sot::Flags::add
void add(const bool &b)
Definition: flags.cpp:69
dynamicgraph::sot::Integrator::getModel
::pinocchio::Model * getModel()
Definition: integrator.cpp:151
dynamicgraph::sot::Integrator::setModel
void setModel(::pinocchio::Model *model)
Definition: integrator.cpp:153
dynamicgraph
i
int i
BOOST_PYTHON_MODULE
BOOST_PYTHON_MODULE(wrap)
Definition: python-module.cc:14
module.hh
def
void def(const char *name, Func func)
f
void f(void)
Definition: test_mailbox.cpp:33
dynamicgraph::sot::PeriodicCall::rmSignal
void rmSignal(const std::string &name)
Definition: periodic-call.cpp:67
dynamicgraph::sot::PeriodicCall::addSignal
void addSignal(const std::string &name, dynamicgraph::SignalBase< sigtime_t > &sig)
Definition: periodic-call.cpp:37
device.hh
s
s
reference_existing_object
bp::return_value_policy< bp::reference_existing_object > reference_existing_object
Definition: python-module.cc:12
wrap
set
void set(bool ownStorage, Vec3f *points_, unsigned int num_points_)
dynamicgraph::sot::Device::getControlSize
size_type getControlSize() const
Definition: device.cpp:261
dynamicgraph::sot::PeriodicCall::clear
void clear(void)
Definition: periodic-call.hh:79
integrator.hh
flags.hh
dynamicgraph::sot
signal.hh
dynamicgraph::sot::PeriodicCall
Definition: periodic-call.hh:37
dynamicgraph::sot::Integrator::periodicCallBefore
PeriodicCall & periodicCallBefore()
Definition: integrator.hh:129
dynamicgraph::sot::Integrator::periodicCallAfter
PeriodicCall & periodicCallAfter()
Definition: integrator.hh:130
dynamicgraph::sot::Flags
Definition: flags.hh:33
dynamicgraph::SignalBase
dynamicgraph::sot::PeriodicCall::addDownsampledSignal
void addDownsampledSignal(const std::string &name, dynamicgraph::SignalBase< sigtime_t > &sig, const std::size_t &downsamplingFactor)
Definition: periodic-call.cpp:51
dynamicgraph::sot::Integrator::setInitialConfig
void setInitialConfig(const Vector &initConfig)
Definition: integrator.cpp:159
dynamicgraph::sot::Flags::unset
void unset(const std::size_t &i)
Definition: flags.cpp:76


sot-core
Author(s): Olivier Stasse, ostasse@laas.fr
autogenerated on Tue Oct 24 2023 02:26:31