本文整理匯總了Python中motor.Motor.moveTo方法的典型用法代碼示例。如果您正苦於以下問題:Python Motor.moveTo方法的具體用法?Python Motor.moveTo怎麽用?Python Motor.moveTo使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類motor.Motor
的用法示例。
在下文中一共展示了Motor.moveTo方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: __init__
# 需要導入模塊: from motor import Motor [as 別名]
# 或者: from motor.Motor import moveTo [as 別名]
class Frank:
def __init__(self):
print "Set mode BCM"
GPIO.setmode(GPIO.BCM)
self.motorX = Motor([6, 13, 19, 26])
#self.motorY = Motor([])
#self.sensor = Sensor(4)
self.setUpScreen()
def setUpScreen(self):
self.screen = curses.initscr()
# turn off input echoing
curses.noecho()
# respond to keys immediately (don't wait for enter)
curses.cbreak()
# map arrow keys to special values
self.screen.keypad(True)
def isArrowKey(self, char):
return char in [curses.KEY_RIGHT,curses.KEY_LEFT, curses.KEY_UP, curses.KEY_DOWN]
def start(self):
try:
char = self.screen.getch()
while True :
while self.isArrowKey():
if char == curses.KEY_RIGHT:
print 'right'
self.motorX.moveTo(Motor.RIGHT)
elif char == curses.KEY_LEFT:
print 'left '
self.motorX.moveTo(Motor.LEFT)
elif char == curses.KEY_UP :
print 'up'
elif char == curses.KEY_DOWN :
print 'down'
char = self.screen.getch()
if char == ord('q'):
self.cleanUp()
break
else:
char = self.screen.getch()
finally:
# shut down cleanly
curses.nocbreak(); self.screen.keypad(0); curses.echo()
curses.endwin()
def cleanUp(self):
GPIO.cleanup()
示例2: exit
# 需要導入模塊: from motor import Motor [as 別名]
# 或者: from motor.Motor import moveTo [as 別名]
exit(0)
direction = sys.argv[2]
if direction not in ['l', 'r']:
print "Direction should be 'l' or 'r'"
exit(0)
try:
distance = int(sys.argv[3])
except ValueError:
print "Distance should be a integer"
exit(0)
print "Motor " + motor_leter
print "Direccion " + direction
print "Distance %d" % distance
print "Set mode BCM"
config = json.load(open("config.json"))
GPIO.setmode(GPIO.BCM)
motor = Motor(config["motor_" + motor_leter]["pins"])
motor.delay = config["motor_" + motor_leter]["delay"]
motor.steps_by_mm = config["motor_" + motor_leter]["steps_by_mm"]
dir = Motor.RIGHT
if direction == 'l':
dir = Motor.LEFT
for x in range(0, int(distance * motor.steps_by_mm)):
motor.moveTo(dir)