當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。