Skip to content
Snippets Groups Projects
Commit cc7662be authored by Joseph Mirabel's avatar Joseph Mirabel Committed by Guilhem Saurel
Browse files

Expose function to define new signals.

parent a58a73a3
No related branches found
No related tags found
No related merge requests found
...@@ -44,6 +44,7 @@ SET(${PROJECT_NAME}_HEADERS ...@@ -44,6 +44,7 @@ SET(${PROJECT_NAME}_HEADERS
include/${CUSTOM_HEADER_DIR}/interpreter.hh include/${CUSTOM_HEADER_DIR}/interpreter.hh
include/${CUSTOM_HEADER_DIR}/module.hh include/${CUSTOM_HEADER_DIR}/module.hh
include/${CUSTOM_HEADER_DIR}/python-compat.hh include/${CUSTOM_HEADER_DIR}/python-compat.hh
include/${CUSTOM_HEADER_DIR}/signal.hh
include/${CUSTOM_HEADER_DIR}/signal-wrapper.hh include/${CUSTOM_HEADER_DIR}/signal-wrapper.hh
) )
......
// Copyright 2020, Joseph Mirabel, LAAS-CNRS.
#include <sstream>
#include <boost/python.hpp>
#include <dynamic-graph/signal-base.h>
#include <dynamic-graph/signal-ptr.h>
#include <dynamic-graph/signal-time-dependent.h>
#include <dynamic-graph/signal.h>
#include "dynamic-graph/python/signal-wrapper.hh"
namespace dynamicgraph {
namespace python {
template <typename T, typename Time>
auto exposeSignal(const std::string& name) {
namespace bp = boost::python;
typedef Signal<T, Time> S_t;
bp::class_<S_t, bp::bases<SignalBase<Time> >, boost::noncopyable> obj(
name.c_str(), bp::init<std::string>());
obj.add_property(
"value",
bp::make_function(&S_t::accessCopy,
bp::return_value_policy<bp::copy_const_reference>()),
&S_t::setConstant, // TODO check the setter
"the signal value.\n"
"warning: for Eigen objects, sig.value[0] = 1. may not work).");
return obj;
}
template <typename T, typename Time>
auto exposeSignalWrapper(const std::string& name) {
namespace bp = boost::python;
typedef SignalWrapper<T, Time> S_t;
bp::class_<S_t, bp::bases<Signal<T, Time> >, boost::noncopyable> obj(
name.c_str(), bp::no_init);
return obj;
}
template <typename T, typename Time>
auto exposeSignalPtr(const std::string& name) {
namespace bp = boost::python;
typedef SignalPtr<T, Time> S_t;
bp::class_<S_t, bp::bases<Signal<T, Time> >, boost::noncopyable> obj(
name.c_str(), bp::no_init);
return obj;
}
template <typename T, typename Time>
auto exposeSignalTimeDependent(const std::string& name) {
namespace bp = boost::python;
typedef SignalTimeDependent<T, Time> S_t;
bp::class_<S_t, bp::bases<Signal<T, Time> >, boost::noncopyable> obj(
name.c_str(), bp::no_init);
return obj;
}
template <typename T, typename Time>
void exposeSignalsOfType(const std::string& name) {
exposeSignal<T, Time>("Signal" + name);
exposeSignalPtr<T, Time>("SignalPtr" + name);
exposeSignalWrapper<T, Time>("SignalWrapper" + name);
exposeSignalTimeDependent<T, Time>("SignalTimeDependent" + name);
}
} // namespace python
} // namespace dynamicgraph
...@@ -5,19 +5,17 @@ ...@@ -5,19 +5,17 @@
#include <boost/python.hpp> #include <boost/python.hpp>
#include "dynamic-graph/python/signal.hh"
#include <dynamic-graph/signal-base.h> #include <dynamic-graph/signal-base.h>
#include <dynamic-graph/signal.h> #include <dynamic-graph/signal.h>
#include <dynamic-graph/signal-ptr.h> #include <dynamic-graph/signal-ptr.h>
#include <dynamic-graph/signal-time-dependent.h> #include <dynamic-graph/signal-time-dependent.h>
#include <dynamic-graph/signal-caster.h>
#include <dynamic-graph/linear-algebra.h> #include <dynamic-graph/linear-algebra.h>
#include <dynamic-graph/pool.h> #include <dynamic-graph/value.h>
#include <dynamic-graph/factory.h>
#include "dynamic-graph/python/dynamic-graph-py.hh" #include "dynamic-graph/python/dynamic-graph-py.hh"
#include "dynamic-graph/python/convert-dg-to-py.hh"
#include "dynamic-graph/python/signal-wrapper.hh" #include "dynamic-graph/python/signal-wrapper.hh"
#include "dynamic-graph/python/module.hh"
using dynamicgraph::SignalBase; using dynamicgraph::SignalBase;
...@@ -26,8 +24,6 @@ namespace bp = boost::python; ...@@ -26,8 +24,6 @@ namespace bp = boost::python;
namespace dynamicgraph { namespace dynamicgraph {
namespace python { namespace python {
using namespace convert;
typedef int time_type; typedef int time_type;
typedef Eigen::AngleAxis<double> VectorUTheta; typedef Eigen::AngleAxis<double> VectorUTheta;
...@@ -82,17 +78,6 @@ void exposeSignalBase(const char* name) { ...@@ -82,17 +78,6 @@ void exposeSignalBase(const char* name) {
"Print the signal dependencies in a string"); "Print the signal dependencies in a string");
} }
template <typename T, typename Time>
auto exposeSignal(const std::string& name) {
typedef Signal<T, Time> S_t;
bp::class_<S_t, bp::bases<SignalBase<Time> >, boost::noncopyable> obj(name.c_str(), bp::init<std::string>());
obj.add_property("value", bp::make_function(&S_t::accessCopy, bp::return_value_policy<bp::copy_const_reference>()),
&S_t::setConstant, // TODO check the setter
"the signal value.\n"
"warning: for Eigen objects, sig.value[0] = 1. may not work).");
return obj;
}
template <> template <>
auto exposeSignal<MatrixHomogeneous, time_type>(const std::string& name) { auto exposeSignal<MatrixHomogeneous, time_type>(const std::string& name) {
typedef Signal<MatrixHomogeneous, time_type> S_t; typedef Signal<MatrixHomogeneous, time_type> S_t;
...@@ -107,35 +92,6 @@ auto exposeSignal<MatrixHomogeneous, time_type>(const std::string& name) { ...@@ -107,35 +92,6 @@ auto exposeSignal<MatrixHomogeneous, time_type>(const std::string& name) {
return obj; return obj;
} }
template <typename T, typename Time>
auto exposeSignalWrapper(const std::string& name) {
typedef SignalWrapper<T, Time> S_t;
bp::class_<S_t, bp::bases<Signal<T, Time> >, boost::noncopyable> obj(name.c_str(), bp::no_init);
return obj;
}
template <typename T, typename Time>
auto exposeSignalPtr(const std::string& name) {
typedef SignalPtr<T, Time> S_t;
bp::class_<S_t, bp::bases<Signal<T, Time> >, boost::noncopyable> obj(name.c_str(), bp::no_init);
return obj;
}
template <typename T, typename Time>
auto exposeSignalTimeDependent(const std::string& name) {
typedef SignalTimeDependent<T, Time> S_t;
bp::class_<S_t, bp::bases<Signal<T, Time> >, boost::noncopyable> obj(name.c_str(), bp::no_init);
return obj;
}
template <typename T, typename Time>
void exposeSignalsOfType(const std::string& name) {
exposeSignal<T, Time>("Signal" + name);
exposeSignalPtr<T, Time>("SignalPtr" + name);
exposeSignalWrapper<T, Time>("SignalWrapper" + name);
exposeSignalTimeDependent<T, Time>("SignalTimeDependent" + name);
}
void exposeSignals() { void exposeSignals() {
exposeSignalBase<time_type>("SignalBase"); exposeSignalBase<time_type>("SignalBase");
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment