Skip to content

Commit 37cb01d

Browse files
committed
Added forward kinematics
1 parent 9c0289a commit 37cb01d

File tree

1 file changed

+106
-16
lines changed

1 file changed

+106
-16
lines changed

rtb/robot/ets.py

Lines changed: 106 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ def dh_to_ets(cls, robot):
6565
ETS representation
6666
6767
:param robot: The robot model to be converted
68-
:type robot: SerialLink, required
68+
:type robot: SerialLink
6969
:return: List of returned :class:`bluepy.btle.Characteristic` objects
7070
:rtype: ets class
7171
"""
@@ -119,6 +119,72 @@ def dh_to_ets(cls, robot):
119119
robot.base,
120120
robot.tool)
121121

122+
@property
123+
def name(self):
124+
return self._name
125+
126+
@property
127+
def manuf(self):
128+
return self._manuf
129+
130+
@property
131+
def base(self):
132+
return self._base
133+
134+
@property
135+
def tool(self):
136+
return self._tool
137+
138+
@property
139+
def n(self):
140+
return self._n
141+
142+
@property
143+
def M(self):
144+
return self._M
145+
146+
@property
147+
def ets(self):
148+
return self._ets
149+
150+
@property
151+
def q_idx(self):
152+
return self._q_idx
153+
154+
def fkine(self, q):
155+
'''
156+
Evaluates the forward kinematics of a robot based on its ETS and
157+
joint angles q.
158+
159+
:param q: The joint coordinates of the robot
160+
:type q: float np.ndarray(n,)
161+
:return: The transformation matrix representing the pose of the
162+
end-effector
163+
:rtype: float np.ndarray(4,4)
164+
165+
References: Kinematic Derivatives using the Elementary Transform
166+
Sequence, J. Haviland and P. Corke
167+
'''
168+
169+
# if not isinstance(q, np.ndarray):
170+
# raise TypeError('q array must be a numpy ndarray.')
171+
# if q.shape != (self._n,):
172+
# raise ValueError('q must be a 1 dim (n,) array')
173+
174+
j = 0
175+
trans = np.eye(4)
176+
177+
for i in range(self.M):
178+
if self._ets[i]._type == 1:
179+
T = self._ets[i].T(q[j])
180+
j += 1
181+
else:
182+
T = self._ets[i].T()
183+
184+
trans = trans @ T
185+
186+
return trans
187+
122188
def __str__(self):
123189
"""
124190
Pretty prints the ETS Model of the robot. Will output angles in degrees
@@ -129,15 +195,15 @@ def __str__(self):
129195
axes = ''
130196

131197
for i in range(self._n):
132-
axes += self._ets[self._q_idx[i]]._axis_s
198+
axes += self.ets[self.q_idx[i]].axis
133199

134200
model = '\n%s (%s): %d axis, %s, ETS\n'\
135201
'Elementary Transform Sequence:\n'\
136202
'%s\n'\
137203
'tool: t = (%g, %g, %g), RPY/xyz = (%g, %g, %g) deg' % (
138-
self._name, self._manuf, self._n, axes,
139-
self._ets,
140-
self._tool[0, 3], self._tool[1, 3], self._tool[2, 3], 0, 0, 0
204+
self.name, self.manuf, self.n, axes,
205+
self.ets,
206+
self.tool[0, 3], self.tool[1, 3], self.tool[2, 3], 0, 0, 0
141207
)
142208

143209
return model
@@ -161,25 +227,49 @@ class et(object):
161227
References: Kinematic Derivatives using the Elementary Transform Sequence,
162228
J. Haviland and P. Corke
163229
"""
164-
def __init__(self, axis, axis_s, eta=None, i=None):
230+
def __init__(self, axis_func, axis, eta=None, i=None):
165231

166232
super(et, self).__init__()
167233
self.STATIC = 0
168234
self.VARIABLE = 1
169235

170236
self._eta = eta
237+
self._axis_func = axis_func
171238
self._axis = axis
172-
self._axis_s = axis_s
173239

174-
if self._eta is not None:
240+
if self.eta is not None:
175241
self._type = self.STATIC
176-
self._T = axis(eta)
242+
self._T = axis_func(eta)
177243
else:
178244
self._type = self.VARIABLE
179245
self._i = i
180246

181-
if self._type is self.STATIC and self._axis_s[0] == 'R':
182-
self._eta_deg = self._eta * (180/np.pi)
247+
if self._type is self.STATIC and self.axis[0] == 'R':
248+
self._eta_deg = self.eta * (180/np.pi)
249+
250+
@property
251+
def eta(self):
252+
return self._eta
253+
254+
@property
255+
def eta_deg(self):
256+
return self._eta_deg
257+
258+
@property
259+
def axis_func(self):
260+
return self._eta
261+
262+
@property
263+
def axis_func(self):
264+
return self._axis_func
265+
266+
@property
267+
def axis(self):
268+
return self._axis
269+
270+
@property
271+
def i(self):
272+
return self._i
183273

184274
def T(self, q=None):
185275
"""
@@ -193,7 +283,7 @@ def T(self, q=None):
193283
if self._type is self.STATIC:
194284
return self._T
195285
else:
196-
return self._axis(q)
286+
return self.axis_func(q)
197287

198288
def __str__(self):
199289
"""
@@ -203,12 +293,12 @@ def __str__(self):
203293
:rtype: str
204294
"""
205295
if self._type is self.STATIC:
206-
if self._axis_s[0] == 'R':
207-
return '%s(%g)' % (self._axis_s, self._eta_deg)
296+
if self.axis[0] == 'R':
297+
return '%s(%g)' % (self.axis, self.eta_deg)
208298
else:
209-
return '%s(%g)' % (self._axis_s, self._eta)
299+
return '%s(%g)' % (self.axis, self.eta)
210300
else:
211-
return '%s(q%d)' % (self._axis_s, self._i)
301+
return '%s(q%d)' % (self.axis, self.i)
212302

213303
def __repr__(self):
214304
return str(self)

0 commit comments

Comments
 (0)