def loadConfig(self, filename, reload=False): # parameters are given in (our own brand of) config-file syntax self.config = ConfigGrabber(filename, sectionId="<!--odeenvironment parameters", delim=("<", ">")) # <passpairs> self.passpairs = [] for passpairstring in self.config.getValue("passpairs")[:]: self.passpairs.append(eval(passpairstring)) if self.verbosity > 0: print "-------[pass tuples]--------" print self.passpairs print "----------------------------" # <centerOn> # set focus of camera to the first object specified in the section, if any if self.render: try: self.centerOn(self.config.getValue("centerOn")[0]) except IndexError: pass # <affixToEnvironment> for jointName in self.config.getValue("affixToEnvironment")[:]: try: # find first object with that name obj = self.root.namedChild(jointName).getODEObject() except IndexError: print "ERROR: Could not affix object '" + jointName + "' to environment!" sys.exit(1) if isinstance(obj, ode.Joint): # if it is a joint, use this joint to fix to environment obj.attach(obj.getBody(0), ode.environment) elif isinstance(obj, ode.Body): # if it is a body, create new joint and fix body to environment j = ode.FixedJoint(self.world) j.attach(obj, ode.environment) j.setFixed() # <colors> for coldefstring in self.config.getValue("colors")[:]: # ('name', (0.3,0.4,0.5)) objname, coldef = eval(coldefstring) for (body, _) in self.body_geom: if hasattr(body, 'name'): if objname == body.name: body.color = coldef break if not reload: # add the JointSensor as default self.sensors = [] ## self.addSensor(self._jointSensor) # <sensors> # expects a list of strings, each of which is the executable command to create a sensor object # example: DistToPointSensor('legSensor', (0.0, 0.0, 5.0)) sens = self.config.getValue("sensors")[:] for s in sens: try: self.addSensor(eval('sensors.' + s)) except AttributeError: print dir(sensors) warnings.warn("Sensor name with name " + s + " not found. skipped.") else: for s in self.sensors: s._connect(self) for a in self.actuators: a._connect(self)