13 #include <dynamic-graph/factory.h> 16 #include <boost/function.hpp> 17 #include <boost/numeric/conversion/cast.hpp> 26 #include "../tools/type-name-helper.hh" 28 namespace dg = ::dynamicgraph;
34 #define ADD_COMMAND(name, def) commandMap.insert(std::make_pair(name, def)) 38 template <
typename TypeIn,
typename TypeOut>
51 "Undocumented unary operator\n" 68 for (std::size_t
i = 0;
i < idxs.size(); ++
i) {
71 assert((nr >= 0) && (R + nr <= m.size()));
72 res.segment(r, nr) = m.segment(R, nr);
78 typedef std::pair<Vector::Index, Vector::Index>
segment_t;
84 idxs = segments_t(1, segment_t(m, M - m));
88 idxs.push_back(segment_t(m, M - m));
97 boost::function<void(const int &, const int &)> setBound =
99 doc =
docCommandVoid2(
"Set the bound of the selection [m,M[.",
"int (min)",
102 boost::function<void(const int &, const int &)> addBound =
104 doc =
docCommandVoid2(
"Add a segment to be selected [m,M[.",
"int (min)",
114 assert(
index < m.size());
125 boost::function<void(const int &)>
callback =
132 std::string docString(
133 "Select a component of a vector\n" 143 assert((imin <= imax) && (imax <= m.rows()));
144 assert((jmin <= jmax) && (jmax <= m.cols()));
145 res.resize(imax - imin, jmax - jmin);
146 for (
int i = imin;
i < imax; ++
i)
147 for (
int j = jmin; j < jmax; ++j) res(
i - imin, j - jmin) = m(
i, j);
168 boost::function<void(const int &, const int &)> setBoundsRow =
170 boost::function<void(const int &, const int &)> setBoundsCol =
173 doc =
docCommandVoid2(
"Set the bound on rows.",
"int (min)",
"int (max)");
186 assert((imin <= imax) && (imax <= m.rows()));
187 assert(jcol < m.cols());
189 res.resize(imax - imin);
190 for (
int i = imin;
i < imax; ++
i) res(
i - imin) = m(
i, jcol);
206 boost::function<void(const int &, const int &)> setBoundsRow =
208 boost::function<void(const int &)> selectCol =
211 doc =
docCommandVoid2(
"Set the bound on rows.",
"int (min)",
"int (max)");
227 res = r.asDiagonal();
242 boost::function<void(const int &, const int &)> resize =
254 template <
typename matrixgen>
258 inline void operator()(
const Tin &m, Tout &res)
const { res = m.inverse(); }
267 std::string docString(
268 "Computes the norm of a vector\n" 293 res.head<3>() = M.translation();
294 res.tail<3>() =
r.angle() *
r.axis();
310 assert(v.size() >= 6);
311 res.translation() = v.head<3>();
312 double theta = v.tail<3>().norm();
314 res.linear() = Eigen::AngleAxisd(theta, v.tail<3>() / theta).matrix();
316 res.linear().setIdentity();
323 Mres.translation() = vect.head<3>();
324 Mres.linear().row(0) = vect.segment(3, 3);
325 Mres.linear().row(1) = vect.segment(6, 3);
326 Mres.linear().row(2) = vect.segment(9, 3);
334 res.head<3>() = M.translation();
335 res.segment(3, 3) = M.linear().row(0);
336 res.segment(6, 3) = M.linear().row(1);
337 res.segment(9, 3) = M.linear().row(2);
344 Mres.translation() = vect.head<3>();
353 res.head<3>() = M.translation();
354 Eigen::Map<VectorQuaternion>
q(res.tail<4>().data());
366 for (
unsigned int i = 0;
i < 3; ++
i) res(
i) =
t(
i);
367 for (
unsigned int i = 0;
i < 3; ++
i) res(
i + 3) =
r(
i);
375 for (
unsigned int i = 0;
i < 3; ++
i)
r(
i) = vect(
i + 3);
377 Eigen::AngleAxisd(
r(1), Eigen::Vector3d::UnitY()) *
378 Eigen::AngleAxisd(
r(0), Eigen::Vector3d::UnitX()))
382 for (
unsigned int i = 0;
i < 3; ++
i)
t(
i) = vect(
i);
385 Mres = Eigen::Translation3d(t) * R;
392 for (
unsigned int i = 0;
i < 3; ++
i)
r(
i) = vect(
i + 3);
394 Eigen::AngleAxisd(
r(1), Eigen::Vector3d::UnitY()) *
395 Eigen::AngleAxisd(
r(0), Eigen::Vector3d::UnitX()))
401 for (
unsigned int i = 0;
i < 3; ++
i) {
402 vectres(
i) = vect(
i);
403 vectres(
i + 3) = rrot.angle() * rrot.axis()(
i);
423 Eigen::Vector3d _t = M.translation();
426 Tx << 0, -_t(2), _t(1), _t(2), 0, -_t(0), -_t(1), _t(0), 0;
430 res.block<3, 3>(0, 0) = R;
431 res.block<3, 3>(0, 3) = sk;
432 res.block<3, 3>(3, 0) = Eigen::Matrix3d::Zero();
433 res.block<3, 3>(3, 3) = R;
447 res = M.translation();
453 res = (Eigen::AngleAxisd(
r(2), Eigen::Vector3d::UnitZ()) *
454 Eigen::AngleAxisd(
r(1), Eigen::Vector3d::UnitY()) *
455 Eigen::AngleAxisd(
r(0), Eigen::Vector3d::UnitX()))
462 res = (r.eulerAngles(2, 1, 0)).reverse();
467 :
public UnaryOpHeader<VectorRollPitchYaw, VectorQuaternion> {
469 res = (Eigen::AngleAxisd(
r(2), Eigen::Vector3d::UnitZ()) *
470 Eigen::AngleAxisd(
r(1), Eigen::Vector3d::UnitY()) *
471 Eigen::AngleAxisd(
r(0), Eigen::Vector3d::UnitX()))
477 :
public UnaryOpHeader<VectorQuaternion, VectorRollPitchYaw> {
479 res = (r.toRotationMatrix().eulerAngles(2, 1, 0)).reverse();
486 res = r.toRotationMatrix();
510 template <
typename TypeIn1,
typename TypeIn2,
typename TypeOut>
527 "Undocumented binary operator\n" 553 template <
typename F,
typename E>
555 inline void operator()(
const F &
f,
const E &e, E &res)
const { res = f * e; }
563 res = f.matrix() * e;
584 template <
typename T>
594 :
public BinaryOpHeader<dynamicgraph::Vector, dynamicgraph::Vector,
595 dynamicgraph::Vector> {
602 assert((v1max >= v1min) && (v1.size() >= v1max));
603 assert((v2max >= v2min) && (v2.size() >= v2max));
605 const int v1size = v1max - v1min, v2size = v2max - v2min;
606 res.resize(v1size + v2size);
607 for (
int i = 0;
i < v1size; ++
i) {
608 res(
i) = v1(
i + v1min);
610 for (
int i = 0;
i < v2size; ++
i) {
611 res(v1size +
i) = v2(
i + v2min);
615 inline void selec1(
const int &m,
const int M) {
619 inline void selec2(
const int &m,
const int M) {
629 boost::function<void(const int &, const int &)> selec1 =
631 boost::function<void(const int &, const int &)> selec2 =
638 "int (imin)",
"int (imax)")));
643 "int (imin)",
"int (imax)")));
650 :
public BinaryOpHeader<dynamicgraph::Matrix, dynamicgraph::Vector,
662 :
public BinaryOpHeader<dynamicgraph::Vector, dynamicgraph::Matrix,
663 dynamicgraph::Vector> {
670 sotDEBUG(15) <<
"Size: " << nconv <<
"x" << nsig << std::endl;
671 if (nconv > f2.cols())
return;
676 for (MemoryType::const_iterator iter = f1.begin(); iter != f1.end();
679 sotDEBUG(45) <<
"Sig" << j <<
": " << s_tau;
680 if (s_tau.size() != nsig)
return;
681 for (
int i = 0;
i < nsig; ++
i) {
682 res(
i) += f2(
i, j) * s_tau(
i);
690 memory.push_front(v1);
691 while ((
Vector::Index)memory.size() > m2.cols()) memory.pop_back();
692 convolution(memory, m2, res);
698 template <
typename T>
706 "Comparison of inputs:\n" 708 Base::nameTypeIn1() +
712 Base::nameTypeIn2() +
716 Base::nameTypeOut() +
719 " sout = ( sin1 < sin2 )\n");
723 template <
typename T1,
typename T2 = T1>
728 res = (a.array() <= b.array()).any();
729 else if (equal && !any)
730 res = (a.array() <= b.array()).all();
731 else if (!equal && any)
732 res = (a.array() < b.array()).any();
733 else if (!equal && !any)
734 res = (a.array() < b.array()).all();
739 "Comparison of inputs:\n" 741 Base::nameTypeIn1() +
745 Base::nameTypeIn2() +
749 Base::nameTypeOut() +
752 " sout = ( sin1 < sin2 ).op()\n") +
755 " where op is either any (default) or all. The " 756 "comparison can be made <=.\n");
782 template <
typename T>
786 inline void operator()(
const T &v1,
const T &v2, T &res)
const {
812 return std::string(
"Weighted Combination of inputs : \n - gain{1|2} gain.");
821 template <
typename Tin,
typename Tout,
typename Time>
825 template <
typename Tin,
typename Tout,
typename Time>
830 template <
typename TypeIn,
typename TypeOut>
840 template <
typename Op>
845 "Undocumented variadic operator\n" 862 : index(i), size(s), sigIdx(sig) {}
867 inline void operator()(
const std::vector<const Vector *> &vs,
870 for (std::size_t
i = 0;
i < idxs.size(); ++
i) {
872 if (s.
sigIdx >= vs.size())
873 throw std::invalid_argument(
"Index out of range in VectorMix");
878 inline void addSelec(
const int &sigIdx,
const int &i,
const int &s) {
888 boost::function<void(const int &, const int &, const int &)> selec =
891 commandMap.insert(std::make_pair(
892 "addSelec", makeCommandVoid3<Base, int, int, int>(
895 "int (signal index >= 1)",
896 "int (index)",
"int (size)"))));
901 template <
typename T>
909 inline void operator()(
const std::vector<const T *> &vs, T &res)
const {
910 assert(vs.size() == (std::size_t)coeffs.size());
911 if (vs.size() == 0)
return;
912 res = coeffs[0] * (*vs[0]);
913 for (std::size_t
i = 1;
i < vs.size(); ++
i) res += coeffs[
i] * (*vs[
i]);
918 throw std::invalid_argument(
"Invalid coefficient size.");
929 return "Linear combination of inputs\n" 936 " sout = sum ([coeffs[i] * sin[i] for i in range(n) ])\n" 937 " Coefficients are set by commands, default value is 1.\n";
942 template <
typename T>
946 inline void operator()(
const std::vector<const T *> &vs, T &res)
const {
951 for (std::size_t
i = 1;
i < vs.size(); ++
i) res *= *vs[
i];
967 const std::vector<const MatrixHomogeneous *> &vs,
973 for (std::size_t
i = 1;
i < vs.size(); ++
i) res = res * *vs[
i];
978 const std::vector<const Vector *> &vs,
Vector &res)
const {
983 for (std::size_t
i = 1;
i < vs.size(); ++
i) res.array() *= vs[
i]->array();
988 template <
int operation>
992 inline void operator()(
const std::vector<const bool *> &vs,
bool &res)
const {
996 if (vs.size() == 0)
return;
998 for (std::size_t
i = 1;
i < vs.size(); ++
i)
switch (operation) {
VariadicOp< AdderVariadic > Base
void operator()(const dynamicgraph::Vector &v1, const dynamicgraph::Vector &v2, dynamicgraph::Vector &res) const
void setCoeffs(const Vector &c)
void addSpecificCommands(Entity &ent, Entity::CommandMap_t &commandMap)
Eigen::Transform< double, 3, Eigen::Affine > SOT_CORE_EXPORT MatrixHomogeneous
std::string docDirectGetter(const std::string &name, const std::string &type)
void setSignalNumber(const int &n)
void operator()(const dynamicgraph::Vector &v1, const dynamicgraph::Matrix &m2, dynamicgraph::Vector &res)
void operator()(const T &v1, const T &v2, T &res) const
void resize(const int &r, const int &c)
DirectGetter< E, T > * makeDirectGetter(E &entity, T *ptr, const std::string &docString)
void operator()(const Tin &m, Tout &res) const
Eigen::Quaternion< double > SOT_CORE_EXPORT VectorQuaternion
void setIndex(const int &m)
void operator()(const std::vector< const Vector *> &vs, Vector &res) const
void operator()(const std::vector< const T *> &vs, T &res) const
void setBoundsCol(const int &m, const int &M)
void operator()(const T &a, const T &b, bool &res) const
std::string getDocString() const
std::pair< Vector::Index, Vector::Index > segment_t
void setIdentity(T &res) const
Multiplier_FxE__E< MatrixTwist, dynamicgraph::Vector > Multiplier_matrixTwist_vector
void operator()(const MatrixRotation &r, VectorRollPitchYaw &res)
void operator()(const dg::Vector &m, double &res) const
std::deque< dynamicgraph::Vector > MemoryType
VariadicOp< BoolOp > Base
Signal< dynamicgraph::Matrix, int > sig("matrix")
void operator()(const dg::Vector &vect, dg::Vector &vectres)
void operator()(const std::vector< const T *> &vs, T &res) const
void operator()(const Tin &m, Vector &res) const
std::string getDocString() const
Multiplier_FxE__E< double, dynamicgraph::Vector > Multiplier_double_vector
void operator()(const Eigen::Matrix< double, 4, 4 > &M, MatrixHomogeneous &res)
void operator()(const VectorQuaternion &r, MatrixRotation &res)
void operator()(const T &v1, const T &v2, T &r) const
CommandVoid1< E, T > * makeCommandVoid1(E &entity, boost::function< void(const T &)> function, const std::string &docString)
Multiplier_FxE__E< MatrixHomogeneous, dynamicgraph::Vector > Multiplier_matrixHomo_vector
void operator()(const MatrixHomogeneous &M, Vector &res)
void convolution(const MemoryType &f1, const dynamicgraph::Matrix &f2, dynamicgraph::Vector &res)
void initialize(Base *ent, Entity::CommandMap_t &)
void addBounds(const int &m, const int &M)
void initialize(Base *ent, Entity::CommandMap_t &commandMap)
std::string docCommandVoid1(const std::string &doc, const std::string &type)
void updateSignalNumber(const int &n)
void setBoundsRow(const int &m, const int &M)
void operator()(const dg::Vector &r, dg::Matrix &res)
void operator()(const MatrixHomogeneous &M, Vector &res)
void operator()(const Tin &m, Tout &res) const
Eigen::Vector3d SOT_CORE_EXPORT VectorRollPitchYaw
void initialize(Base *ent, Entity::CommandMap_t &)
std::string getDocString() const
void operator()(const Tin &m, double &res) const
std::string docCommandVoid3(const std::string &doc, const std::string &type1, const std::string &type2, const std::string &type3)
void operator()(const Matrix &M, Vector &res)
void addSpecificCommands(Entity &ent, Entity::CommandMap_t &commandMap)
static std::string getTypeOutName(void)
UnaryOpHeader< matrixgen, matrixgen >::Tout Tout
void operator()(const std::vector< const bool *> &vs, bool &res) const
std::string getDocString() const
void operator()(const dg::Vector &vect, MatrixHomogeneous &Mres)
Eigen::AngleAxis< double > SOT_CORE_EXPORT VectorUTheta
void operator()(const dg::Vector &vect, MatrixHomogeneous &Mres)
Eigen::Matrix< double, 6, 6 > SOT_CORE_EXPORT MatrixTwist
void operator()(const VectorQuaternion &r, VectorRollPitchYaw &res)
void operator()(const MatrixRotation &r, VectorUTheta &res)
void operator()(const VectorUTheta &r, VectorQuaternion &res)
void operator()(const VectorRollPitchYaw &r, VectorQuaternion &res)
void operator()(const dg::Vector &v, MatrixHomogeneous &res)
void selectCol(const int &m)
VariadicOp< VectorMix > Base
void operator()(const Tin &m, Tout &res) const
std::map< const std::string, command::Command *> CommandMap_t
VariadicOp< Multiplier > Base
std::vector< segment_t > segments_t
void addSpecificCommands(Entity &ent, Entity::CommandMap_t &commandMap)
void setBounds(const int &m, const int &M)
void addSpecificCommands(Entity &ent, Entity::CommandMap_t &commandMap)
std::string getDocString() const
void operator()(const MatrixHomogeneous &M, MatrixTwist &res)
void operator()(const MatrixHomogeneous &M, MatrixRotation &res)
void operator()(const Matrix &m, Matrix &res) const
UnaryOpHeader< matrixgen, matrixgen >::Tin Tin
Eigen::Matrix< double, 3, 3 > SOT_CORE_EXPORT MatrixRotation
void addSelec(const int &sigIdx, const int &i, const int &s)
void operator()(const dg::Vector &vect, MatrixHomogeneous &Mres)
std::string getDocString() const
void operator()(const MatrixRotation &r, VectorQuaternion &res)
void operator()(const MatrixHomogeneous &M, dg::Vector &res)
void operator()(const VectorRollPitchYaw &r, MatrixRotation &res)
void addSpecificCommands(Entity &ent, Entity::CommandMap_t &commandMap)
std::string docCommandVoid2(const std::string &doc, const std::string &type1, const std::string &type2)
void operator()(const Tin &m, Tout &res) const
void toRotationMatrix(const Eigen::MatrixBase< Vector3 > &axis, const Scalar &cos_value, const Scalar &sin_value, const Eigen::MatrixBase< Matrix3 > &res)
void operator()(const MatrixHomogeneous &M, dg::Vector &res)
void operator()(const T1 &a, const T2 &b, bool &res) const
void operator()(const Tin &m, Tout &res) const
void addSpecificCommands(Entity &ent, Entity::CommandMap_t &commandMap)
void operator()(const dynamicgraph::Matrix &R, const dynamicgraph::Vector &t, MatrixHomogeneous &H) const
void operator()(const F &f, const E &e, E &res) const
void operator()(const MatrixHomogeneous &M, dg::Matrix &res)
Multiplier_FxE__E< dynamicgraph::Matrix, dynamicgraph::Vector > Multiplier_matrix_vector
std::vector< segment_t > segments_t
std::string docDirectSetter(const std::string &name, const std::string &type)
#define ADD_COMMAND(name, def)
void addSpecificCommands(Entity &ent, Entity::CommandMap_t &commandMap)
static std::string typeName()
void setBoundsRow(const int &m, const int &M)
void operator()(const MatrixHomogeneous &M, dg::Vector &res)
void selec2(const int &m, const int M)
DirectSetter< E, T > * makeDirectSetter(E &entity, T *ptr, const std::string &docString)
int getSignalNumber() const
segment_t(Vector::Index i, Vector::Index s, std::size_t sig)
CommandVoid2< E, T1, T2 > * makeCommandVoid2(E &entity, boost::function< void(const T1 &, const T2 &)> function, const std::string &docString)
static std::string getTypeInName(void)
void addSpecificCommands(Entity &ent, Entity::CommandMap_t &commandMap)
void selec1(const int &m, const int M)