本文整理汇总了Python中motor.Motor.getDirection方法的典型用法代码示例。如果您正苦于以下问题:Python Motor.getDirection方法的具体用法?Python Motor.getDirection怎么用?Python Motor.getDirection使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类motor.Motor
的用法示例。
在下文中一共展示了Motor.getDirection方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: MotorDriver
# 需要导入模块: from motor import Motor [as 别名]
# 或者: from motor.Motor import getDirection [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()