00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035 import roslib; roslib.load_manifest('calibration_estimation')
00036
00037 import sys
00038 import unittest
00039 import rospy
00040 import numpy
00041 import yaml
00042 from sensor_msgs.msg import JointState
00043 from calibration_estimation.full_chain import FullChainRobotParams
00044 from calibration_estimation.single_transform import SingleTransform
00045 from calibration_estimation.joint_chain import JointChain
00046 from calibration_estimation.urdf_params import UrdfParams
00047
00048 from numpy import *
00049 import numpy
00050
00051 def loadSystem1():
00052 urdf = '''
00053 <robot>
00054 <link name="base_link"/>
00055 <joint name="j0" type="fixed">
00056 <origin xyz="10 0 0" rpy="0 0 0"/>
00057 <parent link="base_link"/>
00058 <child link="j0_link"/>
00059 </joint>
00060 <link name="j0_link"/>
00061 <joint name="j1" type="revolute">
00062 <axis xyz="0 0 1"/>
00063 <origin xyz="1 0 0" rpy="0 0 0"/>
00064 <parent link="j0_link"/>
00065 <child link="j1_link"/>
00066 </joint>
00067 <link name="j1_link"/>
00068 <joint name="j2" type="revolute">
00069 <axis xyz="0 0 1"/>
00070 <origin xyz="0 0 0" rpy="0 0 0"/>
00071 <parent link="j1_link"/>
00072 <child link="j2_link"/>
00073 </joint>
00074 <link name="j2_link"/>
00075 <joint name="j3" type="fixed">
00076 <origin xyz="0 0 20" rpy="0 0 0"/>
00077 <parent link="j2_link"/>
00078 <child link="j3_link"/>
00079 </joint>
00080 <link name="j3_link"/>
00081 </robot>
00082 '''
00083 config = yaml.load('''
00084 sensors:
00085 chains:
00086 chain1:
00087 root: j0_link
00088 tip: j2_link
00089 cov:
00090 joint_angles: [0.001, 0.001]
00091 gearing: [1.0, 1.0]
00092 rectified_cams: {}
00093 tilting_lasers: {}
00094 transforms: {}
00095 checkerboards: {}
00096 ''')
00097
00098 return UrdfParams(urdf, config)
00099
00100 class TestFullChainCalcBlock(unittest.TestCase):
00101
00102 def test_fk_1(self):
00103 print ""
00104 params = loadSystem1()
00105 chain = FullChainRobotParams('chain1', 'j3_link')
00106 chain.update_config(params)
00107
00108 chain_state = JointState(position=[0, 0])
00109 result = chain.calc_block.fk(chain_state)
00110 expected = numpy.matrix( [[ 1, 0, 0,11],
00111 [ 0, 1, 0, 0],
00112 [ 0, 0, 1,20],
00113 [ 0, 0, 0, 1]], float )
00114 print result
00115 self.assertAlmostEqual(numpy.linalg.norm(result-expected), 0.0, 6)
00116
00117 def test_fk_2(self):
00118 print ""
00119 params = loadSystem1()
00120 chain = FullChainRobotParams('chain1', 'j3_link')
00121 chain.update_config(params)
00122
00123 chain_state = JointState(position=[pi/2, 0])
00124 result = chain.calc_block.fk(chain_state)
00125 expected = numpy.matrix( [[ 0,-1, 0,11],
00126 [ 1, 0, 0, 0],
00127 [ 0, 0, 1,20],
00128 [ 0, 0, 0, 1]], float )
00129 print result
00130 self.assertAlmostEqual(numpy.linalg.norm(result-expected), 0.0, 6)
00131
00132 def test_fk_partial(self):
00133 print ""
00134 params = loadSystem1()
00135 chain = FullChainRobotParams('chain1', 'j1_link')
00136 chain.update_config(params)
00137
00138 chain_state = JointState(position=[0, 0])
00139 result = chain.calc_block.fk(chain_state)
00140 expected = numpy.matrix( [[ 1, 0, 0,11],
00141 [ 0, 1, 0, 0],
00142 [ 0, 0, 1, 0],
00143 [ 0, 0, 0, 1]], float )
00144 print result
00145 self.assertAlmostEqual(numpy.linalg.norm(result-expected), 0.0, 6)
00146
00147
00148 if __name__ == '__main__':
00149 import rostest
00150 rostest.unitrun('calibration_estimation', 'test_FullChainCalcBlock', TestFullChainCalcBlock, coverage_packages=['calibration_estimation.full_chain', 'calibration_estimation.urdf_params'])