added argparser, can specify backend and robot model from command line
import roboticstoolbox as rtb
from spatialmath import * # lgtm [py/polluting-import]
+import argparse
+import sys
+parser = argparse.ArgumentParser(description="Puma trajectory demo")
+parser.add_argument('--backend', '-b', dest='backend', default='pyplot',
+ help='choose backend: pyplot (default), swift, vpython', action='store')
+parser.add_argument('--model', '-m', dest='model', default='DH', action='store',
+ help='choose model: DH (default), URDF')
+args = parser.parse_args()
-#robot = rtb.models.URDF.Puma560()
+if args.model.lower() == 'dh':
robot = rtb.models.DH.Puma560()
+elif args.model.lower() == 'urdf':
+ robot = rtb.models.URDF.Puma560()
+else:
+ raise ValueError('unknown model')
+
print(robot)
-print(robot.fkine(robot.qz))
-# tw, T0 = p560.twists(p560.qn)
-# print(tw)
+
qt = rtb.tools.trajectory.jtraj(robot.qz, robot.qr, 200)
-robot.plot(qt.q, dt=0.1, block=True) #movie='puma_sitting.gif')
-#swift = rtb.backend.Swift()
-#swift.launch()
-#swift.add(robot)
-#for q in qt.q:
- #robot.q = q
- #swift.step()
+
+if args.backend.lower() == 'pyplot':
+ if args.model.lower() != 'dh':
+ print('PyPlot only supports DH models for now')
+ sys.exit(1)
+ backend = rtb.backends.PyPlot()
+elif args.backend.lower() == 'vpython':
+ if args.model.lower() != 'dh':
+ print('VPython only supports DH models for now')
+ sys.exit(1)
+ backend = rtb.backends.VPython()
+elif args.backend.lower() == 'swift':
+ if args.model.lower() != 'urdf':
+ print('Swift only supports URDF models for now')
+ sys.exit(1)
+ backend = rtb.backends.Swift()
+else:
+ raise ValueError('unknown backend')
+
+backend.launch()
+backend.add(robot)
+for q in qt.q:
+ robot.q = q
+ backend.step(0.1)
