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


Python Motor.setDirCcw方法代碼示例

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


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

示例1: MotorDriver

# 需要導入模塊: from motor import Motor [as 別名]
# 或者: from motor.Motor import setDirCcw [as 別名]
class TantrumMotors:
    """
    This class is designed to control the motors of a Tyco Tantrum
    RC car. The Tantrum has a front motor controlling direction and
    a rear motor for moving forwards and backwards.
    """

    _front = 0  # Motor
    _rear = 0  # Motor
    _frontDriver = MotorDriver("P9_11", "P9_14")
    _rearDriver = MotorDriver("P9_12", "P9_16")

    # <public>
    # Initialize motors to forward, stopped
    def __init__(self):
        self._front = Motor(self._frontDriver)
        self._rear = Motor(self._rearDriver)
        self._front.setDirCw()
        self._front.setSpeed(0)
        self._rear.setDirCcw()
        self._rear.setSpeed(0)

    # Set the speed for all motors, if a speed is negative then the
    # motor is put in reverse.
    def setSpeed(self, front, rear):
        front = int(front)
        rear = int(rear)

        self._front.setSpeed(front)
        if (front < 0):
            self._front.setDirCcw()
        else:
            self._front.setDirCw()

        self._rear.setSpeed(rear)
        if (rear < 0):
            self._rear.setDirCcw()
        else:
            self._rear.setDirCw()

    def getFrontSpeed(self):
        return self._front.getSpeed()

    def getRearSpeed(self):
        return self._rear.getSpeed()

    def getFrontDirection(self):
        return self._front.getDirection()

    def getRearDirection(self):
        return self._rear.getDirection()

    def updateMotorState(self):
        self._frontDriver.updateState()
        self._rearDriver.updateState()

    def __exit__(self, type, value, traceback):
        self._frontDriver.shutdown()
        self._rearDriver.shutdown()
開發者ID:Grated,項目名稱:Beaglebone,代碼行數:61,代碼來源:tantrum_motors.py


注:本文中的motor.Motor.setDirCcw方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。