00001
00002 #include "kuka361InvDynnf.hpp"
00003 #include <iostream>
00004
00005 #define FSIGN(a) ( a<-1E-15 ? -1.0 : ( a>1E-15 ? 1.0 : 0.0))
00006 #define SSIGN2(a,b) (2.0/(1.0+exp(-3*a/b))-1.0)
00007
00008
00009
00010 using namespace std;
00011
00012 #define Y_LS {29.0130, -10.9085, -0.2629, 2.6403, -0.0421, 0.0509, 3.0221, 2.4426, 0.0531, -0.2577, -0.2627, 346.7819, -0.2651, 35.4666, 5.6321, 0.9935, 3.2192, 10.7823, 34.2604, 16.9902, 39.1594, 5.4501, 16.1392, -12.7243, -6.1094, 1.9590}
00013 #define Y_LS2 {3.4102, 3.2555, 2.2401, 29.5178, 35.0201, 28.1370, 16.3857, 15.5666, 14.5318, -0.5734, -2.1976, 5.8708}
00014
00015 kuka361InvDynnf::kuka361InvDynnf(double dqm_):_tau(6),dqm(dqm_){
00016 D13 = 0.48;
00017 g1 = 9.81;
00018 double y_ls[26] = Y_LS;
00019 for(int i=0; i<26;i++){
00020 _y_ls[i]=y_ls[i];
00021 }
00022 r3 = 51.44118;
00023 l = 0.488;
00024 r = 0.1;
00025 double y_ls2[12] = Y_LS2;
00026 for(int i=0; i<12;i++){
00027 _y_ls2[i]=y_ls2[i];
00028 }
00029 }
00030
00031 vector<double> kuka361InvDynnf::invdyn361(vector<double> &q, vector<double> &dq, vector<double> &dq_des, vector<double> &ddq, vector<double> &torque_scale, vector<double> &torque_offset){
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055 t1 = dq[1] * dq[1];
00056 t3 = q[1] + q[2];
00057 t4 = sin(t3);
00058 t6 = _y_ls[7] * dq[0];
00059 t8 = cos(t3);
00060 t12 = dq[2] * t4;
00061 t16 = _y_ls[2] * dq[0];
00062 t17 = cos(q[1]);
00063 t18 = t17 * t17;
00064 t30 = _y_ls[5] * dq[0];
00065 t31 = t30 * dq[1];
00066 t32 = D13 * t17;
00067 t33 = t32 * t8;
00068 t36 = _y_ls[6] * dq[0];
00069 t37 = t36 * dq[1];
00070 t38 = sin(q[1]);
00071 t39 = D13 * t38;
00072 t40 = t39 * t8;
00073 t43 = t39 * t4;
00074 t49 = t32 * t4;
00075 t52 = _y_ls[8] * dq[0];
00076 t53 = t8 * t8;
00077 t57 = -_y_ls[10] * t1 * t4 + 0.4e1 * t6 * dq[1] * t4 * t8 + 0.4e1 * t6 * t12 * t8 - 0.4e1 * t16 * dq[1] * t18 + SSIGN2(dq_des[0],dqm) * _y_ls[18] + 0.2e1 * _y_ls[9] * dq[1] * dq[2] * t8 - 0.2e1 * _y_ls[10] * dq[1] * t12 - 0.2e1 * t31 * t33 + 0.2e1 * t37 * t40 + 0.2e1 * t31 * t43 + 0.2e1 * t30 * dq[2] * t43 + 0.2e1 * t37 * t49 + 0.4e1 * t52 * dq[1] * t53;
00078 t71 = dq[2] * dq[2];
00079 t87 = _y_ls[23] + 0.4e1 * t52 * dq[2] * t53 + dq[0] * _y_ls[17] + 0.2e1 * t36 * dq[2] * t40 - 0.2e1 * t52 * dq[2] + 0.2e1 * t16 * dq[1] - 0.2e1 * t52 * dq[1] - _y_ls[10] * t71 * t4 - _y_ls[4] * t1 * t17 + _y_ls[9] * t1 * t8 + _y_ls[9] * t71 * t8 - _y_ls[3] * t1 * t38 - 0.4e1 * _y_ls[1] * dq[0] * dq[1] * t17 * t38;
00080 tau1 = t57 + t87;
00081 t88 = l * l;
00082 t89 = r * r;
00083 t90 = l * r;
00084 t94 = sqrt(t88 + t89 - 0.2e1 * t90 * t17);
00085 t99 = dq[0] * dq[0];
00086 t105 = t99 * t4;
00087 t106 = t8 * _y_ls[7];
00088 t110 = _y_ls[5] * t94;
00089 t111 = t110 * t99;
00090 t114 = dq[2] * D13;
00091 t115 = cos(q[2]);
00092 t119 = g1 * t17;
00093 t122 = g1 * t38;
00094 t123 = sin(q[2]);
00095 t126 = _y_ls[6] * t94;
00096 t127 = t126 * t99;
00097 t134 = t71 * D13;
00098 t137 = -_y_ls[24] * t94 + 0.1000e4 * t90 * t38 * _y_ls[16] - 0.2e1 * t99 * t17 * t38 * _y_ls[1] * t94 + 0.2e1 * t105 * t106 * t94 + t111 * t43 - 0.2e1 * t110 * dq[1] * t114 * t115 - t110 * t119 * t115 + t110 * t122 * t123 + t127 * t49 + t127 * t40 + 0.2e1 * t126 * dq[1] * t114 * t123 + t126 * t134 * t123;
00099 t150 = t99 * _y_ls[2];
00100 t155 = t99 * _y_ls[8];
00101 t163 = t126 * t119 * t123 + t126 * t122 * t115 - t38 * _y_ls[11] * t94 - dq[1] * _y_ls[19] * t94 - SSIGN2(dq_des[1],dqm) * _y_ls[20] * t94 + t119 * _y_ls[12] * t94 + t150 * t94 - 0.2e1 * t150 * t94 * t18 - t155 * t94 + 0.2e1 * t155 * t94 * t53 - t111 * t33 - t110 * t134 * t115;
00102 tau2 = -(t137 + t163) / t94;
00103 tau3 = _y_ls[6] * t1 * D13 * t123 - _y_ls[5] * t1 * D13 * t115 + _y_ls[25] - _y_ls[6] * t99 * t40 - 0.2e1 * t105 * t106 - _y_ls[6] * g1 * t4 + _y_ls[5] * g1 * t8 + t155 - 0.2e1 * t155 * t53 + dq[2] * _y_ls[21] + SSIGN2(dq_des[2],dqm) * _y_ls[22] - _y_ls[5] * t99 * t43;
00104
00105 tau4 = (_y_ls2[1*3+0]*dq[3] + _y_ls2[2*3+0]*SSIGN2(dq_des[3],dqm) + _y_ls2[3*3+0]);
00106 tau5 = (_y_ls2[1*3+1]*dq[4] + _y_ls2[2*3+1]*SSIGN2(dq_des[4],dqm) + _y_ls2[3*3+1]);
00107 tau6 = (_y_ls2[1*3+2]*dq[5] + _y_ls2[2*3+2]*SSIGN2(dq_des[5],dqm) + _y_ls2[3*3+2]);
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119 mt1 = cos(q[1]);
00120 mt2 = mt1 * mt1;
00121 mt3 = sin(q[1]);
00122 mt4 = mt3 * mt3;
00123 mt10 = sin(q[2]);
00124 mt11 = D13 * mt10;
00125 mt12 = q[1] + q[2];
00126 mt13 = sin(mt12);
00127 mt14 = mt13 * mt13;
00128 mt15 = cos(mt12);
00129 mt16 = mt15 * mt15;
00130 mt17 = mt14 - mt16;
00131 mt19 = cos(q[2]);
00132 mt20 = D13 * mt19;
00133 mt21 = mt13 * mt15;
00134 M[0+0*6] = _y_ls[0] + (mt2 - mt4) * _y_ls[1] - 0.2e1 * mt1 * mt3 * _y_ls[2] + (mt11 - mt11 * mt17 - 0.2e1 * mt20 * mt21) * _y_ls[5] + (mt20 - 0.2e1 * mt11 * mt21 + mt20 * mt17) * _y_ls[6] + mt17 * _y_ls[7] + 0.2e1 * mt21 * _y_ls[8];
00135 mt36 = mt13 * _y_ls[9];
00136 mt37 = mt15 * _y_ls[10];
00137 M[0+1*6] = mt1 * _y_ls[3] - mt3 * _y_ls[4] + mt36 + mt37;
00138 M[0+2*6] = mt36 + mt37;
00139 M[1+0*6] = M[0+1*6];
00140 mt38 = mt11 * _y_ls[5];
00141 mt40 = mt20 * _y_ls[6];
00142 M[1+1*6] = 0.2e1 * mt38 + 0.2e1 * mt40 + _y_ls[13] + _y_ls[14] + _y_ls[15] / 0.1000e4;
00143 M[1+2*6] = mt38 + mt40 + _y_ls[14] + r3 * _y_ls[15] / 0.1000e4;
00144 M[2+0*6] = M[0+2*6];
00145 M[2+1*6] = M[1+2*6];
00146 mt45 = r3 * r3;
00147 M[2+2*6] = _y_ls[14] + mt45 * _y_ls[15] / 0.1000e4;
00148
00149 M[4+3*6] = 0.0;
00150 M[5+3*6] = 0.0;
00151 M[3+4*6] = 0.0;
00152 M[5+4*6] = 0.0;
00153 M[3+5*6] = 0.0;
00154 M[4+5*6] = 0.0;
00155 M[3+3*6] = _y_ls2[0*3+0];
00156 M[4+4*6] = _y_ls2[0*3+1];
00157 M[5+5*6] = _y_ls2[0*3+2];
00158
00159
00160 tauM[0] = M[0+0*6]*ddq[0]+M[0+1*6]*ddq[1]+M[0+2*6]*ddq[2];
00161 tauM[1] = M[1+0*6]*ddq[0]+M[1+1*6]*ddq[1]+M[1+2*6]*ddq[2];
00162 tauM[2] = M[2+0*6]*ddq[0]+M[2+1*6]*ddq[1]+M[2+2*6]*ddq[2];
00163 tauM[3] = M[3+3*6]*ddq[3];
00164 tauM[4] = M[4+4*6]*ddq[4];
00165 tauM[5] = M[5+5*6]*ddq[5];
00166
00167 _tau[0] = torque_scale[0]* (tauM[0] + tau1) + torque_offset[0];
00168 _tau[1] = torque_scale[1]* (tauM[1] + tau2) + torque_offset[1];
00169 _tau[2] = torque_scale[2]* (tauM[2] + tau3) + torque_offset[2];
00170 _tau[3] = torque_scale[3]* (tauM[3] + tau4) + torque_offset[3];
00171 _tau[4] = torque_scale[4]* (tauM[4] + tau5) + torque_offset[4];
00172 _tau[5] = torque_scale[5]* (tauM[5] + tau6) + torque_offset[5];
00173
00174 return _tau;
00175 }
00176
00177