本文整理汇总了Python中Tools.Tools.delay方法的典型用法代码示例。如果您正苦于以下问题:Python Tools.delay方法的具体用法?Python Tools.delay怎么用?Python Tools.delay使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Tools.Tools
的用法示例。
在下文中一共展示了Tools.delay方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: exit
# 需要导入模块: from Tools import Tools [as 别名]
# 或者: from Tools.Tools import delay [as 别名]
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"
示例2: getValue
# 需要导入模块: from Tools import Tools [as 别名]
# 或者: from Tools.Tools import delay [as 别名]
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
示例3: isButtonDown
# 需要导入模块: from Tools import Tools [as 别名]
# 或者: from Tools.Tools import delay [as 别名]
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
示例4: rightArc
# 需要导入模块: from Tools import Tools [as 别名]
# 或者: from Tools.Tools import delay [as 别名]
def rightArc(self, radius, duration=0):
"""
Starts turning to the right on an arc with given radius (in m) with preset speed.
If duration = 0, the method returns immediately, while the rotation continues.
Otherwise the method blocks until the duration is expired. Then the gear stops.
If the radius is negative, turns right backwards.
@param duration:
"""
Tools.debug("Calling Gear.rigthArc() with radius: " + str(radius))
self._checkRobot()
speed1 = (
self.speed
* (abs(radius) - SharedConstants.GEAR_AXE_LENGTH)
/ (abs(radius) + SharedConstants.GEAR_AXE_LENGTH)
)
Tools.debug("Calling rightArc(). Left speed: " + str(self.speed) + ". Right speed: " + str(speed1))
if self.state != GearState.RIGHTARC:
leftDuty = self.speedToDutyCycle(self.speed)
rightDuty = self.speedToDutyCycle(speed1)
if radius >= 0:
SharedConstants.LEFT_MOTOR_PWM[0].ChangeDutyCycle(leftDuty)
SharedConstants.LEFT_MOTOR_PWM[1].ChangeDutyCycle(0)
SharedConstants.RIGHT_MOTOR_PWM[0].ChangeDutyCycle(rightDuty)
SharedConstants.RIGHT_MOTOR_PWM[1].ChangeDutyCycle(0)
else:
SharedConstants.LEFT_MOTOR_PWM[0].ChangeDutyCycle(0)
SharedConstants.LEFT_MOTOR_PWM[1].ChangeDutyCycle(rightDuty)
SharedConstants.RIGHT_MOTOR_PWM[0].ChangeDutyCycle(0)
SharedConstants.RIGHT_MOTOR_PWM[1].ChangeDutyCycle(leftDuty)
self.state = GearState.RIGHTARC
if duration > 0:
Tools.delay(duration)
self.stop()
示例5: exit
# 需要导入模块: from Tools import Tools [as 别名]
# 或者: from Tools.Tools import delay [as 别名]
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"
示例6: run
# 需要导入模块: from Tools import Tools [as 别名]
# 或者: from Tools.Tools import delay [as 别名]
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)
示例7: isButtonHit
# 需要导入模块: from Tools import Tools [as 别名]
# 或者: from Tools.Tools import delay [as 别名]
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
示例8: getValue
# 需要导入模块: from Tools import Tools [as 别名]
# 或者: from Tools.Tools import delay [as 别名]
def getValue(self):
'''
Returns the current intensity value (0..1000).
@return: the measured light intensity
@rtype: int
'''
self._checkRobot()
Tools.delay(1)
nb = self.id
if nb == 0:
nb = 1
elif nb == 1:
nb = 0
robot = RobotInstance.getRobot()
return int(self._readADC(nb) / 255.0 * 1000 + 0.5)
示例9: backward
# 需要导入模块: from Tools import Tools [as 别名]
# 或者: from Tools.Tools import delay [as 别名]
def backward(self, duration=0):
"""
Starts the backward rotation with preset speed.
If duration = 0, the method returns immediately, while the rotation continues.
Otherwise the method blocks until the duration is expired. Then the gear stops.
@param duration if greater than 0, the method blocks for the given duration (in ms)
"""
Tools.debug("Calling Gear.backward() with speed " + str(self.speed))
self._checkRobot()
if self.state != GearState.BACKWARD:
leftDuty = self.speedToDutyCycle(self.speed + SharedConstants.GEAR_BACKWARD_SPEED_DIFF)
rightDuty = self.speedToDutyCycle(self.speed)
SharedConstants.LEFT_MOTOR_PWM[0].ChangeDutyCycle(0)
SharedConstants.LEFT_MOTOR_PWM[1].ChangeDutyCycle(leftDuty)
SharedConstants.RIGHT_MOTOR_PWM[0].ChangeDutyCycle(0)
SharedConstants.RIGHT_MOTOR_PWM[1].ChangeDutyCycle(rightDuty)
self.state = GearState.BACKWARD
if duration > 0:
Tools.delay(duration)
self.stop()
示例10: right
# 需要导入模块: from Tools import Tools [as 别名]
# 或者: from Tools.Tools import delay [as 别名]
def right(self, duration=0):
"""
Starts turning right with left motor rotating forward and
right motor rotating backward at preset speed.
If duration = 0, the method returns immediately, while the rotation continues.
Otherwise the method blocks until the duration is expired. Then the gear stops.
@param duration if greater than 0, the method blocks for the given duration (in ms)
"""
Tools.debug("Calling Gear.right()")
self._checkRobot()
if self.state != GearState.RIGHT:
duty = self.speedToDutyCycle(self.speed)
SharedConstants.LEFT_MOTOR_PWM[0].ChangeDutyCycle(duty)
SharedConstants.LEFT_MOTOR_PWM[1].ChangeDutyCycle(0)
SharedConstants.RIGHT_MOTOR_PWM[0].ChangeDutyCycle(0)
SharedConstants.RIGHT_MOTOR_PWM[1].ChangeDutyCycle(duty)
self.state = GearState.RIGHT
if duration > 0:
Tools.delay(duration)
self.stop()
示例11: __init__
# 需要导入模块: from Tools import Tools [as 别名]
# 或者: from Tools.Tools import delay [as 别名]
def __init__(self, ipAddress="", buttonEvent=None):
"""
Creates an instance of MyRobot and initalizes the GPIO.
"""
if MyRobot._myInstance != None:
raise Exception("Only one instance of MyRobot allowed")
global _isButtonEnabled, _buttonListener
_buttonListener = buttonEvent
# Use physical pin numbers
GPIO.setmode(GPIO.BOARD)
GPIO.setwarnings(False)
# Left motor
GPIO.setup(SharedConstants.P_LEFT_FORWARD, GPIO.OUT)
SharedConstants.LEFT_MOTOR_PWM[0] = GPIO.PWM(SharedConstants.P_LEFT_FORWARD, SharedConstants.MOTOR_PWM_FREQ)
SharedConstants.LEFT_MOTOR_PWM[0].start(0)
GPIO.setup(SharedConstants.P_LEFT_BACKWARD, GPIO.OUT)
SharedConstants.LEFT_MOTOR_PWM[1] = GPIO.PWM(SharedConstants.P_LEFT_BACKWARD, SharedConstants.MOTOR_PWM_FREQ)
SharedConstants.LEFT_MOTOR_PWM[1].start(0)
# Right motor
GPIO.setup(SharedConstants.P_RIGHT_FORWARD, GPIO.OUT)
SharedConstants.RIGHT_MOTOR_PWM[0] = GPIO.PWM(SharedConstants.P_RIGHT_FORWARD, SharedConstants.MOTOR_PWM_FREQ)
SharedConstants.RIGHT_MOTOR_PWM[0].start(0)
GPIO.setup(SharedConstants.P_RIGHT_BACKWARD, GPIO.OUT)
SharedConstants.RIGHT_MOTOR_PWM[1] = GPIO.PWM(SharedConstants.P_RIGHT_BACKWARD, SharedConstants.MOTOR_PWM_FREQ)
SharedConstants.RIGHT_MOTOR_PWM[1].start(0)
# IR sensors
GPIO.setup(SharedConstants.P_FRONT_LEFT, GPIO.IN, GPIO.PUD_UP)
GPIO.setup(SharedConstants.P_FRONT_CENTER, GPIO.IN, GPIO.PUD_UP)
GPIO.setup(SharedConstants.P_FRONT_RIGHT, GPIO.IN, GPIO.PUD_UP)
GPIO.setup(SharedConstants.P_LINE_LEFT, GPIO.IN, GPIO.PUD_UP)
GPIO.setup(SharedConstants.P_LINE_RIGHT, GPIO.IN, GPIO.PUD_UP)
# Establish event recognition from battery monitor
GPIO.setup(SharedConstants.P_BATTERY_MONITOR, GPIO.IN, GPIO.PUD_UP)
GPIO.add_event_detect(SharedConstants.P_BATTERY_MONITOR, GPIO.RISING, _onBatteryDown)
Tools.debug("Trying to detect I2C bus")
isSMBusAvailable = True
self._bus = None
try:
if GPIO.RPI_REVISION > 1:
self._bus = smbus.SMBus(1) # For revision 2 Raspberry Pi
Tools.debug("Found SMBus for revision 2")
else:
self._bus = smbus.SMBus(0) # For revision 1 Raspberry Pi
Tools.debug("Found SMBus for revision 1")
except:
print "No SMBus found on this robot device."
isSMBusAvailable = False
# I2C PWM chip PCM9685 for LEDs and servos
if isSMBusAvailable:
self.pwm = PWM(self._bus, SharedConstants.PWM_I2C_ADDRESS)
self.pwm.setFreq(SharedConstants.PWM_FREQ)
# clear all LEDs
for id in range(3):
self.pwm.setDuty(3 * id, 0)
self.pwm.setDuty(3 * id + 1, 0)
self.pwm.setDuty(3 * id + 2, 0)
# I2C analog extender chip
if isSMBusAvailable:
Tools.debug("Trying to detect PCF8591P I2C expander")
channel = 0
try:
self._bus.write_byte(SharedConstants.ADC_I2C_ADDRESS, channel)
self._bus.read_byte(SharedConstants.ADC_I2C_ADDRESS) # ignore reply
data = self._bus.read_byte(SharedConstants.ADC_I2C_ADDRESS)
Tools.debug("Found PCF8591P I2C expander")
except:
Tools.debug("PCF8591P I2C expander not found")
Tools.debug("Trying to detect 7-segment display")
if isSMBusAvailable:
self.displayType = "none"
try:
addr = 0x20
rc = self._bus.read_byte_data(addr, 0)
if rc != 0xA0: # returns 255 for 4tronix
raise Exception()
Tools.delay(100)
self.displayType = "didel1"
except:
Tools.debug("'didel1' display not found")
if self.displayType == "none":
try:
addr = 0x20
self._bus.write_byte_data(addr, 0x00, 0x00) # Set all of bank 0 to outputs
Tools.delay(100)
self.displayType = "4tronix"
except:
Tools.debug("'4tronix' display not found")
if self.displayType == "none":
try:
addr = 0x24
#.........这里部分代码省略.........