handle.cpp
Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2008, AIST, the University of Tokyo and General Robotix Inc.
00003  * All rights reserved. This program is made available under the terms of the
00004  * Eclipse Public License v1.0 which accompanies this distribution, and is
00005  * available at http://www.eclipse.org/legal/epl-v10.html
00006  * Contributors:
00007  * The University of Tokyo
00008  */
00009 /*
00010  * handle.cpp
00011  * Create: Katsu Yamane, 03.07.10
00012  */
00013 
00014 #include "ik.h"
00015 
00016 int IKHandle::calc_jacobian()
00017 {
00018         int i, j, count = 0;
00019         int n_dof = ik->NumDOF();
00020         static fMat Jtemp;
00021         J.resize(n_const, n_dof);
00022         Jtemp.resize(6, n_dof);
00023         Jtemp.zero();
00024         joint->CalcJacobian(Jtemp);
00025         // compute other_joint's Jacobian and transform to other_joint's
00026         // local frame
00027         if(other_joint)
00028         {
00029                 static fMat Jtemp_other;
00030                 Jtemp_other.resize(6, ik->NumDOF());
00031                 Jtemp_other.zero();
00032                 other_joint->CalcJacobian(Jtemp_other);
00033                 fMat33& abs_att = other_joint->abs_att;
00034                 for(i=0; i<n_dof; i++)
00035                 {
00036                         double* a = Jtemp.data() + 6*i;
00037                         double* b = Jtemp_other.data() + 6*i;
00038                         double m0 = *a - *b;
00039                         double m1 = *(a+1) - *(b+1);
00040                         double m2 = *(a+2) - *(b+2);
00041                         double m3 = *(a+3) - *(b+3);
00042                         double m4 = *(a+4) - *(b+4);
00043                         double m5 = *(a+5) - *(b+5);
00044                         *a = abs_att(0,0)*m0 + abs_att(1,0)*m1 + abs_att(2,0)*m2;
00045                         *(a+1) = abs_att(0,1)*m0 + abs_att(1,1)*m1 + abs_att(2,1)*m2;
00046                         *(a+2) = abs_att(0,2)*m0 + abs_att(1,2)*m1 + abs_att(2,2)*m2;
00047                         *(a+3) = abs_att(0,0)*m3 + abs_att(1,0)*m4 + abs_att(2,0)*m5;
00048                         *(a+4) = abs_att(0,1)*m3 + abs_att(1,1)*m4 + abs_att(2,1)*m5;
00049                         *(a+5) = abs_att(0,2)*m3 + abs_att(1,2)*m4 + abs_att(2,2)*m5;
00050                 }
00051         }
00052         // copy to J
00053         for(i=0; i<6; i++)
00054         {
00055                 if(const_index[i] == IK::HAVE_CONSTRAINT)
00056                 {
00057                         int a_row = J.row();
00058                         double* a = J.data() + count;
00059                         int b_row = Jtemp.row();
00060                         double* b = Jtemp.data() + i;
00061                         for(j=0; j<n_dof; a+=a_row, b+=b_row, j++)
00062                         {
00063 //                              J(count, j) = Jtemp(i, j);
00064                                 *a = *b;
00065                         }
00066                         count++;
00067                 }
00068         }
00069         return 0;
00070 }
00071 
00072 int IKHandle::calc_feedback()
00073 {
00074         // compute feedback velocity
00075         if(n_const > 0)
00076         {
00077                 static fVec3 fb_pos, fb_att;
00078                 static fVec3 cur_pos;
00079                 static fMat33 cur_att;
00080                 // absolute position / orientation
00081                 cur_att.mul(joint->abs_att, rel_att);
00082                 cur_pos.mul(joint->abs_att, rel_pos);
00083                 cur_pos += joint->abs_pos;
00084                 // relative position / orientation wrt other_joint
00085                 if(other_joint)
00086                 {
00087                         static fVec3 pp;
00088                         static fMat33 rt, catt;
00089                         rt.tran(other_joint->abs_att);
00090                         catt.set(cur_att);
00091                         pp.sub(cur_pos, other_joint->abs_pos);
00092                         cur_pos.mul(rt, pp);
00093                         cur_att.mul(rt, catt);
00094                 }
00095                 fb_pos.sub(abs_pos, cur_pos);
00096                 fb_pos *= gain;
00097                 fb_att.rotation(abs_att, cur_att);
00098                 fb_att *= gain;
00099                 int i, count = 0;
00100                 for(i=0; i<3; i++)
00101                 {
00102                         if(const_index[i] == IK::HAVE_CONSTRAINT)
00103                         {
00104                                 fb(count) = fb_pos(i);
00105                                 count++;
00106                         }
00107                 }
00108                 for(i=0; i<3; i++)
00109                 {
00110                         if(const_index[i+3] == IK::HAVE_CONSTRAINT)
00111                         {
00112                                 fb(count) = fb_att(i);
00113                                 count++;
00114                         }
00115                 }
00116         }
00117         return 0;
00118 }


openhrp3
Author(s): AIST, General Robotix Inc., Nakamura Lab of Dept. of Mechano Informatics at University of Tokyo
autogenerated on Thu Apr 11 2019 03:30:16