$search
00001 import unittest 00002 from PyKDL import * 00003 from math import * 00004 00005 class FrameVelTestFunctions(unittest.TestCase): 00006 00007 def testVectorVel(self): 00008 v=VectorVel(Vector(3,-4,5),Vector(6,3,-5)) 00009 vt = Vector(-4,-6,-8); 00010 self.assert_(Equal( 2*v-v,v)) 00011 self.assert_(Equal( v*2-v,v)) 00012 self.assert_(Equal( v+v+v-2*v,v)) 00013 v2=VectorVel(v) 00014 self.assert_(Equal( v,v2)) 00015 v2+=v 00016 self.assert_(Equal( 2*v,v2)) 00017 v2-=v 00018 self.assert_(Equal( v,v2)) 00019 v2.ReverseSign() 00020 self.assert_(Equal( v,-v2)) 00021 self.assert_(Equal( v*vt,-vt*v)) 00022 v2 = VectorVel(Vector(-5,-6,-3),Vector(3,4,5)) 00023 self.assert_(Equal( v*v2,-v2*v)) 00024 00025 00026 def testRotationVel(self): 00027 v=VectorVel(Vector(9,4,-2),Vector(-5,6,-2)) 00028 vt=Vector(2,3,4) 00029 a= radians(-15) 00030 b= radians(20) 00031 c= radians(-80) 00032 R = RotationVel(Rotation.RPY(a,b,c),Vector(2,4,1)) 00033 R2=RotationVel(R) 00034 self.assert_(Equal(R,R2)) 00035 self.assert_(Equal((R*v).Norm(),(v.Norm()))) 00036 self.assert_(Equal(R.Inverse(R*v),v)) 00037 self.assert_(Equal(R*R.Inverse(v),v)) 00038 self.assert_(Equal(R*Rotation.Identity(),R)) 00039 self.assert_(Equal(Rotation.Identity()*R,R)) 00040 self.assert_(Equal(R*(R*(R*v)),(R*R*R)*v)) 00041 self.assert_(Equal(R*(R*(R*vt)),(R*R*R)*vt)) 00042 self.assert_(Equal(R*R.Inverse(),RotationVel.Identity())) 00043 self.assert_(Equal(R.Inverse()*R,RotationVel.Identity())) 00044 self.assert_(Equal(R.Inverse()*v,R.Inverse(v))) 00045 #v2=v*v-2*v 00046 #print dot(v2,v2) 00047 #self.assert_(Equal((v2).Norm(),sqrt(dot(v2,v2)))) 00048 00049 def testFrameVel(self): 00050 v=VectorVel(Vector(3,4,5),Vector(-2,-4,-1)) 00051 vt=Vector(-1,0,-10) 00052 F = FrameVel(Frame(Rotation.EulerZYX(radians(10),radians(20),radians(-10)),Vector(4,-2,1)), 00053 Twist(Vector(2,-2,-2),Vector(-5,-3,-2))) 00054 F2=FrameVel(F) 00055 self.assert_(Equal( F,F2)) 00056 self.assert_(Equal( F.Inverse(F*v),v)) 00057 self.assert_(Equal( F.Inverse(F*vt), vt)) 00058 self.assert_(Equal( F*F.Inverse(v),v)) 00059 self.assert_(Equal( F*F.Inverse(vt),vt)) 00060 self.assert_(Equal( F*Frame.Identity(),F)) 00061 self.assert_(Equal( Frame.Identity()*F,F)) 00062 self.assert_(Equal( F*(F*(F*v)),(F*F*F)*v)) 00063 self.assert_(Equal( F*(F*(F*vt)),(F*F*F)*vt)) 00064 self.assert_(Equal( F*F.Inverse(),FrameVel.Identity())) 00065 self.assert_(Equal( F.Inverse()*F,Frame.Identity())) 00066 self.assert_(Equal( F.Inverse()*vt,F.Inverse(vt))) 00067 00068 #void TestTwistVel() { 00069 # KDL_CTX; 00070 # // Twist 00071 # TwistVel t(VectorVel( 00072 # Vector(6,3,5), 00073 # Vector(1,4,2) 00074 # ),VectorVel( 00075 # Vector(4,-2,7), 00076 # Vector(-1,-2,-3) 00077 # ) 00078 # ); 00079 # TwistVel t2; 00080 # RotationVel R(Rotation::RPY(10*deg2rad,20*deg2rad,-15*deg2rad),Vector(-1,5,3)); 00081 # FrameVel F = FrameVel( 00082 # Frame( 00083 # Rotation::EulerZYX(-17*deg2rad,13*deg2rad,-16*deg2rad), 00084 # Vector(4,-2,1) 00085 # ), 00086 # Twist( 00087 # Vector(2,-2,-2), 00088 # Vector(-5,-3,-2) 00089 # ) 00090 # ); 00091 # 00092 # KDL_DIFF(2.0*t-t,t); 00093 # KDL_DIFF(t*2.0-t,t); 00094 # KDL_DIFF(t+t+t-2.0*t,t); 00095 # t2=t; 00096 # KDL_DIFF(t,t2); 00097 # t2+=t; 00098 # KDL_DIFF(2.0*t,t2); 00099 # t2-=t; 00100 # KDL_DIFF(t,t2); 00101 # t.ReverseSign(); 00102 # KDL_DIFF(t,-t2); 00103 # KDL_DIFF(R.Inverse(R*t),t); 00104 # KDL_DIFF(R*t,R*R.Inverse(R*t)); 00105 # KDL_DIFF(F.Inverse(F*t),t); 00106 # KDL_DIFF(F*t,F*F.Inverse(F*t)); 00107 # KDL_DIFF(doubleVel(3.14,2)*t,t*doubleVel(3.14,2)); 00108 # KDL_DIFF(t/doubleVel(3.14,2),t*(1.0/doubleVel(3.14,2))); 00109 # KDL_DIFF(t/3.14,t*(1.0/3.14)); 00110 # KDL_DIFF(-t,-1.0*t); 00111 # VectorVel p1(Vector(5,1,2),Vector(4,2,1)) ; 00112 # VectorVel p2(Vector(2,0,5),Vector(-2,7,-1)) ; 00113 # KDL_DIFF(t.RefPoint(p1+p2),t.RefPoint(p1).RefPoint(p2)); 00114 # KDL_DIFF(t,t.RefPoint(-p1).RefPoint(p1)); 00115 #} 00116 # 00117 #void TestTwistAcc() { 00118 # KDL_CTX; 00119 # // Twist 00120 # TwistAcc t( VectorAcc(Vector(6,3,5),Vector(1,4,2),Vector(5,2,1)), 00121 # VectorAcc(Vector(4,-2,7),Vector(-1,-2,-3),Vector(5,2,9) ) 00122 # ); 00123 # TwistAcc t2; 00124 # RotationAcc R(Rotation::RPY(10*deg2rad,20*deg2rad,-15*deg2rad), 00125 # Vector(-1,5,3), 00126 # Vector(2,1,3) 00127 # ) ; 00128 # FrameAcc F = FrameAcc( 00129 # Frame(Rotation::EulerZYX(-17*deg2rad,13*deg2rad,-16*deg2rad),Vector(4,-2,1)), 00130 # Twist(Vector(2,-2,-2),Vector(-5,-3,-2)), 00131 # Twist(Vector(5,4,-5),Vector(12,13,17)) 00132 # ); 00133 # 00134 # KDL_DIFF(2.0*t-t,t); 00135 # KDL_DIFF(t*2.0-t,t); 00136 # KDL_DIFF(t+t+t-2.0*t,t); 00137 # t2=t; 00138 # KDL_DIFF(t,t2); 00139 # t2+=t; 00140 # KDL_DIFF(2.0*t,t2); 00141 # t2-=t; 00142 # KDL_DIFF(t,t2); 00143 # t.ReverseSign(); 00144 # KDL_DIFF(t,-t2); 00145 # KDL_DIFF(R.Inverse(R*t),t); 00146 # KDL_DIFF(R*t,R*R.Inverse(R*t)); 00147 # KDL_DIFF(F.Inverse(F*t),t); 00148 # KDL_DIFF(F*t,F*F.Inverse(F*t)); 00149 # KDL_DIFF(doubleAcc(3.14,2,3)*t,t*doubleAcc(3.14,2,3)); 00150 # KDL_DIFF(t/doubleAcc(3.14,2,7),t*(1.0/doubleAcc(3.14,2,7))); 00151 # KDL_DIFF(t/3.14,t*(1.0/3.14)); 00152 # KDL_DIFF(-t,-1.0*t); 00153 # VectorAcc p1(Vector(5,1,2),Vector(4,2,1),Vector(2,1,3)); 00154 # VectorAcc p2(Vector(2,0,5),Vector(-2,7,-1),Vector(-3,2,-1)); 00155 # KDL_DIFF(t.RefPoint(p1+p2),t.RefPoint(p1).RefPoint(p2)); 00156 # KDL_DIFF(t,t.RefPoint(-p1).RefPoint(p1)); 00157 #} 00158 # 00159 00160 def suite(): 00161 suite=unittest.TestSuite() 00162 suite.addTest(FrameVelTestFunctions('testVectorVel')) 00163 suite.addTest(FrameVelTestFunctions('testRotationVel')) 00164 suite.addTest(FrameVelTestFunctions('testFrameVel')) 00165 return suite 00166 00167 #suite = suite() 00168 #unittest.TextTestRunner(verbosity=5).run(suite) 00169 00170 00171