当前位置: 首页>>代码示例>>Python>>正文


Python Timer.millis方法代码示例

本文整理汇总了Python中tamproxy.Timer.millis方法的典型用法代码示例。如果您正苦于以下问题:Python Timer.millis方法的具体用法?Python Timer.millis怎么用?Python Timer.millis使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在tamproxy.Timer的用法示例。


在下文中一共展示了Timer.millis方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: GyroRead

# 需要导入模块: from tamproxy import Timer [as 别名]
# 或者: from tamproxy.Timer import millis [as 别名]
class GyroRead(SyncedSketch):

    # Set me!
    ss_pin = 10

    def setup(self):
        self.gyro = Gyro(self.tamp, self.ss_pin, integrate=True)
        self.timer = Timer()
        self.cali_timer = Timer()
        self.calibration = 0.0
        self.calibrated = False

    def loop(self):
        if self.timer.millis() > 100:
            self.timer.reset()
            # Valid gyro status is [0,1], see datasheet on ST1:ST0 bits
            print "{:6f}, raw: 0x{:08x} = 0b{:032b}".format(self.gyro.val, self.gyro.raw, self.gyro.raw)
        # Janky autocalibration scheme
        if not self.calibrated and self.cali_timer.millis() > 3000:
            drift = self.gyro.val / (self.cali_timer.millis() / 1000.0)
            # Arbitrary calibration tolerance of 0.1 deg/sec
            if abs(drift) > 0.1:
                self.calibration += drift
                print "Calibration:", self.calibration
                self.gyro.calibrate_bias(self.calibration)
            else:
                print "Calibration complete:", self.calibration
                self.calibrated = True
            self.gyro.reset_integration()
            self.cali_timer.reset()
开发者ID:mitchgu,项目名称:TAMProxy-pyHost,代码行数:32,代码来源:gyro_read.py

示例2: TestWallFollow

# 需要导入模块: from tamproxy import Timer [as 别名]
# 或者: from tamproxy.Timer import millis [as 别名]
class TestWallFollow(SyncedSketch):
    
    def setup(self):
        self.left = Motor(self.tamp, 5, 4)
        self.right = Motor(self.tamp, 2, 3)
        hugs = Motor(self.tamp, 8, 9)
        ir0 = LRIR(self.tamp,14)
        ir1 = LRIR(self.tamp,15)
        ir2 = LRIR(self.tamp,16)
        ir3 = LRIR(self.tamp,17)
        self.movement = WallFollow(self.left, self.right, Timer(), ir0, ir1, ir2, ir3)

        self.timer = Timer()
        self.wintimer = Timer()

    def loop(self):
        if self.wintimer.millis() < 19600:
            if self.timer.millis() > 100:
                self.timer.reset()
                print self.movement.distance()

            # Intended behavior: bot will follow wall
            # IR return distance, 50 speed


                self.movement.followWall(self.movement.distance(),-FORWARD_SPEED)
        elif self.wintimer.millis() < 19900:
            self.left.write( 0, 145)
            self.right.write( 1, 145)
        else:
            self.wintimer.reset()
            self.left.write(0,0)
            self.right.write(0,0)
开发者ID:pravinas,项目名称:et-maslab-2016,代码行数:35,代码来源:Test_Wall_Follow.py

示例3: MotorWrite

# 需要导入模块: from tamproxy import Timer [as 别名]
# 或者: from tamproxy.Timer import millis [as 别名]
class MotorWrite(SyncedSketch):

    def setup(self):
        self.motor1 = Motor(self.tamp, 2, 3)
        self.motor1.write(1,0)
        self.motor2 = Motor(self.tamp, 5, 4)
        self.motor2.write(1,0)
        self.delta = 1
        self.motorval = 70
        self.timer = Timer()
        self.steps = 0

    def loop(self):
        if self.steps < 2:
            if (self.timer.millis() > 5000):
                self.timer.reset()
                self.motorval = -self.motorval
                self.motor1.write(self.motorval>0, abs(self.motorval))
                self.motor2.write(self.motorval>0, abs(self.motorval))
                self.steps += 1
        elif self.steps < 5:
            if (self.timer.millis() > 5000):
                self.timer.reset()
                self.motorval = -self.motorval
                self.motor1.write(self.motorval>0, abs(self.motorval))
                self.motor2.write(self.motorval<0, abs(self.motorval))
                self.steps += 1
        else:
            self.motor1.write(0, 0)
            self.motor2.write(0, 0)
            self.stop()
