本文整理汇总了Python中tamproxy.Timer.reset方法的典型用法代码示例。如果您正苦于以下问题:Python Timer.reset方法的具体用法?Python Timer.reset怎么用?Python Timer.reset使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tamproxy.Timer
的用法示例。
在下文中一共展示了Timer.reset方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TestFollow
# 需要导入模块: from tamproxy import Timer [as 别名]
# 或者: from tamproxy.Timer import reset [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()
示例2: ColorRead
# 需要导入模块: from tamproxy import Timer [as 别名]
# 或者: from tamproxy.Timer import reset [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"
示例3: MotorWrite
# 需要导入模块: from tamproxy import Timer [as 别名]
# 或者: from tamproxy.Timer import reset [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()
示例4: MotorWrite
# 需要导入模块: from tamproxy import Timer [as 别名]
# 或者: from tamproxy.Timer import reset [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
示例5: GyroRead
# 需要导入模块: from tamproxy import Timer [as 别名]
# 或者: from tamproxy.Timer import reset [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()
示例6: TestWallFollow
# 需要导入模块: from tamproxy import Timer [as 别名]
# 或者: from tamproxy.Timer import reset [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)
示例7: EncoderRead
# 需要导入模块: from tamproxy import Timer [as 别名]
# 或者: from tamproxy.Timer import reset [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()
'''
示例8: PID
# 需要导入模块: from tamproxy import Timer [as 别名]
# 或者: from tamproxy.Timer import reset [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();
示例9: EncoderRead
# 需要导入模块: from tamproxy import Timer [as 别名]
# 或者: from tamproxy.Timer import reset [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
示例10: AnalogRead
# 需要导入模块: from tamproxy import Timer [as 别名]
# 或者: from tamproxy.Timer import reset [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
示例11: Blink
# 需要导入模块: from tamproxy import Timer [as 别名]
# 或者: from tamproxy.Timer import reset [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)
示例12: SwitchRead
# 需要导入模块: from tamproxy import Timer [as 别名]
# 或者: from tamproxy.Timer import reset [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()
示例13: ColorRead
# 需要导入模块: from tamproxy import Timer [as 别名]
# 或者: from tamproxy.Timer import reset [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
示例14: Bot
# 需要导入模块: from tamproxy import Timer [as 别名]
# 或者: from tamproxy.Timer import reset [as 别名]
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()
示例15: AnalogWrite
# 需要导入模块: from tamproxy import Timer [as 别名]
# 或者: from tamproxy.Timer import reset [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)