本文整理汇总了Python中Tools.Tools类的典型用法代码示例。如果您正苦于以下问题:Python Tools类的具体用法?Python Tools怎么用?Python Tools使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Tools类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: run
def run(self):
Tools.debug("Led blinker thread starting")
nb = 0
self._isRunning = True
while self._isRunning:
self.led.setColor(self._onColor)
startTime = time.time()
while time.time() - startTime < self._onTime / 1000.0 and self._isRunning:
time.sleep(0.001)
if not self._isRunning:
break
self.led.setColor(self._offColor)
startTime = time.time()
while time.time() - startTime < self._offTime / 1000.0 and self._isRunning:
time.sleep(0.001)
if not self._isRunning:
break
nb += 1
if nb == self._count:
self._isRunning = False
self.led.setColor(0, 0, 0)
self.led._blinkerThread = None
self._isAlive = False
Tools.debug("Led blinker thread finished")
示例2: _readByte
def _readByte(self, reg):
try:
result = self.bus.read_byte_data(self.address, reg)
return result
except:
Tools.debug("Error while reading from I2C device at address: " + str(self.address))
return None
示例3: __init__
def __init__(self, id, **kwargs):
'''
Creates a light sensor instance with given id.
IDs: 0: front left, 1: front right, 2: rear left, 3: rear right
The following global constants are defined:
LS_FRONT_LEFT = 0, LS_FRONT_RIGHT = 1, LS_REAR_LEFT = 2, LS_REAR_RIGHT = 3.
@param id: the LightSensor identifier
'''
self.id = id
self.sensorState = "DARK"
self.sensorType = "LightSensor"
self.triggerLevel = 500
self.brightCallback = None
self.darkCallback = None
self.isRegistered = False
for key in kwargs:
if key == "bright":
self.brightCallback = kwargs[key]
elif key == "dark":
self.darkCallback = kwargs[key]
robot = RobotInstance.getRobot()
if robot == None: # deferred registering, because Robot not yet created
RobotInstance._sensorsToRegister.append(self)
else:
if self.brightCallback != None or self.darkCallback != None:
robot.registerSensor(self)
Tools.debug("LightSensor instance with ID " + str(id) + " created")
示例4: isButtonDown
def isButtonDown(self):
"""
Checks if button is currently pressed.
@return: True, if the button is actually pressed
"""
Tools.delay(1)
return GPIO.input(SharedConstants.P_BUTTON) == GPIO.LOW
示例5: __init__
def __init__(self, id, **kwargs):
'''
Creates an infrared sensor at given port.
For the Pi2Go the following infrared sensors are used:
id = 0: front center; id = 1: front left; id = 2: front right;
id = 3: line left; id = 4: line right. The following global constants are defined:
IR_CENTER = 0, IR_LEFT = 1, IR_RIGHT = 2, IR_LINE_LEFT = 3, IR_LINE_RIGHT = 4
@param id: sensor identifier
'''
self.id = id
self.sensorState = "PASSIVATED"
self.sensorType = "InfraredSensor"
self.activateCallback = None
self.passivateCallback = None
for key in kwargs:
if key == "activated":
self.activateCallback = kwargs[key]
elif key == "passivated":
self.passivateCallback = kwargs[key]
robot = RobotInstance.getRobot()
if robot == None: # deferred registering, because Robot not yet created
RobotInstance._sensorsToRegister.append(self)
else:
if self.activateCallback != None or self.passivateCallback != None:
robot.registerSensor(self)
Tools.debug("InfraredSensor instance with ID " + str(id) + " created")
示例6: getValue
def getValue(self):
'''
Checks, if reflected light is detected.
@return: 1, if the sensor detects reflected light; otherwise 0
@rtype: int
'''
Tools.delay(1)
self._checkRobot()
if self.id == SharedConstants.IR_CENTER and \
GPIO.input(SharedConstants.P_FRONT_CENTER) == GPIO.LOW:
return 1
elif self.id == SharedConstants.IR_LEFT and \
GPIO.input(SharedConstants.P_FRONT_LEFT) == GPIO.LOW:
return 1
elif self.id == SharedConstants.IR_RIGHT and \
GPIO.input(SharedConstants.P_FRONT_RIGHT) == GPIO.LOW:
return 1
elif self.id == SharedConstants.IR_LINE_LEFT and \
GPIO.input(SharedConstants.P_LINE_LEFT) == GPIO.LOW:
return 1
elif self.id == SharedConstants.IR_LINE_RIGHT and \
GPIO.input(SharedConstants.P_LINE_RIGHT) == GPIO.LOW:
return 1
else:
return 0
示例7: __init__
def __init__(self):
"""
Creates a gear instance.
"""
self.speed = SharedConstants.GEAR_DEFAULT_SPEED
self.state = GearState.UNDEFINED
Tools.debug("Gear instance created")
示例8: exit
def exit(self):
"""
Cleans-up and releases all resources.
"""
global _isButtonEnabled
Tools.debug("Calling Robot.exit()")
self.setButtonEnabled(False)
# Stop motors
SharedConstants.LEFT_MOTOR_PWM[0].ChangeDutyCycle(0)
SharedConstants.LEFT_MOTOR_PWM[1].ChangeDutyCycle(0)
SharedConstants.RIGHT_MOTOR_PWM[0].ChangeDutyCycle(0)
SharedConstants.RIGHT_MOTOR_PWM[1].ChangeDutyCycle(0)
# Stop button thread, if necessary
if _buttonThread != None:
_buttonThread.stop()
# Stop display
display = Display._myInstance
if display != None:
display.stopTicker()
display.clear()
Led.clearAll()
MyRobot.closeSound()
if self.sensorThread != None:
self.sensorThread.stop()
self.sensorThread.join(2000)
# GPIO.cleanup() Do not cleanup, otherwise button will not work any more when coming back
# from remote execution
Tools.delay(2000) # avoid "sys.excepthook is missing"
示例9: exit
def exit(self):
"""
Cleans-up and releases all resources.
"""
global _isButtonEnabled
Tools.debug("Calling Robot.exit()")
self.setButtonEnabled(False)
# Stop motors
SharedConstants.LEFT_MOTOR_PWM[0].ChangeDutyCycle(0)
SharedConstants.LEFT_MOTOR_PWM[1].ChangeDutyCycle(0)
SharedConstants.RIGHT_MOTOR_PWM[0].ChangeDutyCycle(0)
SharedConstants.RIGHT_MOTOR_PWM[1].ChangeDutyCycle(0)
# Stop button thread, if necessary
if _buttonThread != None:
_buttonThread.stop()
# Stop display
display = Display._myInstance
if display != None:
display.stopTicker()
display.clear()
Led.clearAll()
Tools.delay(2000) # avoid "sys.excepthook is missing"
示例10: run
def run(self):
count = 0
while self.isRunning and count < SharedConstants.BUTTON_LONGPRESS_DURATION:
Tools.delay(200)
count += 1
if self.isRunning:
if _buttonListener != None:
_buttonListener(SharedConstants.BUTTON_LONGPRESSED)
示例11: setButtonEnabled
def setButtonEnabled(self, enable):
"""
Enables/disables the push button. The button is enabled, when the Robot is created.
@param enable: if True, the button is enabled; otherwise disabled
"""
Tools.debug("Calling setButtonEnabled() with enable = " + str(enable))
global _isButtonEnabled
_isButtonEnabled = enable
示例12: __init__
def __init__(self, id):
'''
Creates a Led instance with given ID.
IDs of the double LEDs: 0: front, 1: left side , 2: rear, 3: right side.
The following global constants are defined:
LED_FRONT = 0, LED_LEFT = 1, LED_REAR = 2, RED_RIGHT = 3.
@param id: the LED identifier
'''
self.id = id
Tools.debug("Led instance with ID " + str(id) + " created")
示例13: isButtonHit
def isButtonHit(self):
"""
Checks, if the button was ever hit or hit since the last invocation.
@return: True, if the button was hit; otherwise False
"""
global _isBtnHit
Tools.delay(1)
hit = _isBtnHit
_isBtnHit = False
return hit
示例14: run
def run(self):
Tools.debug("===>ButtonThread started")
self.isRunning = True
startTime = time.time()
while self.isRunning and (time.time() - startTime < SharedConstants.BUTTON_LONGPRESS_DURATION):
time.sleep(0.1)
if self.isRunning:
if _buttonListener != None:
_buttonListener(SharedConstants.BUTTON_LONGPRESSED)
Tools.debug("===>ButtonThread terminated")
示例15: __init__
def __init__(self, id):
'''
Creates a light sensor instance with given id.
IDs: 0: front left, 1: front right, 2: rear left, 3: rear right
The following global constants are defined:
LS_FRONT_LEFT = 0, LS_FRONT_RIGHT = 1, LS_REAR_LEFT = 2, LS_REAR_RIGHT = 3.
@param id: the LightSensor identifier
'''
self.id = id
Tools.debug("LightSensor instance with ID " + str(id) + " created")