30 const double KatanaKinematics6M90G::_tolerance = 0.001;
31 const int KatanaKinematics6M90G::_nrOfPossibleSolutions = 8;
38 double x0, x1, x2, x3;
39 double y0, y1, y2, y3;
40 double z0, z1, z2, z3;
41 double R13, R23, R33, R31, R32;
44 for(
int z = 0; z < 6; ++z) {
45 current_angles[z] =
enc2rad(current_encoders[z], _parameters[z].angleOffset, _parameters[z].epc, _parameters[z].encOffset, _parameters[z].rotDir);
55 current_angles[1] = current_angles[1] -
M_PI/2.0;
56 current_angles[2] = current_angles[2] -
M_PI;
57 current_angles[3] = M_PI - current_angles[3];
61 angles cx(current_angles.size()), sx(current_angles.size());
62 angles::iterator cx_iter, sx_iter;
66 angle[2] = angle[1]+angle[2];
67 angle[3] = angle[2]+angle[3];
74 R13 = (-1*cx[0]*cx[3]*cx[4])-(sx[0]*sx[4]);
75 R23 = (-1*sx[0]*cx[3]*cx[4])+(cx[0]*sx[4]);
78 R32 =(-1)*sx[3]*sx[4];
84 x3 = -cx[0]*cx[3]*cx[4]-sx[0]*sx[4];
85 pose[0] = x0*_length[0]+x1*_length[1]+x2*_length[2]+x3*_length[3];
91 y3 = -sx[0]*cx[3]*cx[4]+cx[0]*sx[4];
92 pose[1] = y0*_length[0]+y1*_length[1]+y2*_length[2]+y3*_length[3];
99 pose[2] = z0*_length[0]+z1*_length[1]+z2*_length[2]+z3*_length[3];
104 pose[3] = atan2(pose[1],pose[0]);
106 }
else if(pose[4]==M_PI) {
107 pose[3] = atan2(pose[1],pose[0])+M_PI/2;
110 pose[3] = atan2(R13,-R23);
111 pose[5] = atan2(R31,R32);
120 assert( (length.size() == 4) &&
"You have to provide the metrics for exactly 4 links" );
121 assert( (parameters.size() == 6) &&
"You have to provide exactly 5 motor parameters" );
122 _setLength( length );
123 _setParameters ( parameters );
132 sqrt( ( -
pow2(p_gr.
z) ) *
146 griptest = GripperTest(p_gr, angle);
149 griptest=GripperTest(p_gr, angle);
152 sqrt( ( -
pow2(p_gr.
z) ) *
163 griptest=GripperTest(p_gr, angle);
175 double xgr2, ygr2, zgr2;
181 if((
pow2(p_gr.
x-xgr2)+
pow2(p_gr.
y-ygr2)+
pow2(p_gr.
z-zgr2))>=_tolerance)
192 double d5 = _length[2] + _length[3];
195 zg = p.
z + ( _length[3] * cos(angle.
theta234) );
211 if(!PositionTest6MS(angle,p_m)) {
221 double temp, xm2, ym2, zm2;
244 if(a.
theta1>_parameters[0].angleStop) {
250 if(a.
theta5<_parameters[4].angleOffset) {
254 return AnglePositionTest(a);
261 if( (a.
theta1+0.0087<_parameters[0].angleOffset)||(a.
theta1>_parameters[0].angleStop) )
264 if( (a.
theta2-0.0087>_parameters[1].angleOffset)||(a.
theta2<_parameters[1].angleStop) )
267 if( (a.
theta3<_parameters[2].angleOffset)||(a.
theta3>_parameters[2].angleStop) )
270 if( (a.
theta4<_parameters[3].angleOffset)||(a.
theta4>_parameters[3].angleStop) )
273 if( (a.
theta5<_parameters[4].angleOffset)||(a.
theta5>_parameters[4].angleStop) )
297 p_gr.
x = _length[3]*sin(pose[4])*sin(pose[3]);
298 p_gr.
y = -_length[3]*sin(pose[4])*cos(pose[3]);
299 p_gr.
z = _length[3]*cos(pose[4]);
301 p_m.
x = pose[0]-p_gr.
x;
302 p_m.
y = pose[1]-p_gr.
y;
303 p_m.
z = pose[2]-p_gr.
z;
306 angle[0].theta1 =
atan1(p_m.
x,p_m.
y);
307 angle[4].theta1 = angle[0].theta1+
M_PI;
311 if(angle[0].theta1>_parameters[0].angleStop)
312 angle[0].theta1=angle[0].theta1-2.0*
M_PI;
314 if(angle[0].theta1<_parameters[0].angleOffset)
315 angle[0].theta1=angle[0].theta1+2.0*
M_PI;
317 if(angle[4].theta1>_parameters[0].angleStop)
318 angle[4].theta1=angle[4].theta1-2.0*
M_PI;
320 if(angle[4].theta1<_parameters[0].angleOffset)
321 angle[4].theta1=angle[4].theta1+2.0*
M_PI;
326 IK_theta234theta5(angle[0], p_gr);
327 IK_b1b2costh3_6MS(angle[0], p_m);
330 angle[0].theta3 = acos(angle[0].costh3)-
M_PI;
331 thetacomp(angle[0], p_m);
332 angle[1].theta3 = -acos(angle[1].costh3)+
M_PI;
333 thetacomp(angle[1], p_m);
336 angle[2].theta1=angle[0].theta1;
337 angle[2].theta234=angle[0].theta234-
M_PI;
338 angle[2].theta5=
M_PI-angle[0].theta5;
340 IK_b1b2costh3_6MS(angle[2], p_m);
342 angle[2].theta3 = acos(angle[2].costh3)-
M_PI;
343 thetacomp(angle[2], p_m);
344 angle[3].theta3 = -acos(angle[3].costh3)+
M_PI;
345 thetacomp(angle[3], p_m);
350 IK_theta234theta5(angle[4], p_gr);
351 IK_b1b2costh3_6MS(angle[4], p_m);
354 angle[4].theta3 = acos(angle[4].costh3)-
M_PI;
355 thetacomp(angle[4], p_m);
356 angle[5].theta3 = -acos(angle[5].costh3)+
M_PI;
357 thetacomp(angle[5], p_m);
360 angle[6].theta1=angle[4].theta1;
361 angle[6].theta234=angle[4].theta234-
M_PI;
362 angle[6].theta5=
M_PI-angle[4].theta5;
363 IK_b1b2costh3_6MS(angle[6], p_m);
365 angle[6].theta3 = acos(angle[6].costh3)-
M_PI;
366 thetacomp(angle[6], p_m);
367 angle[7].theta3 = -acos(angle[7].costh3)+
M_PI;
368 thetacomp(angle[7], p_m);
370 for( ::std::vector<angles_calc>::iterator iter = angle.begin(); iter != angle.end(); ) {
371 if(
pow2(iter->costh3) <= 1.0) {
373 iter = angle.erase(iter);
378 iter = angle.erase(iter);
382 if(angle.size() == 0) {
386 ::std::vector< ::std::vector<int> > PossibleTargetsInEncoders;
387 for( ::std::vector<angles_calc>::iterator i = angle.begin(); i != angle.end(); ++i ) {
388 ::std::vector<int> solution(5);
390 solution[0] =
rad2enc(i->theta1, _parameters[0].angleOffset, _parameters[0].epc, _parameters[0].encOffset, _parameters[0].rotDir);
391 solution[1] =
rad2enc(i->theta2, _parameters[1].angleOffset, _parameters[1].epc, _parameters[1].encOffset, _parameters[1].rotDir);
392 solution[2] =
rad2enc(i->theta3, _parameters[2].angleOffset, _parameters[2].epc, _parameters[2].encOffset, _parameters[2].rotDir);
393 solution[3] =
rad2enc(i->theta4, _parameters[3].angleOffset, _parameters[3].epc, _parameters[3].encOffset, _parameters[3].rotDir);
394 solution[4] =
rad2enc(i->theta5, _parameters[4].angleOffset, _parameters[4].epc, _parameters[4].encOffset, _parameters[4].rotDir);
396 PossibleTargetsInEncoders.push_back(solution);
400 ::std::vector< ::std::vector<int> >::const_iterator sol =
KinematicsDefaultEncMinAlgorithm()(PossibleTargetsInEncoders.begin(), PossibleTargetsInEncoders.end(), current_encoders.begin(), current_encoders.end());
402 assert( sol != PossibleTargetsInEncoders.end() &&
"All solutions are out of range");
405 encoders::iterator gripper_encoder_iter = std::copy( (*sol).begin(), (*sol).end(), solution );
406 *gripper_encoder_iter = current_encoders[5];
_encT rad2enc(_angleT const &angle, _angleT const &angleOffset, _encT const &epc, _encT const &encOffset, _encT const &rotDir)
std::vector< double > angles
Being used to store angles (in radian).
std::vector< angles_calc > angles_container
_T anglereduce(const _T a)
void swap(Matrix &A, Matrix &B)
std::vector< KinematicParameters > parameter_container
FloatVector FloatVector * a
_angleT enc2rad(_encT const &enc, _angleT const &angleOffset, _encT const &epc, _encT const &encOffset, _encT const &rotDir)
std::vector< double > coordinates
To store coordinates.
_T atan0(const _T in1, const _T in2)
std::vector< int > encoders
To store encoders.
std::vector< double > metrics
To store metrics, 'aka' the length's of the different segments of the robot.