Skip to content

Commit 42acc67

Browse files
committed
fix block tests, integrate with main tests folder
1 parent 1b35ecf commit 42acc67

File tree

4 files changed

+110
-99
lines changed

4 files changed

+110
-99
lines changed

roboticstoolbox/blocks/arm.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
"""
2020
# The constructor of each class ``MyClass`` with a ``@block`` decorator becomes a method ``MYCLASS()`` of the BlockDiagram instance.
2121

22+
2223
# ------------------------------------------------------------------------ #
2324
class FKine(FunctionBlock):
2425
r"""
@@ -184,7 +185,7 @@ def output(self, t, inports, x):
184185
else:
185186
q0 = self.q0
186187

187-
sol = self.ik(inputs[0], q0=q0, seed=self.seed, **self.args)
188+
sol = self.ik(inports[0], q0=q0, seed=self.seed, **self.args)
188189

189190
if not sol.success:
190191
raise RuntimeError("inverse kinematic failure for pose", inports[0])
@@ -411,7 +412,6 @@ def start(self, simstate):
411412
)
412413

413414
def step(self, t, inports):
414-
415415
# update the robot plot
416416
self.robot.q = inports[0]
417417
self.env.step()
@@ -518,11 +518,12 @@ def __init__(self, q0, qf, qd0=None, qdf=None, T=None, **blockargs):
518518
# set T to 1 just for now
519519
if T is None:
520520
self.T = 1
521-
self.start()
522521
self.T = T
523522

524-
def start(self, simstate):
523+
# valid value, to allow compile to call output() before start()
524+
self.start(None)
525525

526+
def start(self, simstate):
526527
if self.T is None:
527528
# use simulation tmax
528529
self.T = simstate.T
@@ -558,7 +559,6 @@ def start(self, simstate):
558559
)
559560

560561
def output(self, t, inports, x):
561-
562562
tscal = self.tscal
563563
ts = t / tscal
564564
tt = np.array([ts**5, ts**4, ts**3, ts**2, ts, 1]).T
@@ -822,7 +822,6 @@ def __init__(self, q0, qf, V=None, T=None, **blockargs):
822822
self.qf = qf
823823

824824
def start(self, simstate):
825-
826825
if self.T is None:
827826
self.T = simstate.T
828827
self.trapezoidalfunc = trapezoidal_func(self.q0, self.qf, self.T)
@@ -946,7 +945,7 @@ def start(self, simstate):
946945
else:
947946
# input based
948947
xmax = 1
949-
sim.xmax = xmax
948+
self.xmax = xmax
950949

951950
for i in range(len(self.y0)):
952951
self.trajfuncs.append(trajfunc(self.y0[i], self.yf[i], xmax))
@@ -1557,7 +1556,6 @@ def deriv(self, t, inports, x):
15571556

15581557

15591558
if __name__ == "__main__":
1560-
15611559
from pathlib import Path
15621560

15631561
exec(

roboticstoolbox/blocks/mobile.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ def __init__(
8787
# gamma dot
8888

8989
super().__init__(nstates=3, **blockargs)
90+
self.type = "bicycle"
9091

9192
self.vehicle = mobile.Bicycle(
9293
L=L, steer_max=steer_max, speed_max=speed_max, accel_max=accel_max
@@ -185,6 +186,7 @@ def __init__(
185186
:type blockargs: dict
186187
"""
187188
super().__init__(nstates=3, **blockargs)
189+
self.type = "unicycle"
188190

189191
if x0 is None:
190192
self._x0 = np.zeros((self.nstates,))
@@ -299,7 +301,7 @@ def __init__(
299301
:type blockargs: dict
300302
"""
301303
super().__init__(nstates=3, **blockargs)
302-
# self.type = "diffsteer"
304+
self.type = "diffsteer"
303305
self.R = R
304306

305307
if x0 is None:
@@ -310,7 +312,7 @@ def __init__(
310312
)
311313
self._x0 = x0
312314

313-
self.vehicle = mobile.Unicycle(
315+
self.vehicle = mobile.DiffSteer(
314316
W=w, steer_max=steer_max, speed_max=speed_max, accel_max=accel_max
315317
)
316318

roboticstoolbox/mobile/Vehicle.py

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1227,6 +1227,27 @@ def init(self):
12271227
self._v_prev_L = [0]
12281228
self._v_prev_R = [0]
12291229

1230+
1231+
def u_limited(self, u):
1232+
"""
1233+
Apply vehicle velocity and acceleration limits
1234+
1235+
:param u: Desired vehicle inputs :math:`(v_L, v_R)`
1236+
:type u: array_like(2)
1237+
:return: Allowable vehicle inputs :math:`(v_L, v_R)`
1238+
:rtype: ndarray(2)
1239+
1240+
Velocity and acceleration limits are applied to :math:`v` and
1241+
turn rate limits are applied to :math:`\omega`.
1242+
"""
1243+
1244+
# limit speed and acceleration of each wheel/track
1245+
ulim = np.array(u)
1246+
ulim[0] = self.limits_va(u[0], self._v_prev_L)
1247+
ulim[1] = self.limits_va(u[1], self._v_prev_R)
1248+
1249+
return ulim
1250+
12301251
def deriv(self, x, u, limits=True):
12311252
r"""
12321253
Time derivative of state
@@ -1270,27 +1291,8 @@ def deriv(self, x, u, limits=True):
12701291

12711292
return np.r_[v * cos(theta), v * sin(theta), vdiff / self._W]
12721293

1273-
def u_limited(self, u):
1274-
"""
1275-
Apply vehicle velocity and acceleration limits
1276-
1277-
:param u: Desired vehicle inputs :math:`(v_L, v_R)`
1278-
:type u: array_like(2)
1279-
:return: Allowable vehicle inputs :math:`(v_L, v_R)`
1280-
:rtype: ndarray(2)
1281-
1282-
Velocity and acceleration limits are applied to :math:`v` and
1283-
turn rate limits are applied to :math:`\omega`.
1284-
"""
1285-
1286-
# limit speed and steer angle
1287-
ulim = np.array(u)
1288-
ulim[0] = self.limits_va(u[0], self._v_prev_L)
1289-
ulim[1] = self.limits_va(u[1], self._v_prev_R)
1290-
1291-
return ulim
1292-
12931294

1295+
12941296
if __name__ == "__main__":
12951297

12961298
from roboticstoolbox import RandomPath

0 commit comments

Comments
 (0)