当前位置: 首页>>代码示例>>Python>>正文


Python Motor.moveTo方法代码示例

本文整理汇总了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()
开发者ID:godiard,项目名称:frank,代码行数:54,代码来源:Frank.py

示例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)
开发者ID:godiard,项目名称:frank,代码行数:32,代码来源:move-motor.py


注:本文中的motor.Motor.moveTo方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。