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


Python Motor.arm方法代码示例

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


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

示例1: __init__

# 需要导入模块: from motor import Motor [as 别名]
# 或者: from motor.Motor import arm [as 别名]
class FlightController:

    def __init__(self, mode):
        self.mode = mode
        adafruitLoader = AdafruitLoader(self.mode)
        self.pwm = adafruitLoader.getPwmModule()
        self.bno = adafruitLoader.getBNO055Module()

        if not self.bno.begin():
            raise RuntimeError('Failed to initialize BNO055! Is the sensor connected?')

        # Set frequency to 60hz, good for servos.
        self.pwm.set_pwm_freq(60)

        self.motor1 = Motor(0, self.pwm, 276,457)
        self.motor2 = Motor(1, self.pwm, 276,457)
        self.motor3 = Motor(14, self.pwm, 276,457)
        self.motor4 = Motor(15, self.pwm, 276,457)

    def getPWMValueFromNanoseconds(self,nanoseconds):
        print(nanoseconds)
        pwmValue = nanoseconds / (1000000.0/4096.0/60.0)
        return int(round(pwmValue))

    def armMotors(self):
        print('Arming motors')
        self.motor1.arm()
        self.motor2.arm()
        self.motor3.arm()
        self.motor4.arm()
        time.sleep(5)

    def stopMotors(self):
        print("Stopping")
        self.motor1.stop()
        self.motor2.stop()
        self.motor3.stop()
        self.motor4.stop()

    def calibrateThrottles(self):
        self.motor1.calibrateThrottle()
        self.motor2.calibrateThrottle()
        self.motor3.calibrateThrottle()
        self.motor4.calibrateThrottle()

    def setPwmForAllMotors(self, pwmValue):
        self.motor1.setPwmValue(pwmValue)
        self.motor2.setPwmValue(pwmValue)
        self.motor3.setPwmValue(pwmValue)
        self.motor4.setPwmValue(pwmValue)

    def simpleExample(self):
        print('Starting motors at 300')
        self.setPwmForAllMotors(300)
        time.sleep(3)
        print('increasing to 360')
        self.setPwmForAllMotors(360)
        time.sleep(3)
        print('increasing to 400')
        self.setPwmForAllMotors(400)
        time.sleep(3)
        print('increasing to 450')
        self.setPwmForAllMotors(450)
        time.sleep(3)

    def manualControl(self):
        exit = False
        pwmValue = 261
        print("Press i to increase speed, d to decrease, q to quit")
        while not(exit):
            action = raw_input()

            if action == "i":
                pwmValue+=1
            elif action == "d":
                pwmValue-=1
            elif action == "q":
                exit = True

            print(pwmValue)

            if not(exit):
                setPwmForAllMotors(pwmValue)


    def autonomousControl(self):

        # Print system status and self test result.
        status, self_test, error = self.bno.get_system_status()
        print('System status: {0}'.format(status))
        print('Self test result (0x0F is normal): 0x{0:02X}'.format(self_test))
        # Print out an error if system status is in error mode.
        if status == 0x01:
            print('System error: {0}'.format(error))
            print('See datasheet section 4.3.59 for the meaning.')

        # Print BNO055 software revision and other diagnostic data.
        sw, bl, accel, mag, gyro = self.bno.get_revision()
        print('Software version:   {0}'.format(sw))
        print('Bootloader version: {0}'.format(bl))
#.........这里部分代码省略.........
开发者ID:matthewcodes,项目名称:piRotor,代码行数:103,代码来源:flight_controller.py


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