當前位置: 首頁>>代碼示例>>Python>>正文


Python Tools.delay方法代碼示例

本文整理匯總了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"
開發者ID:raspibrick,項目名稱:install,代碼行數:36,代碼來源:Robot.py

示例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
開發者ID:raspibrick,項目名稱:install,代碼行數:27,代碼來源:InfraredSensor.py

示例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
開發者ID:raspibrick,項目名稱:install,代碼行數:9,代碼來源:Robot.py

示例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()
開發者ID:Aegidius,項目名稱:apluraspi,代碼行數:35,代碼來源:Gear.py

示例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"
開發者ID:Aegidius,項目名稱:apluraspi,代碼行數:28,代碼來源:Robot.py

示例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)
開發者ID:Aegidius,項目名稱:apluraspi,代碼行數:10,代碼來源:Robot.py

示例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
開發者ID:raspibrick,項目名稱:install,代碼行數:12,代碼來源:Robot.py

示例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)
開發者ID:raspibrick,項目名稱:install,代碼行數:17,代碼來源:LightSensor.py

示例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()
開發者ID:Aegidius,項目名稱:apluraspi,代碼行數:22,代碼來源:Gear.py

示例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()
開發者ID:Aegidius,項目名稱:apluraspi,代碼行數:22,代碼來源:Gear.py

示例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
#.........這裏部分代碼省略.........
開發者ID:raspibrick,項目名稱:install,代碼行數:103,代碼來源:Robot.py


注:本文中的Tools.Tools.delay方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。