开发者ID:pravinas,项目名称:et-maslab-2016,代码行数:33,代码来源:test_motor.py

示例4: SwitchRead

# 需要导入模块: from tamproxy import Timer [as 别名]
# 或者: from tamproxy.Timer import millis [as 别名]
class SwitchRead(SyncedSketch):

    def setup(self):
        self.switch = A(DigitalInput(self.tamp, 23))
        self.timer = Timer()
        self.ttt = Timer()

    def loop(self):
        if self.timer.millis() > 100:
            self.timer.reset()
            print self.switch.read()
        if self.ttt.millis() > 8000:
        	self.stop()
开发者ID:pravinas,项目名称:et-maslab-2016,代码行数:15,代码来源:test_switch.py

示例5: TestFollow

# 需要导入模块: from tamproxy import Timer [as 别名]
# 或者: from tamproxy.Timer import millis [as 别名]
class TestFollow(SyncedSketch):

    def setup(self):
        self.ttt = Timer()
        timer = Timer()
        stepTimer = Timer()
        wallFollowTimer = Timer()
        leftMotor = Motor(self.tamp, LEFT_DRIVE_CONTROLLER_DIRECTION, LEFT_DRIVE_CONTROLLER_PWM)
        rightMotor = Motor(self.tamp, RIGHT_DRIVE_CONTROLLER_DIRECTION, RIGHT_DRIVE_CONTROLLER_PWM)
        intakeMotor = Motor(self.tamp, HUGS_MOTOR_CONTROLLER_DIRECTION, HUGS_MOTOR_CONTROLLER_PWM)
        irFL = LRIR(self.tamp, LONG_DISTANCE_IR_FL)
        irFR = LRIR(self.tamp, LONG_DISTANCE_IR_FR)
        irBL = LRIR(self.tamp, LONG_DISTANCE_IR_BL)
        irBR = LRIR(self.tamp, LONG_DISTANCE_IR_BR)
        self.wallFollow = WallFollow(leftMotor, rightMotor, wallFollowTimer, irFL, irFR, irBL, irBR)
        blockSwitch = DigitalInput(self.tamp, BLOCK_LIMIT_SWITCH)
        self.blockSwitch = DigitalInput(self.tamp, 21)
        self.follow = FollowModule(timer, leftMotor, rightMotor, intakeMotor, self.wallFollow, FORWARD_SPEED, self.blockSwitch)
        self.follow.start()

    def loop(self):
        response = self.follow.run()
        if self.ttt.millis() > 100:
            self.ttt.reset()
            print self.wallFollow.distance()
        if response != MODULE_FOLLOW:
            self.stop()
开发者ID:pravinas,项目名称:et-maslab-2016,代码行数:29,代码来源:test_follow.py

示例6: EncoderRead

