Commit 47d250a7 authored by Joseph Mirabel's avatar Joseph Mirabel
Browse files

Fix signal tracing format.

parent 7a687378
......@@ -90,14 +90,15 @@ inline static double run (std::istringstream &iss) {
/// Template class used to display a signal value.
template <typename T> struct signal_trace {
inline static void run(const T &value, std::ostream &os) { os << value << '\n'; }
inline static void run(const T &value, std::ostream &os) { os << value; }
};
/// Template specialization of signal_trace for Eigen objects
template <typename Derived> struct signal_trace<Eigen::DenseBase<Derived> > {
inline static void run(const Eigen::DenseBase<Derived> &value, std::ostream &os) {
template<typename _Scalar, int _Rows, int _Cols, int _Options, int _MaxRows, int _MaxCols>
struct signal_trace<Eigen::Matrix<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols> > {
inline static void run(const Eigen::Matrix<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols> &value, std::ostream &os) {
static const Eigen::IOFormat row_format (Eigen::StreamPrecision,
Eigen::DontAlignCols, ", ", ", ", "", "", "", "\n");
Eigen::DontAlignCols, "\t", "\t", "", "", "", "");
os << value.format(row_format);
}
};
......
......@@ -25,6 +25,7 @@ struct MyEntity : public dynamicgraph::Entity {
dynamicgraph::Signal<double, int> m_sigdSIN;
dynamicgraph::SignalTimeDependent<double, int> m_sigdTimeDepSOUT;
dynamicgraph::SignalTimeDependent<Vector, int> m_sigVTimeDepSOUT;
dynamicgraph::SignalTimeDependent<double, int> m_sigdTwoTimeDepSOUT;
explicit MyEntity(const std::string &name)
......@@ -33,12 +34,15 @@ struct MyEntity : public dynamicgraph::Entity {
m_sigdTimeDepSOUT(boost::bind(&MyEntity::update, this, _1, _2),
m_sigdSIN,
"MyEntity(" + name + ")::input(double)::out_double"),
m_sigVTimeDepSOUT(boost::bind(&MyEntity::updateVector, this, _1, _2),
m_sigdSIN,
"MyEntity(" + name + ")::input(vector)::out_vector"),
m_sigdTwoTimeDepSOUT(
boost::bind(&MyEntity::update, this, _1, _2), m_sigdSIN,
"MyEntity(" + name + ")::input(double)::out2double")
{
signalRegistration(m_sigdSIN << m_sigdTimeDepSOUT << m_sigdTwoTimeDepSOUT);
signalRegistration(m_sigdSIN << m_sigdTimeDepSOUT << m_sigVTimeDepSOUT << m_sigdTwoTimeDepSOUT);
}
virtual void display(std::ostream &os) const {
......@@ -52,11 +56,20 @@ struct MyEntity : public dynamicgraph::Entity {
res = aDouble;
return res;
}
Vector &updateVector(Vector &res, const int &inTime) {
const double &aDouble = m_sigdSIN(inTime);
res.resize(2);
res << aDouble, 2*aDouble;
return res;
}
};
DYNAMICGRAPH_FACTORY_ENTITY_PLUGIN(MyEntity, "MyEntity");
} // namespace dynamicgraph
BOOST_AUTO_TEST_CASE(test_tracer) {
using dynamicgraph::Vector;
// Creates a tracer.
dynamicgraph::Tracer &atracer = *dynamic_cast<dynamicgraph::Tracer *>(
dynamicgraph::FactoryStorage::getInstance()->newEntity("Tracer",
......@@ -75,6 +88,8 @@ BOOST_AUTO_TEST_CASE(test_tracer) {
/// Add trace by name
atracer.addSignalToTraceByName("my-entity.out_double", "output");
/// Add trace by name
atracer.addSignalToTraceByName("my-entity.out_vector", "output-vector");
dynamicgraph::SignalBase<int> &aSignal = entity.getSignal("out2double");
......@@ -82,6 +97,10 @@ BOOST_AUTO_TEST_CASE(test_tracer) {
*(dynamic_cast<dynamicgraph::Signal<double, int> *>(
&entity.getSignal("in_double")));
dynamicgraph::Signal<Vector, int> &aSignalVector =
*(dynamic_cast<dynamicgraph::Signal<Vector, int> *>(
&entity.getSignal("out_vector")));
/// Add trace by signal object
atracer.addSignalToTrace(aSignal, "output2");
......@@ -91,7 +110,10 @@ BOOST_AUTO_TEST_CASE(test_tracer) {
for (int i = 0; i < 1000; i++) {
aSignal.setTime(i);
aSignalInt.access(i);
aSignalInt.setTime(i);
aSignalVector.recompute(i);
aSignalVector.setTime(i);
atracer.recordTrigger(i, i);
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment