-
Notifications
You must be signed in to change notification settings - Fork 0
/
youBot.py
155 lines (123 loc) · 4.07 KB
/
youBot.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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
import numpy as np
import modern_robotics as mr
from math import sin,cos
from numpy.lib.function_base import _select_dispatcher
class youBotProperties:
"""
contains all the properties for the youBot simulation...
includes dimensions , Transformaion Matrices , initial configuration and other stuff
"""
def __init__(self):
pass
robotDim = [0.47/2,0.30/2,0.0475] # Correspomds to length , width of the robot from centre and the radius of the wheels.
l,w,r = robotDim
Blist = np.array([
[0,0,1,0,0.033,0],
[0,-1,0,-0.5076,0,0],
[0,-1,0,-0.3526,0,0],
[0,-1,0,-0.2176,0,0],
[0,0,1,0,0,0]
]).T
homePositionM0e = np.array([
[1,0,0,0.033],
[0,1,0,0],
[0,0,1,0.6546],
[0,0,0,1]
])
F_theta = (r/4) * np.array([
[-1/(l+w),1/(l+w),1/(l+w),-1/(l+w)],
[1 ,1 ,1 ,1 ],
[-1 ,1 ,-1 ,1]
])
zeroMatrix = np.zeros(np.shape(F_theta)[1])
F6 = np.concatenate((zeroMatrix[np.newaxis,:],zeroMatrix[np.newaxis,:],F_theta,zeroMatrix[np.newaxis,:]),axis=0)
jointSpeedLimit = 12
wheelSpeedLimit = 40
deltaT = 0.01
ErrorInt = np.zeros(6)
@staticmethod
def saturate(variable,limit):
"""
saturates variable within
-limit <= variable <= limit
"""
variable = np.clip(variable,a_min= -1 * limit, a_max= limit)
return variable
class youBotState:
def __init__(self):
self.chasisState = np.zeros(3)
self.jointState = np.zeros(5)
self.wheelState = np.zeros(4)
self.gripperState = np.zeros(1)
class ControlVector:
def __init__(self):
self.jointSpeeds = np.zeros(5)
self.wheelSpeeds = np.zeros(4)
self.griperControl = np.zeros(1) # could be redundant....
class TrasformMatrix:
"""
Contains all the transformation Matrices required for the use in the entire simulation
and the functions required to do form them..
"""
def __init__(self):
pass
T_b0 = np.array([
[1,0,0,0.1662],
[0,1,0,0],
[0,0,1,0.0026],
[0,0,0,1]
])
Standoff_Tce = np.array([[-0.34202014, 0. , 0.93969262, 0.05 ],
[ 0. , 1. , 0. , 0. ],
[-0.93969262, 0. , -0.34202014, 0.2 ],
[ 0. , 0. , 0. , 1. ]])
Grasp_Tce = np.array([[-0.34202014, 0. , 0.93969262, 0.01 ],
[ 0. , 1. , 0. , 0. ],
[-0.93969262, 0. , -0.34202014, 0. ],
[ 0. , 0. , 0. , 1. ]])
def cubePosition(cubePos):
"""
give the position of the cube in the space frame {s}
x,y,phi
used for both initial and final configurations
"""
x,y,phi = cubePos
cube = np.array([
[cos(phi),-sin(phi),0,x],
[sin(phi),cos(phi),0,y],
[0,0,1,0.025],
[0,0,0,1]
])
return cube
def basePosition(chasisConfig):
"""
input: takes in Chasis configuration of the robot
Chasis Config represented by phi,x,y
returns: the transformation matrix of the base in the space frame {s}
"""
phi,x,y = chasisConfig
base = np.array([
[cos(phi),-sin(phi),0,x],
[sin(phi),cos(phi),0,y],
[0,0,1,0.0963],
[0,0,0,1]
])
return base
def endEffectorinSpace(currentState):
"""
input:
current state
returns:
the transformation matrix of the end effector in space frame.
"""
base = basePosition(currentState.chasisState)
offset = TrasformMatrix.T_b0
forwardkin = mr.FKinBody(youBotProperties.homePositionM0e,youBotProperties.Blist,currentState.jointState)
endEffector = np.dot(base,np.dot(offset,forwardkin))
return endEffector
def flatTrajtoTransform(traj):
gripper = traj[-1]
rotation = traj[0:9].reshape(3,3)
point = traj[9:12]
transform = mr.RpToTrans(rotation,point)
return transform,gripper