當前位置: 首頁>>代碼示例>>Python>>正文


Python Motor.setPwmValue方法代碼示例

本文整理匯總了Python中motor.Motor.setPwmValue方法的典型用法代碼示例。如果您正苦於以下問題:Python Motor.setPwmValue方法的具體用法?Python Motor.setPwmValue怎麽用?Python Motor.setPwmValue使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在motor.Motor的用法示例。


在下文中一共展示了Motor.setPwmValue方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: __init__

# 需要導入模塊: from motor import Motor [as 別名]
# 或者: from motor.Motor import setPwmValue [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.setPwmValue方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。