-
Notifications
You must be signed in to change notification settings - Fork 70
/
IK_solver.py
52 lines (48 loc) · 1.86 KB
/
IK_solver.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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Thu Feb 20 18:20:45 2020
@author: miguel-asd
"""
import numpy
def checkdomain(D):
if D > 1 or D < -1:
print("____OUT OF DOMAIN____")
if D > 1:
D = 0.99
return D
elif D < -1:
D = -0.99
return D
else:
return D
#this is based on this paper:
#"https://www.researchgate.net/publication/320307716_Inverse_Kinematic_Analysis_Of_A_Quadruped_Robot"
"""
"using pybullet frame"
" z "
" | "
" | "
" | / y "
" | / "
" | / "
" | / "
" |/____________ x "
"""
#IK equations now written in pybullet frame.
def solve_R(coord , coxa , femur , tibia):
D = (coord[1]**2+(-coord[2])**2-coxa**2+(-coord[0])**2-femur**2-tibia**2)/(2*tibia*femur) #siempre <1
D = checkdomain(D)
gamma = numpy.arctan2(-numpy.sqrt(1-D**2),D)
tetta = -numpy.arctan2(coord[2],coord[1])-numpy.arctan2(numpy.sqrt(coord[1]**2+(-coord[2])**2-coxa**2),-coxa)
alpha = numpy.arctan2(-coord[0],numpy.sqrt(coord[1]**2+(-coord[2])**2-coxa**2))-numpy.arctan2(tibia*numpy.sin(gamma),femur+tibia*numpy.cos(gamma))
angles = numpy.array([-tetta, alpha, gamma])
return angles
def solve_L(coord , coxa , femur , tibia):
D = (coord[1]**2+(-coord[2])**2-coxa**2+(-coord[0])**2-femur**2-tibia**2)/(2*tibia*femur) #siempre <1
D = checkdomain(D)
gamma = numpy.arctan2(-numpy.sqrt(1-D**2),D)
tetta = -numpy.arctan2(coord[2],coord[1])-numpy.arctan2(numpy.sqrt(coord[1]**2+(-coord[2])**2-coxa**2),coxa)
alpha = numpy.arctan2(-coord[0],numpy.sqrt(coord[1]**2+(-coord[2])**2-coxa**2))-numpy.arctan2(tibia*numpy.sin(gamma),femur+tibia*numpy.cos(gamma))
angles = numpy.array([-tetta, alpha, gamma])
return angles