Пример #1
0
	def connectionParameterMatrix(self, parameter):
		if utils.isCallable(parameter):
			matrix = parameter((self.noNodes, self.noNodes)) * self.connections
			matrix = np.tril(matrix) + np.tril(matrix).T # ensure symmetry
		else:
			matrix = parameter * np.ones((self.noNodes, self.noNodes)) * self.connections
		return matrix
Пример #2
0
	def __init__(self, initialPos, connections, noNodes, mass, environment):
		"""--- Initialise a morphology of a robot ---
		-- parameters --
			- noNodes : integer
				the number of nodes the robot consists of      
			- mass : float or callable
				the initial mass of the nodes
			- spring : float or callable
				the initial spring constant value
			- damping : float or callable
				the initial damping factor
			- initHeight : float
				initial height of the robot in construction
			- noNeighbours : int
				number of neighbours to which a spring connection is made
			- environment : Environment
				physical environment in which the robot will move
		"""
		# init robot
		self.noNodes = noNodes # the number of nodes the robot consists of
		self.environment = environment
		self.initialPos = initialPos
		self.connections = connections


		# set initial masses
		if utils.isCallable(mass):
			self.mass = mass((self.noNodes,))
		else:
			self.mass = mass * np.ones((self.noNodes,))

		# map connectionNumber to start and end position
		indexMatrix = np.tile(np.arange(noNodes), [noNodes,1])
		self.start = utils.connections2Array(indexMatrix, self.connections)
		self.end = utils.connections2Array(indexMatrix.T, self.connections)
Пример #3
0
    def writeMember(self, obj, memberName):
        if isString(obj):
            logging.warning(u"String as object provided! " +
                            self._warningPrefix(obj, memberName))
        if isInteger(memberName) and isList(obj):
            member = obj[memberName]
            memberName = str(memberName)
        else:
            member = getattr(obj, memberName, None)
        if member is None:
            self.log(u"skipped " + self._warningPrefix(obj, memberName) +
                     u"It is empty or does not exist (=None).")
            return

        if isCallable(member) and not hasattr(member, "hdfWrite"):
            member = member()

        if hasattr(member, "hdfWrite"):  # support instances and types
            # store the member in a group of its own
            oldLocation = self.location
            self._location = "/".join((oldLocation.rstrip('/'), memberName))
            member.hdfWrite(self)  # recursion entry, mind the loops!
            self._location = oldLocation
        elif isList(member):
            self.writeDataset(memberName, member)
        elif isString(member) or isNumber(member):
            self.writeAttribute(memberName, member)
        else:
            self.log(u"skipped " + self._warningPrefix(obj, memberName) +
                     "(={}) It is not a compatible value type!".format(
                         classname(member)))
Пример #4
0
 def register(self, what, *func):
     # check for the correct number of arguments of func as well?
     assert all((isCallable(f) for f in func))
     self._assertPurpose(what)
     if self._callbacks is None:  # lazy init
         self._callbacks = dict()
     if what not in self._callbacks:
         self._callbacks[what] = []
     for f in func:
         if funcNotInFuncList(f, self._callbacks[what]):
             self._callbacks[what].append(f)
Пример #5
0
 def callback(self, what, *args, **kwargs):
     self._assertPurpose(what)
     if self._callbacks is None:
         return
     funcLst = []
     for func in self._callbacks.get(what, []):
         if not isCallable(func):
             continue
         func(*args, **kwargs)
         funcLst.append(func)
     # update the callback list, invalid functions removed
     self._callbacks[what] = funcLst
Пример #6
0
 def registerUpdateFunc(self, func):
     assert isCallable(func)
     self._updateFunc.append(func)