-
Notifications
You must be signed in to change notification settings - Fork 0
/
execute_path.py
99 lines (80 loc) · 2.48 KB
/
execute_path.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#! /usr/bin/env python
"""
Script for executing a specified path
@author: Achille
"""
import logging
from cuspidal.arm_ik import *
from cuspidal.viz_manip import MatplotlibCuspidalVisualizer, MayaCuspidalVisualizer
logging.basicConfig(level=logging.DEBUG)
# choose a kinematics model, see arm_ik.py
kinematics = Manipulator2()
# visualize, choose which visualizer. Both are possible.
# viz = MatplotlibCuspidalVisualizer(kinematics)
viz = MayaCuspidalVisualizer(kinematics)
# viz.update()
print(kinematics.origins([0, 0, 0]))
print(kinematics.forward_kinematics_2D([0, 0, 0]))
# give user a moment to adjust windows
viz.pause(2)
# SHOWING SOME POSTURE
# viz.update(joint_angles=np.array([0, -pi/2, 0]))
####################
# SHOWING ALL IK SOLUTIONS
# specify an end effector (ee) position
# xee = 1.2
# yee = 1.
# zee = 0.5
# all_solns = kinematics.ik(xee, yee, zee)
# for soln in all_solns:
# print(kinematics.origins(soln)[2, :])
# print(np.sqrt(kinematics.origins(soln)[2, 0]**2 + kinematics.origins(soln)[2, 1]**2))
# viz.update(soln)
# viz.pause(0.5)
####################
# INTERPOLATE FROM ONE POSTURE TO ANOTHER
# xee = 1.2
# yee = 1.
# zee = 0.5
# all_solns = kinematics.ik(xee, yee, zee)
# interpolated_angles = np.linspace(all_solns[0], all_solns[2], num=40)
# print(interpolated_angles)
# viz.pause(2)
# for i in range(len(interpolated_angles)):
# joints = kinematics.random_valid_config()
# angles = interpolated_angles[i]
# viz.update(angles)
####################
# INTERPOLATE TWO WORKSPACE POINTS TO CREATE PATH
# starting position
x_s = 2.45
y_s = 0.7
z_s = 0.2
# endpoint position
x_e = 0.3
y_e = 0.7
z_e = 0.2
interp_rhozee = np.linspace(np.array([x_s, y_s, z_s]), np.array([x_e, y_e, z_e]), num=40)
all_solns = kinematics.ik(x_s, y_s, z_s)
configs = [all_solns[1]]
norms = []
for x, y, z in interp_rhozee:
postures = kinematics.ik(x, y, z)
print("number of postures found: {}".format(len(postures)))
# pick the closest config
best_norm = np.inf
best_config = None
for posture in postures:
norm = np.linalg.norm(np.array(posture)-np.array(configs[-1]))
if norm < best_norm:
best_norm = norm
best_config = posture
configs.append(best_config)
norms.append(best_norm)
for config, norm in zip(configs, norms):
viz.update(config)
# tweak this to adjust speed of animation
viz.pause(0.05)
######################################################
done = input("enter when done: ")
viz.shutdown()