Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use long int for signal time #113

Merged
merged 3 commits into from
Jul 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions include/dynamic-graph/python/dynamic-graph-py.hh
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ void exposeSignals();

// Declare functions defined in other source files
namespace signalBase {
SignalBase<int>* createSignalWrapper(const char* name, const char* type,
bp::object object);
SignalBase<sigtime_t>* createSignalWrapper(const char* name, const char* type,
bp::object object);
} // namespace signalBase
namespace entity {

Expand Down
2 changes: 1 addition & 1 deletion include/dynamic-graph/python/signal-wrapper.hh
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class PythonSignalContainer : public Entity {
public:
using Entity::Entity;

void signalRegistration(const SignalArray<int>& signals);
void signalRegistration(const SignalArray<sigtime_t>& signals);

void rmSignal(const std::string& name);
};
Expand Down
8 changes: 8 additions & 0 deletions src/dynamic_graph/convert-dg-to-py.cc
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,12 @@ command::Value toValue(bp::object o, const command::Value::Type& valueType) {
return Value(bp::extract<bool>(o));
case (Value::UNSIGNED):
return Value(bp::extract<unsigned>(o));
case (Value::UNSIGNEDLONGINT):
return Value(bp::extract<unsigned long int>(o));
case (Value::INT):
return Value(bp::extract<int>(o));
case (Value::LONGINT):
return Value(bp::extract<long int>(o));
case (Value::FLOAT):
return Value(bp::extract<float>(o));
case (Value::DOUBLE):
Expand Down Expand Up @@ -67,8 +71,12 @@ bp::object fromValue(const command::Value& value) {
return bp::object(value.boolValue());
case (Value::UNSIGNED):
return bp::object(value.unsignedValue());
case (Value::UNSIGNEDLONGINT):
return bp::object(value.unsignedlongintValue());
case (Value::INT):
return bp::object(value.intValue());
case (Value::LONGINT):
return bp::object(value.longintValue());
case (Value::FLOAT):
return bp::object(value.floatValue());
case (Value::DOUBLE):
Expand Down
7 changes: 4 additions & 3 deletions src/dynamic_graph/dynamic-graph-py.cc
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ namespace python {
/**
\brief plug a signal into another one.
*/
void plug(SignalBase<int>* signalOut, SignalBase<int>* signalIn) {
void plug(SignalBase<sigtime_t>* signalOut, SignalBase<sigtime_t>* signalIn) {
signalIn->plug(signalOut);
}

Expand Down Expand Up @@ -66,7 +66,8 @@ MapOfEntities* getEntityMap() {
&dg::PoolStorage::getInstance()->getEntityMap());
}

dg::SignalBase<int>* getSignal(dg::Entity& e, const std::string& name) {
dg::SignalBase<dg::sigtime_t>* getSignal(dg::Entity& e,
const std::string& name) {
return &e.getSignal(name);
}

Expand All @@ -76,7 +77,7 @@ class PythonEntity : public dg::Entity {
public:
using dg::Entity::Entity;

void signalRegistration(dg::SignalBase<int>& signal) {
void signalRegistration(dg::SignalBase<dg::sigtime_t>& signal) {
dg::Entity::signalRegistration(signal);
}
void signalDeregistration(const std::string& name) {
Expand Down
95 changes: 55 additions & 40 deletions src/dynamic_graph/signal-base-py.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ namespace bp = boost::python;
namespace dynamicgraph {
namespace python {

typedef int time_type;

typedef Eigen::AngleAxis<double> VectorUTheta;
typedef Eigen::Quaternion<double> Quaternion;

Expand Down Expand Up @@ -79,18 +77,18 @@ void exposeSignalBase(const char* name) {
})
.def(
"displayDependencies",
+[](const S_t& s, int time) -> std::string {
+[](const S_t& s, int depth) -> std::string {
std::ostringstream oss;
s.displayDependencies(oss, time);
s.displayDependencies(oss, depth);
return oss.str();
},
"Print the signal dependencies in a string");
}

template <>
auto exposeSignal<MatrixHomogeneous, time_type>(const std::string& name) {
typedef Signal<MatrixHomogeneous, time_type> S_t;
bp::class_<S_t, bp::bases<SignalBase<time_type> >, boost::noncopyable> obj(
auto exposeSignal<MatrixHomogeneous, sigtime_t>(const std::string& name) {
typedef Signal<MatrixHomogeneous, sigtime_t> S_t;
bp::class_<S_t, bp::bases<SignalBase<sigtime_t> >, boost::noncopyable> obj(
name.c_str(), bp::init<std::string>());
obj.add_property(
"value",
Expand All @@ -107,31 +105,35 @@ auto exposeSignal<MatrixHomogeneous, time_type>(const std::string& name) {
}

void exposeSignals() {
exposeSignalBase<time_type>("SignalBase");

exposeSignalsOfType<bool, time_type>("Bool");
exposeSignalsOfType<int, time_type>("Int");
exposeSignalsOfType<double, time_type>("Double");

exposeSignalsOfType<Vector, time_type>("Vector");
exposeSignalsOfType<Vector3, time_type>("Vector3");
exposeSignalsOfType<Vector7, time_type>("Vector7");

exposeSignalsOfType<Matrix, time_type>("Matrix");
exposeSignalsOfType<MatrixRotation, time_type>("MatrixRotation");
exposeSignalsOfType<MatrixHomogeneous, time_type>("MatrixHomogeneous");
exposeSignalsOfType<MatrixTwist, time_type>("MatrixTwist");

exposeSignalsOfType<Quaternion, time_type>("Quaternion");
exposeSignalsOfType<VectorUTheta, time_type>("VectorUTheta");
exposeSignalBase<sigtime_t>("SignalBase");

exposeSignalsOfType<bool, sigtime_t>("Bool");
exposeSignalsOfType<unsigned int, sigtime_t>("UInt");
exposeSignalsOfType<int, sigtime_t>("Int");
exposeSignalsOfType<uint64_t, sigtime_t>("UInt64");
exposeSignalsOfType<int64_t, sigtime_t>("Int64");
exposeSignalsOfType<double, sigtime_t>("Double");

exposeSignalsOfType<Vector, sigtime_t>("Vector");
exposeSignalsOfType<Vector3, sigtime_t>("Vector3");
exposeSignalsOfType<Vector7, sigtime_t>("Vector7");

exposeSignalsOfType<Matrix, sigtime_t>("Matrix");
exposeSignalsOfType<MatrixRotation, sigtime_t>("MatrixRotation");
exposeSignalsOfType<MatrixHomogeneous, sigtime_t>("MatrixHomogeneous");
exposeSignalsOfType<MatrixTwist, sigtime_t>("MatrixTwist");

exposeSignalsOfType<Quaternion, sigtime_t>("Quaternion");
exposeSignalsOfType<VectorUTheta, sigtime_t>("VectorUTheta");
}

namespace signalBase {

template <class T>
SignalWrapper<T, int>* createSignalWrapperTpl(const char* name, bp::object o,
std::string& error) {
typedef SignalWrapper<T, int> SignalWrapper_t;
SignalWrapper<T, sigtime_t>* createSignalWrapperTpl(const char* name,
bp::object o,
std::string& error) {
typedef SignalWrapper<T, sigtime_t> SignalWrapper_t;
if (!SignalWrapper_t::checkCallable(o, error)) {
return NULL;
}
Expand All @@ -153,23 +155,36 @@ PythonSignalContainer* getPythonSignalContainer() {
/**
\brief Create an instance of SignalWrapper
*/
SignalBase<int>* createSignalWrapper(const char* name, const char* type,
bp::object object) {
SignalBase<sigtime_t>* createSignalWrapper(const char* name, const char* type,
bp::object object) {
PythonSignalContainer* psc = getPythonSignalContainer();
if (psc == NULL) return NULL;

SignalBase<int>* obj = NULL;
SignalBase<sigtime_t>* obj = NULL;
std::string error;
SIGNAL_WRAPPER_TYPE(if, BOOL, bool)
// SIGNAL_WRAPPER_TYPE(else if, UNSIGNED ,bool)
SIGNAL_WRAPPER_TYPE(else if, INT, int)
SIGNAL_WRAPPER_TYPE(else if, FLOAT, float)
SIGNAL_WRAPPER_TYPE(else if, DOUBLE, double)
// SIGNAL_WRAPPER_TYPE(else if, STRING ,bool)
SIGNAL_WRAPPER_TYPE(else if, VECTOR, Vector)
// SIGNAL_WRAPPER_TYPE(else if, MATRIX ,bool)
// SIGNAL_WRAPPER_TYPE(else if, MATRIX4D ,bool)
else {
if (command::Value::typeName(command::Value::BOOL).compare(type) == 0) {
obj = createSignalWrapperTpl<bool>(name, object, error);
} else if (command::Value::typeName(command::Value::UNSIGNED).compare(type) ==
0) {
obj = createSignalWrapperTpl<unsigned int>(name, object, error);
} else if (command::Value::typeName(command::Value::INT).compare(type) == 0) {
obj = createSignalWrapperTpl<int>(name, object, error);
} else if (command::Value::typeName(command::Value::UNSIGNEDLONGINT)
.compare(type) == 0) {
obj = createSignalWrapperTpl<uint64_t>(name, object, error);
} else if (command::Value::typeName(command::Value::LONGINT).compare(type) ==
0) {
obj = createSignalWrapperTpl<int64_t>(name, object, error);
} else if (command::Value::typeName(command::Value::FLOAT).compare(type) ==
0) {
obj = createSignalWrapperTpl<float>(name, object, error);
} else if (command::Value::typeName(command::Value::DOUBLE).compare(type) ==
0) {
obj = createSignalWrapperTpl<double>(name, object, error);
} else if (command::Value::typeName(command::Value::VECTOR).compare(type) ==
0) {
obj = createSignalWrapperTpl<Vector>(name, object, error);
} else {
error = "Type not understood";
}

Expand Down
15 changes: 9 additions & 6 deletions src/dynamic_graph/signal-wrapper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
namespace dynamicgraph {
namespace python {
void PythonSignalContainer::signalRegistration(
const SignalArray<int>& signals) {
const SignalArray<sigtime_t>& signals) {
Entity::signalRegistration(signals);
}

Expand All @@ -30,10 +30,13 @@ bool SignalWrapper<T, Time>::checkCallable(pyobject c, std::string& error) {
return true;
}

template class SignalWrapper<bool, int>;
template class SignalWrapper<int, int>;
template class SignalWrapper<float, int>;
template class SignalWrapper<double, int>;
template class SignalWrapper<Vector, int>;
template class SignalWrapper<bool, sigtime_t>;
template class SignalWrapper<int32_t, sigtime_t>;
template class SignalWrapper<int64_t, sigtime_t>;
template class SignalWrapper<uint32_t, sigtime_t>;
template class SignalWrapper<uint64_t, sigtime_t>;
template class SignalWrapper<float, sigtime_t>;
template class SignalWrapper<double, sigtime_t>;
template class SignalWrapper<Vector, sigtime_t>;
} // namespace python
} // namespace dynamicgraph
2 changes: 1 addition & 1 deletion tests/custom_entity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ void CustomEntity::rmValidSignal() {
signalDeregistration("out_double");
}

double &CustomEntity::update(double &res, const int &inTime) {
double &CustomEntity::update(double &res, const sigtime_t &inTime) {
const double &aDouble = m_sigdSIN(inTime);
res = aDouble;
logger().stream(MSG_TYPE_ERROR) << "start update " << res << '\n';
Expand Down
6 changes: 3 additions & 3 deletions tests/custom_entity.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
namespace dynamicgraph {
class CustomEntity : public Entity {
public:
dynamicgraph::SignalPtr<double, int> m_sigdSIN;
dynamicgraph::SignalTimeDependent<double, int> m_sigdTimeDepSOUT;
dynamicgraph::SignalPtr<double, sigtime_t> m_sigdSIN;
dynamicgraph::SignalTimeDependent<double, sigtime_t> m_sigdTimeDepSOUT;

DYNAMIC_GRAPH_ENTITY_DECL();
CustomEntity(const std::string n);
Expand All @@ -24,7 +24,7 @@ class CustomEntity : public Entity {

void rmValidSignal();

double &update(double &res, const int &inTime);
double &update(double &res, const sigtime_t &inTime);

void act();
};
Expand Down
4 changes: 2 additions & 2 deletions tests/test_bindings.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
dynamic_graph.wrap.plug(%s, %s)
did not match C++ signature:
plug("""
"dynamicgraph::SignalBase<int>* signalOut, "
"dynamicgraph::SignalBase<int>* signalIn)"
"dynamicgraph::SignalBase<long>* signalOut, "
"dynamicgraph::SignalBase<long>* signalIn)"
)


Expand Down