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


Python Motor.getPwmValue方法代码示例

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


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

示例1: __init__

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

#.........这里部分代码省略.........

    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))
        print('Accelerometer ID:   0x{0:02X}'.format(accel))
        print('Magnetometer ID:    0x{0:02X}'.format(mag))
        print('Gyroscope ID:       0x{0:02X}\n'.format(gyro))

        pitchPIDController = PID(0.7,0.1,0.1)

        self.setPwmForAllMotors(300)

        while True:
            heading, roll, pitch = self.bno.read_euler()

            pitchPIDOutput = pitchPIDController.update(pitch, 0)

            print('Heading={0:0.2F} Roll={1:0.2F} Pitch={2:0.2F}'.format(heading, roll, pitch))

            print('PITCH PID OUTPUT: '+str(pitchPIDOutput))

            motor1Value = int(round(self.motor1.getPwmValue()+pitchPIDOutput))
            motor2Value = int(round(self.motor2.getPwmValue()+pitchPIDOutput))

            motor3Value = int(round(self.motor3.getPwmValue()-pitchPIDOutput))
            motor4Value = int(round(self.motor4.getPwmValue()-pitchPIDOutput))

            print('motor1={0} motor2={1} motor3={2} motor4={3}'.format(motor1Value, motor2Value, motor3Value, motor4Value))

            self.motor1.setPwmValue(motor1Value)
            self.motor2.setPwmValue(motor2Value)
            self.motor3.setPwmValue(motor3Value)
            self.motor4.setPwmValue(motor4Value)

            time.sleep(1)
开发者ID:matthewcodes,项目名称:piRotor,代码行数:104,代码来源:flight_controller.py


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