本文整理汇总了Python中link.Link.connect方法的典型用法代码示例。如果您正苦于以下问题:Python Link.connect方法的具体用法?Python Link.connect怎么用?Python Link.connect使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类link.Link
的用法示例。
在下文中一共展示了Link.connect方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Module
# 需要导入模块: from link import Link [as 别名]
# 或者: from link.Link import connect [as 别名]
class Module(Component):
protocols.advise(instancesProvide=[ISceneItem])
#
#=== Public Methods ======================================================
#
#
#--- Creation ------------------------------------------------------------
#
# REQ: cfg = {'block': {'lengths': double,
# 'active': dict,
# 'passive': dict},
# 'link': dict}. <>
def __init__(self,
world,
name = "Module",
pos = vec3(),
rot = mat3(),
robot = None,
cfg = None,
data = None):
Component.__init__(self, name=name)
self.world = world
self.pos = pos
self.rot = rot
self.robot = robot
self.cfg = cfg
self.data = data
self.sensor = {}
self._createBlocks()
self._createLink()
self._connectObjects()
self._positionObjects()
self._configureSensors()
#
#--- Docking --------------------------------------------------------------
#
def dock(self, activeSide, module):
passiveSide = self._findMatchingDockingSide(activeSide, module.passive)
if passiveSide is not None:
self.active.dock(activeSide, module.passive, passiveSide)
else:
logger.warn("No matching docking side found for side '%s'." %
activeSide)
def undock(self, side):
self.active.undock(side)
#
#--- State information ----------------------------------------------------
#
def _getState(self):
activeBlockAngle = self.link.motor['active'].angle
passiveBlockAngle = self.link.motor['passive'].angle
activeBlockLightValue = self.active.state
passiveBlockLightValue = self.passive.state
moduleLightValue = 0.5 * (activeBlockLightValue + passiveBlockLightValue)
# get module direction
moduleDirection = self.sensor['direction'].value
# get module rotation
moduleRotation = self.sensor['rotation'].value
value = [moduleLightValue, moduleRotation, moduleDirection, activeBlockAngle, passiveBlockAngle]
return value
state = property(_getState)
def _getStatus(self):
motorStatus = [motor.status for motor in self.link.motor.values()]
logger.debug("motorStatus: %s" % str(motorStatus) )
moduleStatus = allIdle(motorStatus) and IDLE or BUSY
logger.debug("moduleStatus: %s" % moduleStatus)
return moduleStatus
status = property(_getStatus)
#
#=== Private Methods ======================================================
#
#
#--- Creation -------------------------------------------------------------
#
def _createBlocks(self):
self.active = self._createBlock(ACTIVE)
self.passive = self._createBlock(PASSIVE)
def _createBlock(self, type):
cfg = self._getBlockConfig(type)
pos, rot = self._getInitialValues(type)
name = '%s.%s' % (self.name, type)
block = Block(self.world, name=name, type=type, pos=pos, rot=rot,
cfg=cfg, module=self)
self.world.add(block)
logger.info("using block pos: %s" % pos)
return block
def _getBlockConfig(self, type):
cfg = self._getBaseBlockConfig()
#.........这里部分代码省略.........