# 需要导入模块: from tamproxy import Timer [as 别名]
# 或者: from tamproxy.Timer import millis [as 别名]
class EncoderRead(SyncedSketch):

    encoderPins = 28, 27
    motorPwm = 6 #green
    motorDir = 7 #yellow

    def setup(self):
        self.encoder = Encoder(self.tamp, *self.encoderPins, continuous=True)
        self.motor = Motor(self.tamp, self.motorDir, self.motorPwm)
        self.miscTimer = Timer()
        self.timer = Timer()
        self.rotations = 0
        self.lastRot = 0
        self.motor.write(0, 100)

    def loop(self):
        if self.timer.millis() > 100:
            print "enc", self.encoder.val
            self.timer.reset()
        if self.encoder.val > 5.0 * 3200:
            print "Stopped at", self.encoder.val
            self.motor.write(1,0)
            self.stop()

        '''
开发者ID:pravinas,项目名称:et-maslab-2016,代码行数:27,代码来源:test_encoder.py

示例7: ColorRead

# 需要导入模块: from tamproxy import Timer [as 别名]
# 或者: from tamproxy.Timer import millis [as 别名]
class ColorRead(SyncedSketch):

    def setup(self):
        self.color = Color(self.tamp,
                           integrationTime=Color.INTEGRATION_TIME_101MS,
                           gain=Color.GAIN_1X)
        self.timer = Timer()

    def loop(self):
        if self.timer.millis() > 100:
            self.timer.reset()
            print "~~~~~~~~~"
            print self.color.r, self.color.g, self.color.b, self.color.c
            #print self.calibrate_colors(self.color.r, self.color.g, self.color.b)
            #print self.color.colorTemp, self.color.lux
            print self.whatColorIsThis(self.color.r, self.color.g, self.color.b)

    def calibrate_colors(self, r, g, b):
        return (int(r / 0.90), int(g / 0.45), int(b / 0.40))

    def whatColorIsThis(self, r, g, b):
        if r > 1.6*g and r > 1.6*b:
            return "Red"
        elif g > r and g > 1.2*b:
            return "Green"
        else:
            return "No Block"
开发者ID:pravinas,项目名称:et-maslab-2016,代码行数:29,代码来源:test_color.py

示例8: MotorWrite

# 需要导入模块: from tamproxy import Timer [as 别名]
# 或者: from tamproxy.Timer import millis [as 别名]
class MotorWrite(Sketch):

    def setup(self):
        #self.motor = Motor(self.tamp, 2, 3)
        #self.motor.write(1,0)
        self.delta = 1
        self.motorval = 0
        self.timer = Timer()

        self.pipe_path = "./motorL"
        if not os.path.exists(pipe_path):
            os.mkfifo(pipe_path)
        # Open the fifo. We need to open in non-blocking mode or it will stalls until
        # someone opens it for writting
        pipe_fd = os.open(pipe_path, os.O_RDONLY)


    def loop(self):
        if (self.timer.millis() > 10):
            message = os.read(pipe_fd,100)
            if message:
                print("Received: '%s'" % message)
            self.timer.reset()
            if abs(self.motorval) == 255: self.delta = -self.delta
            self.motorval += self.delta
开发者ID:dmayo,项目名称:maslab-2016-team-10,代码行数:27,代码来源:motor_write_pipe.py

示例9: AnalogRead

# 需要导入模块: from tamproxy import Timer [as 别名]
# 或者: from tamproxy.Timer import millis [as 别名]
class AnalogRead(SyncedSketch):

    screen = pygame.display.set_mode((300, 300))

    v_max = 1
    points = []
    distances = [[x, []] for x in xrange(2, 16)]
    distances = dict(distances)
    data = []
    set = 0

    def setup(self):
        self.sensor_array = Ir_array(self.tamp, 16, 15, 14, 40, 11, 10)
        # self.testpin = AnalogInput(self.tamp, self.adc_pin) #these
        self.timer = Timer() #this, too.

    def loop(self):
        if self.timer.millis() > 100:
            self.screen.fill((0, 0, 0))
            events =  pygame.event.get()
            self.sensor_array.update()

            for x in xrange(6):
                value = self.sensor_array.ir_value[x]
                print value
                if value != float('inf'):
                    pygame.draw.rect(self.screen, (255, 255, 255), (10*x, 300-value*10, 5, 5))
            pygame.display.flip()
开发者ID:dmayo,项目名称:maslab-2016-team-10,代码行数:30,代码来源:analog_read.py

示例10: PID

# 需要导入模块: from tamproxy import Timer [as 别名]
# 或者: from tamproxy.Timer import millis [as 别名]
class PID(SyncedSketch):
    def setup(self):
        #self.motorLeft = Motor(self.tamp, 21, 20)
        #self.motorRight = Motor(self.tamp, 23, 22)
        self.motorLeft = Motor(self.tamp, 20, 21)
        self.motorRight = Motor(self.tamp, 22, 23)
        self.motorLeft.write(1,0)
        self.motorRight.write(1,0)

        left_pins = 6,5
        right_pins = 3,4
        # Encoder doesn't work when after gyro
        self.encoderLeft = Encoder(self.tamp, 6,5, continuous=False)
        self.encoderRight = Encoder(self.tamp, 3,4, continuous=True)
        # TODO: set encoder to 0
        self.timer = Timer()
        self.gyro = Gyro(self.tamp, 10)

        self.P = 5
        self.I = 0 # should be negative
        self.D = 0
        self.dT = .03
        self.motorval = 25 #50
        self.last_diff = 0
        self.integral = 0
        self.desired = self.gyro.val #+ 45 # to drive in a straight line
        self.encoderLeft.start_continuous()
        self.encoderRight.start_continuous()

    def loop(self):
        # Set encoder to 0 after turning. 
        # To turn in place, set bias (i.e. motorval to 0)
        if self.timer.millis() > self.dT*1000:
            self.timer.reset()
            gyroVal = self.gyro.val
            print gyroVal, self.gyro.stxatus
            # TODO: encoderVal
            estimated = gyroVal # TODO: calculate estimated with encoder
            diff = self.desired-estimated
            self.integral += diff*self.dT
            derivative = (diff - self.last_diff)/self.dT
            power = self.P*diff + self.I*self.integral + self.D*derivative # NOTE: Cap self.D*derivative, use as timeout
            power = min(40, power)
            self.motorLeft.write((self.motorval + power) > 0, min(255, abs(self.motorval + power)))
            self.motorRight.write((self.motorval - power) > 0, min(255, abs(self.motorval - power)))
            print "EncoderLeft: " + str(self.encoderLeft.val)
            print "EncoderRight: " + str(self.encoderRight.val)

    def stop(self):
        self.motorLeft.write(1, 0)
        self.motorRight.write(1, 0)
        # print self.motorval
        super(PID,self).stop()
        self.tamp.clear_devices();
开发者ID:Pdgraham,项目名称:MASLAB-2016-Team-2,代码行数:56,代码来源:PID.py

示例11: Blink

# 需要导入模块: from tamproxy import Timer [as 别名]
# 或者: from tamproxy.Timer import millis [as 别名]
class Blink(Sketch):

    def setup(self):
        self.led = DigitalOutput(self.tamp, 13)
        self.led_timer = Timer()
        self.led_state = False

    def loop(self):
        if self.led_timer.millis() > 1000:
            self.led_timer.reset()
            self.led_state = not self.led_state
            self.led.write(self.led_state)
开发者ID:mitchgu,项目名称:TAMProxy-pyHost,代码行数:14,代码来源:blink.py

示例12: EncoderRead

# 需要导入模块: from tamproxy import Timer [as 别名]
# 或者: from tamproxy.Timer import millis [as 别名]
class EncoderRead(SyncedSketch):

    pins = 5, 6

    def setup(self):
        self.encoder = Encoder(self.tamp, *self.pins, continuous=True)
        self.timer = Timer()

    def loop(self):
        if self.timer.millis() > 100:
            self.timer.reset()
            print self.encoder.val
开发者ID:pravinas,项目名称:TAMProxy-pyHost,代码行数:14,代码来源:encoder_read.py

示例13: AnalogRead

# 需要导入模块: from tamproxy import Timer [as 别名]
# 或者: from tamproxy.Timer import millis [as 别名]
class AnalogRead(SyncedSketch):

    adc_pin = 0

    def setup(self):
        self.testpin = AnalogInput(self.tamp, self.adc_pin)
        self.timer = Timer()

    def loop(self):
        if self.timer.millis() > 100:
            self.timer.reset()
            print self.testpin.val
开发者ID:mitchgu,项目名称:TAMProxy-pyHost,代码行数:14,代码来源:analog_read.py

示例14: ColorRead

# 需要导入模块: from tamproxy import Timer [as 别名]
# 或者: from tamproxy.Timer import millis [as 别名]
class ColorRead(SyncedSketch):

    def setup(self):
        self.color = Color(self.tamp,
                           integrationTime=Color.INTEGRATION_TIME_101MS,
                           gain=Color.GAIN_1X)
        self.timer = Timer()

    def loop(self):
        if self.timer.millis() > 100:
            self.timer.reset()
            print self.color.r, self.color.g, self.color.b, self.color.c
            print self.color.colorTemp, self.color.lux
开发者ID:mitchgu,项目名称:TAMProxy-pyHost,代码行数:15,代码来源:color_read.py

示例15: AnalogWrite

# 需要导入模块: from tamproxy import Timer [as 别名]
# 或者: from tamproxy.Timer import millis [as 别名]
class AnalogWrite(Sketch):

    PWM_PIN = 3

    def setup(self):
        self.pwm = AnalogOutput(self.tamp, self.PWM_PIN)
        self.pwm_value = 0
        self.pwm_timer = Timer()

    def loop(self):
        if self.pwm_timer.millis() > 10:
            self.pwm_timer.reset()
            self.pwm_value = (self.pwm_value + 1) % 256
            self.pwm.write(self.pwm_value)
开发者ID:mitchgu,项目名称:TAMProxy-pyHost,代码行数:16,代码来源:analog_write.py


注:本文中的tamproxy.Timer.millis方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。