Go to the documentation of this file.00001 #include "robodyn_controllers/KdlChainIdRne.h"
00002
00003 using namespace KDL;
00004
00012 KdlChainIdRne::KdlChainIdRne(const Chain& chain_, const Twist& v_base, const Twist& a_base):
00013 chain(chain_), nj(chain.getNrOfJoints()), ns(chain.getNrOfSegments()),
00014 X(ns), S(ns), v(ns), a(ns), Ii(ns), vb(v_base), ab(a_base)
00015 {
00016 }
00017
00027 int KdlChainIdRne::KinematicsPass(const JntArray& q, const JntArray& q_dot, const JntArray& q_dotdot, Twist& velOut, Twist& accelOut)
00028 {
00029
00030 if (q.rows() != nj || q_dot.rows() != nj || q_dotdot.rows() != nj )
00031 {
00032 return -1;
00033 }
00034
00035 unsigned int j = 0;
00036
00037
00038 for (unsigned int i = 0; i < ns; i++)
00039 {
00040 double q_, qdot_, qdotdot_;
00041
00042 if (chain.getSegment(i).getJoint().getType() != Joint::None)
00043 {
00044 q_ = q(j);
00045 qdot_ = q_dot(j);
00046 qdotdot_ = q_dotdot(j);
00047 j++;
00048 }
00049 else
00050 {
00051 q_ = qdot_ = qdotdot_ = 0.0;
00052 }
00053
00054
00055 X[i] = chain.getSegment(i).pose(q_);
00056
00057
00058
00059 Twist vj = X[i].M.Inverse(chain.getSegment(i).twist(q_, qdot_));
00060 S[i] = X[i].M.Inverse(chain.getSegment(i).twist(q_, 1.0));
00061
00062
00063
00064 if (i == 0)
00065 {
00066 v[i] = X[i].Inverse(vb) + vj;
00067 a[i] = X[i].Inverse(ab) + S[i] * qdotdot_ + v[i] * vj;
00068 }
00069 else
00070 {
00071 v[i] = X[i].Inverse(v[i - 1]) + vj;
00072 a[i] = X[i].Inverse(a[i - 1]) + S[i] * qdotdot_ + v[i] * vj;
00073 }
00074 }
00075
00076 if (ns > 0)
00077 {
00078 velOut = v[ns - 1];
00079 accelOut = a[ns - 1];
00080 }
00081
00082 return 0;
00083 }
00084
00095 int KdlChainIdRne::DynamicsPass(const Wrenches& forceExt, JntArray& torques, Wrench& forceBase, std::vector<KDL::Wrench>& f, const KDL::RigidBodyInertia& inertiaExt, const KDL::RigidBodyInertia& inertiaSeg, KDL::JntArray& Hv, KDL::RigidBodyInertia& inertiaBase)
00096 {
00097 if (torques.rows() != nj || forceExt.size() != ns || Hv.rows() != nj || f.size() != ns || ns == 0)
00098 {
00099 return -1;
00100 }
00101
00102 unsigned int j = 0;
00103
00104 for (unsigned int i = 0; i < ns; i++)
00105 {
00106
00107
00108 Ii[i] = chain.getSegment(i).getInertia();
00109 }
00110
00111 Ii[ns - 1] = Ii[ns - 1] + inertiaSeg;
00112
00113 for (unsigned int i = 0; i < ns; i++)
00114 {
00115 f[i] = Ii[i] * a[i] + v[i] * (Ii[i] * v[i]) + forceExt[i];
00116 }
00117
00118 Ii[ns - 1] = Ii[ns - 1] + inertiaExt;
00119
00120
00121 j = nj - 1;
00122
00123 for (int i = ns - 1; i >= 0; i--)
00124 {
00125
00126 if (i != 0)
00127 {
00128 f[i - 1] = f[i - 1] + X[i] * f[i];
00129 Ii[i - 1] = Ii[i - 1] + X[i] * Ii[i];
00130 }
00131
00132 Fis = Ii[i] * S[i];
00133
00134 if (chain.getSegment(i).getJoint().getType() != Joint::None)
00135 {
00136 Hv(j) = dot(S[i], Fis);
00137 torques(j--) = dot(S[i], f[i]);
00138 }
00139 }
00140
00141 forceBase = X[0] * f[0];
00142 inertiaBase = X[0] * Ii[0];
00143
00144 return 0;
00145 }