1 from __future__
import print_function
5 roslib.load_manifest(
"ur_kinematics")
6 from ur_kin_py
import forward, inverse
11 test_sol = np.ones(6)*9999.
13 for add_ang
in [-2.*np.pi, 0, 2.*np.pi]:
14 test_ang = sol[i] + add_ang
15 if (abs(test_ang) <= 2.*np.pi
and 16 abs(test_ang - q_guess[i]) < abs(test_sol[i] - q_guess[i])):
17 test_sol[i] = test_ang
18 if np.all(test_sol != 9999.):
19 valid_sols.append(test_sol)
20 if len(valid_sols) == 0:
22 best_sol_ind = np.argmin(np.sum((weights*(valid_sols - np.array(q_guess)))**2,1))
23 return valid_sols[best_sol_ind]
27 sols =
inverse(np.array(x), float(q[5]))
32 diff = np.sum(np.abs(np.array(qsol) - q))
35 print(
'Best q:', qsol)
36 print(
'Actual:', np.array(q))
37 print(
'Diff: ', q - qsol)
38 print(
'Difdiv:', (q - qsol)/np.pi)
39 print(i1-3, i2-3, i3-3, i4-3, i5-3, i6-3)
40 if raw_input() ==
'q':
44 np.set_printoptions(precision=3)
45 print(
"Testing multiples of pi/2...")
53 q = np.array([i1*np.pi/2., i2*np.pi/2., i3*np.pi/2.,
54 i4*np.pi/2., i5*np.pi/2., i6*np.pi/2.])
56 print(
"Testing random configurations...")
57 for i
in range(10000):
58 q = (np.random.rand(6)-.5)*4*np.pi
62 if __name__ ==
"__main__":
65 cProfile.run(
'main()',
'ik_prof')
int inverse(const double *T, double *q_sols, double q6_des=0.0)
void forward(const double *q, double *T)
def best_sol(sols, q_guess, weights)