本文整理汇总了Python中Adafruit_MotorHAT.Adafruit_MotorHAT.BACKWARD属性的典型用法代码示例。如果您正苦于以下问题:Python Adafruit_MotorHAT.BACKWARD属性的具体用法?Python Adafruit_MotorHAT.BACKWARD怎么用?Python Adafruit_MotorHAT.BACKWARD使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类Adafruit_MotorHAT.Adafruit_MotorHAT
的用法示例。
在下文中一共展示了Adafruit_MotorHAT.BACKWARD属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: run
# 需要导入模块: from Adafruit_MotorHAT import Adafruit_MotorHAT [as 别名]
# 或者: from Adafruit_MotorHAT.Adafruit_MotorHAT import BACKWARD [as 别名]
def run(self, speed):
'''
Update the speed of the motor where 1 is full forward and
-1 is full backwards.
'''
if speed > 1 or speed < -1:
raise ValueError( "Speed must be between 1(forward) and -1(reverse)")
self.speed = speed
self.throttle = int(dk.utils.map_range(abs(speed), -1, 1, -255, 255))
if speed > 0:
self.motor.run(self.FORWARD)
else:
self.motor.run(self.BACKWARD)
self.motor.setSpeed(self.throttle)
示例2: __init__
# 需要导入模块: from Adafruit_MotorHAT import Adafruit_MotorHAT [as 别名]
# 或者: from Adafruit_MotorHAT.Adafruit_MotorHAT import BACKWARD [as 别名]
def __init__(self, motor_id, invert='False'):
"""Create an instance of the auto stepper motor. Must provide a motor_id
parameter with the motor ID from the motor HAT (sent as a string). Can
optionally provide:
- invert: Set to True to reverse the forward/backward direction. Set
this if the motor spins the wrong way when going forward/backward.
"""
# Create stepper motor driver.
self._mh = Adafruit_MotorHAT()
self._stepper = self._mh.getStepper(600, int(motor_id))
self._forward = Adafruit_MotorHAT.FORWARD
self._backward = Adafruit_MotorHAT.BACKWARD
if self.parse_bool(invert):
# Invert forward/backward directions
self._forward, self._backward = self._backward, self._forward
# Rotate forward 600 times to get back into a known 0/home state.
for i in range(600):
self._stepper.oneStep(self._backward, Adafruit_MotorHAT.DOUBLE)
self._steps = 0
示例3: open_blinds
# 需要导入模块: from Adafruit_MotorHAT import Adafruit_MotorHAT [as 别名]
# 或者: from Adafruit_MotorHAT.Adafruit_MotorHAT import BACKWARD [as 别名]
def open_blinds(self):
if not self.blinds_are_open:
if not self.r_thread.isAlive():
self.r_thread = threading.Thread(target=self.stepper_worker,
args=(self.r_blind,
2500,
Adafruit_MotorHAT.BACKWARD,
Adafruit_MotorHAT.MICROSTEP))
self.r_thread.start()
if not self.l_thread.isAlive():
self.l_thread = threading.Thread(target=self.stepper_worker,
args=(self.l_blind,
2100,
Adafruit_MotorHAT.BACKWARD,
Adafruit_MotorHAT.MICROSTEP))
self.l_thread.start()
self.blinds_are_open = True
示例4: reverse
# 需要导入模块: from Adafruit_MotorHAT import Adafruit_MotorHAT [as 别名]
# 或者: from Adafruit_MotorHAT.Adafruit_MotorHAT import BACKWARD [as 别名]
def reverse(self, duration):
self.set_speed()
self.left_motor.run(Adafruit_MotorHAT.BACKWARD)
self.right_motor.run(Adafruit_MotorHAT.BACKWARD)
time.sleep(duration)
self.stop()
示例5: __init__
# 需要导入模块: from Adafruit_MotorHAT import Adafruit_MotorHAT [as 别名]
# 或者: from Adafruit_MotorHAT.Adafruit_MotorHAT import BACKWARD [as 别名]
def __init__(self, motor_num):
from Adafruit_MotorHAT import Adafruit_MotorHAT, Adafruit_DCMotor
import atexit
self.FORWARD = Adafruit_MotorHAT.FORWARD
self.BACKWARD = Adafruit_MotorHAT.BACKWARD
self.mh = Adafruit_MotorHAT(addr=0x60)
self.motor = self.mh.getMotor(motor_num)
self.motor_num = motor_num
atexit.register(self.turn_off_motors)
self.speed = 0
self.throttle = 0
示例6: backward
# 需要导入模块: from Adafruit_MotorHAT import Adafruit_MotorHAT [as 别名]
# 或者: from Adafruit_MotorHAT.Adafruit_MotorHAT import BACKWARD [as 别名]
def backward(self, speed, seconds=None):
"""Move backward at the specified speed (0-255). Will start moving
backward and return unless a seconds value is specified, in which
case the robot will move backward for that amount of time and then stop.
"""
# Set motor speed and move both backward.
self._left_speed(speed)
self._right_speed(speed)
self._left.run(Adafruit_MotorHAT.BACKWARD)
self._right.run(Adafruit_MotorHAT.BACKWARD)
# If an amount of time is specified, move for that time and then stop.
if seconds is not None:
time.sleep(seconds)
self.stop()
示例7: right
# 需要导入模块: from Adafruit_MotorHAT import Adafruit_MotorHAT [as 别名]
# 或者: from Adafruit_MotorHAT.Adafruit_MotorHAT import BACKWARD [as 别名]
def right(self, speed, seconds=None):
"""Spin to the right at the specified speed. Will start spinning and
return unless a seconds value is specified, in which case the robot will
spin for that amount of time and then stop.
"""
# Set motor speed and move both forward.
self._left_speed(speed)
self._right_speed(speed)
self._left.run(Adafruit_MotorHAT.FORWARD)
self._right.run(Adafruit_MotorHAT.BACKWARD)
# If an amount of time is specified, move for that time and then stop.
if seconds is not None:
time.sleep(seconds)
self.stop()
示例8: left
# 需要导入模块: from Adafruit_MotorHAT import Adafruit_MotorHAT [as 别名]
# 或者: from Adafruit_MotorHAT.Adafruit_MotorHAT import BACKWARD [as 别名]
def left(self, speed, seconds=None):
"""Spin to the left at the specified speed. Will start spinning and
return unless a seconds value is specified, in which case the robot will
spin for that amount of time and then stop.
"""
# Set motor speed and move both forward.
self._left_speed(speed)
self._right_speed(speed)
self._left.run(Adafruit_MotorHAT.BACKWARD)
self._right.run(Adafruit_MotorHAT.FORWARD)
# If an amount of time is specified, move for that time and then stop.
if seconds is not None:
time.sleep(seconds)
self.stop()
示例9: turn_on
# 需要导入模块: from Adafruit_MotorHAT import Adafruit_MotorHAT [as 别名]
# 或者: from Adafruit_MotorHAT.Adafruit_MotorHAT import BACKWARD [as 别名]
def turn_on(self, speed=255, forwards=True):
self.motor.setSpeed(speed)
# print "Effect turned on: {} going: {}".format(self.name, "forwards" if forwards else "backwards")
self.motor.run(Adafruit_MotorHAT.FORWARD if forwards else Adafruit_MotorHAT.BACKWARD)
############################################
# Turn motor off #
############################################
# Treat motor as output
示例10: _thread_duration
# 需要导入模块: from Adafruit_MotorHAT import Adafruit_MotorHAT [as 别名]
# 或者: from Adafruit_MotorHAT.Adafruit_MotorHAT import BACKWARD [as 别名]
def _thread_duration(self, duration, forwards=True):
self.motor.setSpeed(255)
self.motor.run(Adafruit_MotorHAT.FORWARD if forwards else Adafruit_MotorHAT.BACKWARD)
time.sleep(duration)
self.motor.run(Adafruit_MotorHAT.RELEASE)
############################################
# Ramp the motor speed up -- like a fade #
############################################
# Slowly raise or lower the speed of the motor.
# The wait is simply how long the loop takes.
示例11: _thread_ramp
# 需要导入模块: from Adafruit_MotorHAT import Adafruit_MotorHAT [as 别名]
# 或者: from Adafruit_MotorHAT.Adafruit_MotorHAT import BACKWARD [as 别名]
def _thread_ramp(self, ramp_up=True, forwards=True, step=2):
for i in range(0 if ramp_up else 255, 255 if ramp_up else -1, step if ramp_up else (-step)):
self.motor.setSpeed(i)
self.motor.run(Adafruit_MotorHAT.FORWARD if forwards else Adafruit_MotorHAT.BACKWARD)
if not ramp_up:
self.motor.run(Adafruit_MotorHAT.RELEASE)
############################################
# Flash the motor randomly #
############################################
# Pick random delay times until it exceeds duration
# Note: I cheated - the last flash rounds up to duration
示例12: runMotor
# 需要导入模块: from Adafruit_MotorHAT import Adafruit_MotorHAT [as 别名]
# 或者: from Adafruit_MotorHAT.Adafruit_MotorHAT import BACKWARD [as 别名]
def runMotor(motorIndex, direction):
motor = mh.getMotor(motorIndex+1)
if direction == 1:
motor.setSpeed(drivingSpeed)
motor.run(Adafruit_MotorHAT.FORWARD)
if direction == -1:
motor.setSpeed(drivingSpeed)
motor.run(Adafruit_MotorHAT.BACKWARD)
if direction == 0.5:
motor.setSpeed(128)
motor.run(Adafruit_MotorHAT.FORWARD)
if direction == -0.5:
motor.setSpeed(128)
motor.run(Adafruit_MotorHAT.BACKWARD)
示例13: step
# 需要导入模块: from Adafruit_MotorHAT import Adafruit_MotorHAT [as 别名]
# 或者: from Adafruit_MotorHAT.Adafruit_MotorHAT import BACKWARD [as 别名]
def step(self, l_value, r_value):
"""for debug and manual operation"""
if l_value > 0:
self.stepper_worker(self.l_blind, l_value, Adafruit_MotorHAT.FORWARD, Adafruit_MotorHAT.MICROSTEP)
else:
self.stepper_worker(self.l_blind, l_value*-1, Adafruit_MotorHAT.BACKWARD, Adafruit_MotorHAT.MICROSTEP)
if r_value > 0:
self.stepper_worker(self.r_blind, r_value, Adafruit_MotorHAT.FORWARD, Adafruit_MotorHAT.MICROSTEP)
else:
self.stepper_worker(self.r_blind, r_value*-1, Adafruit_MotorHAT.BACKWARD, Adafruit_MotorHAT.MICROSTEP)
示例14: reverse
# 需要导入模块: from Adafruit_MotorHAT import Adafruit_MotorHAT [as 别名]
# 或者: from Adafruit_MotorHAT.Adafruit_MotorHAT import BACKWARD [as 别名]
def reverse(self, duration):
self.set_speed()
self.left_motor.run(Adafruit_MotorHAT.BACKWARD)
self.right_motor.run(Adafruit_MotorHAT.BACKWARD)
time.sleep(duration)
self.stop()
示例15: gof
# 需要导入模块: from Adafruit_MotorHAT import Adafruit_MotorHAT [as 别名]
# 或者: from Adafruit_MotorHAT.Adafruit_MotorHAT import BACKWARD [as 别名]
def gof():
#mBR.run(Adafruit_MotorHAT.BACKWARD)
#mBL.run(Adafruit_MotorHAT.BACKWARD)
mFL.run(Adafruit_MotorHAT.FORWARD)
mFR.run(Adafruit_MotorHAT.FORWARD)
#mBR.setSpeed(200)
#mBL.setSpeed(200)
mFR.setSpeed(200)
mFL.setSpeed(200)