Commit 146632c5 authored by Guilhem Saurel's avatar Guilhem Saurel

[Python] add a load helper, and use it in __main__

Gathering all expected available robots and parameters in one dict
indexed by names avoid the need to duplicate those informations.
parent 4f75b943
# flake8: noqa
from .robots_loader import (getModelPath, loadANYmal, loadDoublePendulum, loadHector, loadHyQ, loadICub, loadIris,
loadKinova, loadPanda, loadRomeo, loadSolo, loadTalos, loadTalosArm, loadTalosLegs,
loadTiago, loadTiagoNoHand, loadUR, readParamsFromSrdf)
from .robots_loader import (ROBOTS, getModelPath, load, loadANYmal, loadDoublePendulum, loadHector, loadHyQ, loadICub,
loadIris, loadKinova, loadPanda, loadRomeo, loadSolo, loadTalos, loadTalosArm,
loadTalosLegs, loadTiago, loadTiagoNoHand, loadUR, readParamsFromSrdf)
from argparse import ArgumentParser
import eigenpy
from .robots_loader import ROBOTS, load
from . import robots_loader
ROBOTS = sorted(ROBOTS.keys())
eigenpy.switchToNumpyMatrix()
ROBOTS = [
'anymal', 'anymal_kinova', 'hyq', 'solo', 'solo12', 'talos', 'talos_arm', 'talos_legs', 'kinova', 'tiago',
'tiago_no_hand', 'icub', 'ur5', 'romeo', 'hector', 'double_pendulum', 'iris', 'panda'
]
parser = ArgumentParser()
parser = ArgumentParser(description=load.__doc__)
parser.add_argument('robot', nargs='?', default=ROBOTS[0], choices=ROBOTS)
parser.add_argument('--no-display', action='store_false')
args = parser.parse_args()
if args.robot == 'anymal':
anymal = robots_loader.loadANYmal()
anymal.initViewer(loadModel=True)
anymal.display(anymal.q0)
elif args.robot == 'anymal_kinova':
anymal = robots_loader.loadANYmal(withArm='kinova')
anymal.initViewer(loadModel=True)
anymal.display(anymal.q0)
elif args.robot == 'hyq':
hyq = robots_loader.loadHyQ()
hyq.initViewer(loadModel=True)
hyq.display(hyq.q0)
elif args.robot == 'solo':
solo = robots_loader.loadSolo()
solo.initViewer(loadModel=True)
solo.display(solo.q0)
elif args.robot == 'solo12':
solo = robots_loader.loadSolo(False)
solo.initViewer(loadModel=True)
solo.display(solo.q0)
elif args.robot == 'talos':
talos = robots_loader.loadTalos()
talos.initViewer(loadModel=True)
talos.display(talos.q0)
elif args.robot == 'talos_arm':
talos_arm = robots_loader.loadTalosArm()
talos_arm.initViewer(loadModel=True)
talos_arm.display(talos_arm.q0)
elif args.robot == 'talos_legs':
talos_legs = robots_loader.loadTalosLegs()
talos_legs.initViewer(loadModel=True)
talos_legs.display(talos_legs.q0)
elif args.robot == 'kinova':
kinova = robots_loader.loadKinova()
kinova.initViewer(loadModel=True)
kinova.display(kinova.q0)
elif args.robot == 'tiago':
tiago = robots_loader.loadTiago()
tiago.initViewer(loadModel=True)
tiago.display(tiago.q0)
elif args.robot == 'tiago_no_hand':
tiago_no_hand = robots_loader.loadTiagoNoHand()
tiago_no_hand.initViewer(loadModel=True)
tiago_no_hand.display(tiago_no_hand.q0)
elif args.robot == 'icub':
icub = robots_loader.loadICub()
icub.initViewer(loadModel=True)
icub.display(icub.q0)
elif args.robot == 'ur5':
ur5 = robots_loader.loadUR()
ur5.initViewer(loadModel=True)
ur5.display(ur5.q0)
elif args.robot == 'romeo':
romeo = robots_loader.loadRomeo()
romeo.initViewer(loadModel=True)
romeo.display(romeo.q0)
if args.robot == 'hector':
hector = robots_loader.loadHector()
hector.initViewer(loadModel=True)
hector.display(hector.q0)
if args.robot == 'double_pendulum':
pendulum = robots_loader.loadDoublePendulum()
pendulum.initViewer(loadModel=True)
pendulum.display(pendulum.q0)
if args.robot == 'iris':
iris = robots_loader.loadIris()
iris.initViewer(loadModel=True)
iris.display(iris.q0)
if args.robot == 'panda':
panda = robots_loader.loadPanda()
panda.initViewer(loadModel=True)
panda.display(panda.q0)
load(args.robot, display=not args.no_display)
......@@ -227,3 +227,45 @@ def loadRomeo():
def loadIris():
return robot_loader('iris_description', "iris_simple.urdf", free_flyer=True)
ROBOTS = {
'anymal': (loadANYmal, {}),
'anymal_kinova': (loadANYmal, {
'withArm': 'kinova'
}),
'double_pendulum': (loadDoublePendulum, {}),
'hector': (loadHector, {}),
'hyq': (loadHyQ, {}),
'icub': (loadICub, {}),
'iris': (loadIris, {}),
'kinova': (loadKinova, {}),
'panda': (loadPanda, {}),
'romeo': (loadRomeo, {}),
'solo': (loadSolo, {}),
'solo12': (loadSolo, {
'solo': False
}),
'talos': (loadTalos, {}),
'talos_arm': (loadTalos, {
'arm': True
}),
'talos_legs': (loadTalos, {
'legs': True
}),
'tiago': (loadTiago, {}),
'tiago_no_hand': (loadTiago, {
'hand': False
}),
'ur5': (loadUR, {}),
}
def load(name, display=False):
"""Load a robot by its name, and optionnaly display it in a viewer."""
loader, kwargs = ROBOTS[name]
robot = loader(**kwargs)
if display:
robot.initViewer(loadModel=True)
robot.display(robot.q0)
return robot
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment