-
Notifications
You must be signed in to change notification settings - Fork 279
/
Copy pathforward_kinematics.py
76 lines (60 loc) · 2.74 KB
/
forward_kinematics.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
'''In this exercise you need to implement forward kinematics for NAO robot
* Tasks:
1. complete the kinematics chain definition (self.chains in class ForwardKinematicsAgent)
The documentation from Aldebaran is here:
http://doc.aldebaran.com/2-1/family/robots/bodyparts.html#effector-chain
2. implement the calculation of local transformation for one joint in function
ForwardKinematicsAgent.local_trans. The necessary documentation are:
http://doc.aldebaran.com/2-1/family/nao_h21/joints_h21.html
http://doc.aldebaran.com/2-1/family/nao_h21/links_h21.html
3. complete function ForwardKinematicsAgent.forward_kinematics, save the transforms of all body parts in torso
coordinate into self.transforms of class ForwardKinematicsAgent
* Hints:
1. the local_trans has to consider different joint axes and link parameters for different joints
2. Please use radians and meters as unit.
'''
# add PYTHONPATH
import os
import sys
sys.path.append(os.path.join(os.path.abspath(os.path.dirname(__file__)), '..', 'joint_control'))
from numpy.matlib import matrix, identity
from recognize_posture import PostureRecognitionAgent
class ForwardKinematicsAgent(PostureRecognitionAgent):
def __init__(self, simspark_ip='localhost',
simspark_port=3100,
teamname='DAInamite',
player_id=0,
sync_mode=True):
super(ForwardKinematicsAgent, self).__init__(simspark_ip, simspark_port, teamname, player_id, sync_mode)
self.transforms = {n: identity(4) for n in self.joint_names}
# chains defines the name of chain and joints of the chain
self.chains = {'Head': ['HeadYaw', 'HeadPitch']
# YOUR CODE HERE
}
def think(self, perception):
self.forward_kinematics(perception.joint)
return super(ForwardKinematicsAgent, self).think(perception)
def local_trans(self, joint_name, joint_angle):
'''calculate local transformation of one joint
:param str joint_name: the name of joint
:param float joint_angle: the angle of joint in radians
:return: transformation
:rtype: 4x4 matrix
'''
T = identity(4)
# YOUR CODE HERE
return T
def forward_kinematics(self, joints):
'''forward kinematics
:param joints: {joint_name: joint_angle}
'''
for chain_joints in self.chains.values():
T = identity(4)
for joint in chain_joints:
angle = joints[joint]
Tl = self.local_trans(joint, angle)
# YOUR CODE HERE
self.transforms[joint] = T
if __name__ == '__main__':
agent = ForwardKinematicsAgent()
agent.run()