def loadRobotModel(name=None, view=None, parent='scene', urdfFile=None, color=None, visible=True, colorMode='URDF Colors', useConfigFile=True): if not urdfFile: urdfFile = drcargs.getDirectorConfig()['urdfConfig']['default'] if isinstance(parent, str): parent = om.getOrCreateContainer(parent) model = loadRobotModelFromFile(urdfFile) if not model: raise Exception('Error loading robot model from file: %s' % urdfFile) obj = RobotModelItem(model) om.addToObjectModel(obj, parent) if name: obj.setProperty('Name', name) obj.setProperty('Visible', visible) obj.setProperty('Color', color or getRobotGrayColor()) if colorMode == 'Textures': obj.setProperty('Color Mode', 1) elif colorMode == 'Solid Color': obj.setProperty('Color Mode', 0) elif colorMode == 'URDF Colors': obj.setProperty('Color Mode', 2) if view is not None: obj.addToView(view) if useConfigFile: jointNames = None else: jointNames = model.getJointNames() jointController = jointcontrol.JointController([obj], jointNames=jointNames) if useConfigFile: fixedPointFile = drcargs.getDirectorConfig().get('fixedPointFile') if fixedPointFile: jointController.setPose( 'q_nom', jointController.loadPoseFromFile(fixedPointFile)) else: jointController.setPose('q_nom', jointController.getPose('q_zero')) return obj, jointController
def loadRobotModel( name=None, view=None, parent="scene", urdfFile=None, color=None, visible=True, colorMode="URDF Colors", useConfigFile=True, robotName="", ): if isinstance(parent, str): parent = om.getOrCreateContainer(parent) if urdfFile: model = loadRobotModelFromFile(urdfFile) haveModel = True else: model = None useConfigFile = True # we can't extract joint names from the model haveModel = False colorModes = {"Solid Color": 0, "Textures": 1, "URDF Colors": 2} obj = RobotModelItem( model=model, visible=visible, color=color or getRobotGrayColor(), colorMode=colorModes[colorMode], robotName=robotName, ) om.addToObjectModel(obj, parent) if name: obj.setProperty("Name", name) if view is not None: obj.addToView(view) if useConfigFile: jointNames = None else: jointNames = model.getJointNames() jointController = jointcontrol.JointController([obj], jointNames=jointNames, robotName=robotName, pushToModel=haveModel) return obj, jointController
return args app = mainwindowapp.construct() view = app.view args = getArgs() if args.urdf: robotModel, jointController = roboturdf.loadRobotModel(urdfFile=args.urdf, view=view, useConfigFile=False) jointNames = robotModel.model.getJointNames() jointController = jointcontrol.JointController([robotModel], jointNames=jointNames) elif args.glob_dir: urdfFiles = [] for root, dirnames, filenames in os.walk(args.glob_dir): for filename in fnmatch.filter(filenames, '*.urdf'): urdfFiles.append(os.path.join(root, filename)) failedFiles = [] for urdfFile in urdfFiles: print 'loading:', urdfFile try: robotModel, jointController = roboturdf.loadRobotModel( urdfFile=urdfFile, view=view,