-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_kinematics.py
44 lines (35 loc) · 1.46 KB
/
test_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
#!/usr/bin/env python
import rospy
import numpy as np
from math import pi
from std_msgs.msg import Header
from sensor_msgs.msg import JointState
from forward_kinematics import forward_kinematics
from inverse_kinematics import inverse_kinematics
class Manipulator():
def __init__(self):
rospy.init_node('manipulator')
rospy.loginfo("Press Ctrl + C to terminate")
self.rate = rospy.Rate(10)
## PLease fill in your code here
self.joint_pub = rospy.Publisher('/rx150/joint_states',JointState,queue_size=10)
# prepare joint message to publish
joint_msg = JointState()
joint_msg.header = Header()
joint_msg.name = ['waist', 'shoulder', 'elbow', 'wrist_angle',\
'wrist_rotate', 'gripper', 'left_finger', 'right_finger']
joint_msg.position = [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.026, -0.026]
# test cases
angles = [pi/6, -pi/3, -pi/6] # joint angle in radian
pos = [0.02165, 0.01250, 0.29721]
position = forward_kinematics(angles)
joint_angle = inverse_kinematics(pos)
print('Position of end-effector = ', position)
print('Joint angles = ', joint_angle)
while not rospy.is_shutdown():
joint_msg.header.stamp = rospy.Time.now()
joint_msg.position[0:3] = angles
self.joint_pub.publish(joint_msg)
self.rate.sleep()
if __name__ == '__main__':
whatever = Manipulator()