• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python tamproxy.Timer类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: TestFollow

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,代码行数:27,代码来源:test_follow.py


示例2: ColorRead

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,代码行数:27,代码来源:test_color.py


示例3: setup

    def setup(self):
        self.state = self.STRAIGHT_STATE


        self.leftMotor = Motor(self.tamp, LEFT_MOTOR_DIRECTION, LEFT_MOTOR_PWM)
    
        self.rightMotor = Motor(self.tamp, RIGHT_MOTOR_DIRECTION, RIGHT_MOTOR_PWM)

    

        self.bumper_RF = DigitalInput(self.tamp, BUMP_SENSOR_R_FRONT)

        self.bumper_LF = DigitalInput(self.tamp, BUMP_SENSOR_L_FRONT)

        self.bumper_RS = DigitalInput(self.tamp, BUMP_SENSOR_R_SIDE)

        self.bumper_LS = DigitalInput(self.tamp, BUMP_SENSOR_L_SIDE)


        self.comp_timer = Timer()

        self.straight_timer = Timer()

        self.reverse_timer = Timer()

        self.turn_timer = Timer()

        self.bump_timer = Timer()


        self.turn_direction = LEFT
        self.turn_pwm = 50
开发者ID:amyliu345,项目名称:maslab,代码行数:32,代码来源:main.py


示例4: MotorWrite

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,代码行数:25,代码来源:motor_write_pipe.py


示例5: EncoderRead

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,代码行数:25,代码来源:test_encoder.py


示例6: PID

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,代码行数:54,代码来源:PID.py


示例7: setup

    def setup(self):
        self.timer = Timer()
        self.ttt  = Timer()
        self.timeout = 5000
        # Motor object representing the conveyor belt motor.
        self.conveyorMotor = Motor(self.tamp, 7, 6)
        # Encoder object for the conveyor belt motor.
        self.conveyorEncoder = Encoder(self.tamp, 28, 27)
        self.blocksPickedUp = 0

        self.startThing()
开发者ID:pravinas,项目名称:et-maslab-2016,代码行数:11,代码来源:test_belt.py


示例8: AnalogRead

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,代码行数:12,代码来源:analog_read.py


示例9: setup

    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()
开发者ID:pravinas,项目名称:et-maslab-2016,代码行数:12,代码来源:Test_Wall_Follow.py


示例10: EncoderRead

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,代码行数:12,代码来源:encoder_read.py


示例11: Blink

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,代码行数:12,代码来源:blink.py


示例12: SwitchRead

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,代码行数:13,代码来源:test_switch.py


示例13: ColorRead

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,代码行数:13,代码来源:color_read.py


示例14: Bot

class Bot(SyncedSketch):

    def setup(self):
        self.timer = Timer()
        self.utils = Utils(time.time(),180) #start time, total game time
        self.sensors = Sensors(self.tamp)
        self.actuators = Actuators(self.tamp)
        self.motorController= MotorController(self.sensors,self.actuators)
        self.myState = startState(self.sensors, self.actuators, self.motorController, self.timer, self.utils)

    def loop(self):
        self.myState=self.myState.run() #run current state and return next state
        self.timer.reset()
开发者ID:dmayo,项目名称:maslab-2016-team-10,代码行数:13,代码来源:bot.py


示例15: GyroRead

class GyroRead(SyncedSketch):

    # Set me!
    ss_pin = 10

    def setup(self):
        self.gyro = Gyro(self.tamp, self.ss_pin, integrate=True)
        self.timer = Timer()

    def loop(self):
        if self.timer.millis() > 100:
            self.timer.reset()
            # Valid gyro status is [0,1], see datasheet on ST1:ST0 bits
            print self.gyro.val, self.gyro.status
开发者ID:pravinas,项目名称:et-maslab-2016,代码行数:14,代码来源:test_gyro.py


示例16: AnalogWrite

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,代码行数:14,代码来源:analog_write.py


示例17: MotorWrite

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()

    def loop(self):
        if self.timer.millis() > 10:
            self.timer.reset()
            if abs(self.motorval) == 255:
                self.delta = -self.delta
            self.motorval += self.delta
            self.motor.write(self.motorval > 0, abs(self.motorval))
开发者ID:mitchgu,项目名称:TAMProxy-pyHost,代码行数:15,代码来源:motor_write.py


示例18: IRRead

class IRRead(SyncedSketch):

    adc_pin = 4

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

    def loop(self):
        if self.timer.millis() > 100:
            self.timer.reset()
            # if self.testpin.distInches != "far" :
            print str(self.testpin.distTicks)
            print str(self.testpin.distInches)
            print "---"
开发者ID:skrub-wreckers,项目名称:TAMProxy-pyHost,代码行数:15,代码来源:ir_read.py


示例19: TestIR

class TestIR(SyncedSketch):
    def setup(self):
        self.ir = IR(self.tamp, 23)
        self.sum = 0
        self.timer = Timer()
        self.timestep = 0

    def loop(self):
        if (self.timer.millis() > 100):
            self.timer.reset()
            #self.sum += self.ir.read_ir()
            self.timestep += 1
            print self.timestep
            print "raw val:",self.ir.val
            print "distance:",self.ir.read_ir()
开发者ID:pravinas,项目名称:TAMProxy-pyHost,代码行数:15,代码来源:test_short_range_ir.py


示例20: BeltMove

class BeltMove(SyncedSketch):

    def setup(self):
        # Motor object representing the conveyor belt motor.
        self.limSwitch = DigitalInput(self.tamp, 23)
        self.conveyorMotor = Motor(self.tamp, 7, 6)
        self.timer = Timer()

    def loop(self):
        if self.timer.millis() > 100:
        	self.timer.reset()
	    	if self.limSwitch.val:
	    		self.conveyorMotor.write(UP, 0)
                        self.stop()
	    	else:
	    		self.conveyorMotor.write(DOWN, 80)
开发者ID:pravinas,项目名称:et-maslab-2016,代码行数:16,代码来源:adjust_belt.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python tangelo.content_type函数代码示例发布时间:2022-05-27
下一篇:
Python utf8.get_letters函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap