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


Python Adafruit_MotorHAT.FORWARD属性代码示例

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


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

示例1: run

# 需要导入模块: from Adafruit_MotorHAT import Adafruit_MotorHAT [as 别名]
# 或者: from Adafruit_MotorHAT.Adafruit_MotorHAT import FORWARD [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) 
开发者ID:wroscoe,项目名称:donkey,代码行数:19,代码来源:actuator.py

示例2: test_all_motors

# 需要导入模块: from Adafruit_MotorHAT import Adafruit_MotorHAT [as 别名]
# 或者: from Adafruit_MotorHAT.Adafruit_MotorHAT import FORWARD [as 别名]
def test_all_motors(cls):
        # Note: motors are 1-indexed, range is 0-indexed, begin at 1, goes to 4
        for each_hat in cls.hat_stack:
            for each_motor in range(1, Motors.motors_on_each_Hat+1):
                try:
                    cls.hat_stack[each_hat].getMotor(each_motor).run(Adafruit_MotorHAT.FORWARD)
                    print "Testing Hat: ", each_hat._i2caddr, " and Motor: ", each_motor
                    time.sleep(1)
                    cls.hat_stack[each_hat].getMotor(each_motor).run(Adafruit_MotorHAT.RELEASE)
                except:  # Not all motors in all Hats will be available
                    print "Nonexistent motor: #{} in HAT: {}".format(each_motor, each_hat._i2caddr)

    ############################################
    # Initialize the motors on the Bot         #
    ############################################
    # Turn off all motors -- this is registered to run at program exit: atexit.register(turn_off_motors)
    # recommended for auto-disabling motors on shutdown! 
开发者ID:kikiorg,项目名称:TikiBot,代码行数:19,代码来源:Motors.py

示例3: __init__

# 需要导入模块: from Adafruit_MotorHAT import Adafruit_MotorHAT [as 别名]
# 或者: from Adafruit_MotorHAT.Adafruit_MotorHAT import FORWARD [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 
开发者ID:adafruit,项目名称:Pi_Physical_Dashboard,代码行数:21,代码来源:auto_gauge.py

示例4: close_blinds

# 需要导入模块: from Adafruit_MotorHAT import Adafruit_MotorHAT [as 别名]
# 或者: from Adafruit_MotorHAT.Adafruit_MotorHAT import FORWARD [as 别名]
def close_blinds(self):
        if 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.FORWARD,
                                                       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.FORWARD,
                                                       Adafruit_MotorHAT.MICROSTEP))
                self.l_thread.start()
            self.blinds_are_open = False 
开发者ID:jwahawis,项目名称:jwahawis.github.io,代码行数:19,代码来源:blinds.py

示例5: forward

# 需要导入模块: from Adafruit_MotorHAT import Adafruit_MotorHAT [as 别名]
# 或者: from Adafruit_MotorHAT.Adafruit_MotorHAT import FORWARD [as 别名]
def forward(self, duration):
    self.set_speed()
    self.left_motor.run(Adafruit_MotorHAT.FORWARD)
    self.right_motor.run(Adafruit_MotorHAT.FORWARD)
    time.sleep(duration)
    self.stop() 
开发者ID:PacktPublishing,项目名称:Python-Programming-with-Raspberry-Pi,代码行数:8,代码来源:robot.py

示例6: left

# 需要导入模块: from Adafruit_MotorHAT import Adafruit_MotorHAT [as 别名]
# 或者: from Adafruit_MotorHAT.Adafruit_MotorHAT import FORWARD [as 别名]
def left(self, duration):
    self.set_speed()
    self.right_motor.run(Adafruit_MotorHAT.FORWARD)
    time.sleep(duration)
    self.stop() 
开发者ID:PacktPublishing,项目名称:Python-Programming-with-Raspberry-Pi,代码行数:7,代码来源:robot.py

示例7: right

# 需要导入模块: from Adafruit_MotorHAT import Adafruit_MotorHAT [as 别名]
# 或者: from Adafruit_MotorHAT.Adafruit_MotorHAT import FORWARD [as 别名]
def right(self, duration):
    self.set_speed()
    self.left_motor.run(Adafruit_MotorHAT.FORWARD)
    time.sleep(duration)
    self.stop() 
开发者ID:PacktPublishing,项目名称:Python-Programming-with-Raspberry-Pi,代码行数:7,代码来源:robot.py

示例8: __init__

# 需要导入模块: from Adafruit_MotorHAT import Adafruit_MotorHAT [as 别名]
# 或者: from Adafruit_MotorHAT.Adafruit_MotorHAT import FORWARD [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 
开发者ID:wroscoe,项目名称:donkey,代码行数:16,代码来源:actuator.py

示例9: forward

# 需要导入模块: from Adafruit_MotorHAT import Adafruit_MotorHAT [as 别名]
# 或者: from Adafruit_MotorHAT.Adafruit_MotorHAT import FORWARD [as 别名]
def forward(self, speed, seconds=None):
        """Move forward at the specified speed (0-255).  Will start moving
        forward and return unless a seconds value is specified, in which
        case the robot will move forward 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.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() 
开发者ID:xubonnie,项目名称:velocity_drawer,代码行数:16,代码来源:Robot.py

示例10: right

# 需要导入模块: from Adafruit_MotorHAT import Adafruit_MotorHAT [as 别名]
# 或者: from Adafruit_MotorHAT.Adafruit_MotorHAT import FORWARD [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() 
开发者ID:xubonnie,项目名称:velocity_drawer,代码行数:16,代码来源:Robot.py

示例11: left

# 需要导入模块: from Adafruit_MotorHAT import Adafruit_MotorHAT [as 别名]
# 或者: from Adafruit_MotorHAT.Adafruit_MotorHAT import FORWARD [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() 
开发者ID:xubonnie,项目名称:velocity_drawer,代码行数:16,代码来源:Robot.py

示例12: turn_on

# 需要导入模块: from Adafruit_MotorHAT import Adafruit_MotorHAT [as 别名]
# 或者: from Adafruit_MotorHAT.Adafruit_MotorHAT import FORWARD [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 
开发者ID:kikiorg,项目名称:TikiBot,代码行数:11,代码来源:Motors.py

示例13: _thread_duration

# 需要导入模块: from Adafruit_MotorHAT import Adafruit_MotorHAT [as 别名]
# 或者: from Adafruit_MotorHAT.Adafruit_MotorHAT import FORWARD [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. 
开发者ID:kikiorg,项目名称:TikiBot,代码行数:13,代码来源:Motors.py

示例14: _thread_ramp

# 需要导入模块: from Adafruit_MotorHAT import Adafruit_MotorHAT [as 别名]
# 或者: from Adafruit_MotorHAT.Adafruit_MotorHAT import FORWARD [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 
开发者ID:kikiorg,项目名称:TikiBot,代码行数:14,代码来源:Motors.py

示例15: _thread_flash_randomly

# 需要导入模块: from Adafruit_MotorHAT import Adafruit_MotorHAT [as 别名]
# 或者: from Adafruit_MotorHAT.Adafruit_MotorHAT import FORWARD [as 别名]
def _thread_flash_randomly(self, shortest=0.1, longest=0.5):
        if shortest > longest:
            temp_num = longest
            longest = shortest
            shortest = temp_num
        while not self.stop_request.isSet():
            # Flash dim
            self.motor.setSpeed(255)
            self.motor.run(Adafruit_MotorHAT.FORWARD)
            percent = randint(0, 100)
            my_duration = (longest - shortest) * percent/100 + shortest
            # print "on: {}".format(my_duration)
            time.sleep(my_duration)

            # Flash bright
            self.motor.setSpeed(255/10)
            self.motor.run(Adafruit_MotorHAT.FORWARD)
            percent = randint(0, 100)
            my_duration = (longest - shortest) * percent/100 + shortest
            # print "off: {}".format(my_duration)
            time.sleep(my_duration)

        self.motor.setSpeed(255)
        self.motor.run(Adafruit_MotorHAT.FORWARD)

    #############################################
    # ThreadMotor class:                        #
    #############################################
    # This class allows the motors to all run at the same time.
    # Note that it takes the function that you want to thread, plus the function's arguments
    # This allows this class to be generalized to run any function as a thread. 
开发者ID:kikiorg,项目名称:TikiBot,代码行数:33,代码来源:Motors.py


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