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


Python Motor.stop方法代码示例

本文整理汇总了Python中motor.Motor.stop方法的典型用法代码示例。如果您正苦于以下问题:Python Motor.stop方法的具体用法?Python Motor.stop怎么用?Python Motor.stop使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在motor.Motor的用法示例。


在下文中一共展示了Motor.stop方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __init__

# 需要导入模块: from motor import Motor [as 别名]
# 或者: from motor.Motor import stop [as 别名]
class ZMQMotor:
    def __init__(self, address, pin, maxthrottle=200, minthrottle=500, name="motor"):
        self.name = name
        self.address = address
        self.server = ZMQServer(address)
        self.motor = Motor(pin, minthrottle, maxthrottle)
        self.motor.setmin()
        self.quit = False
        self.engage()
        
    def engage(self):
        self.mainloop()
    
    def mainloop(self):
        while not self.quit:
            try:
                message = self.server.receive()
                self.process_msg(message)
                self.reply(message)
                time.sleep(1)
            except ZMQError as e:
                pass
        self.destroy()
            
    def process_msg(self, message):
        match = THROTTLE_REGEX.match(message)
        print "Received message: " + message
        if message == "laputanmachine":
            self.quit=True
        elif match:
            throttle = int(match.group('throttle'))
            self.motor.set_throttle(throttle)
        else:
            print message
            
    def reply(self, message):
        self.server.reply(message)
    
    def destroy(self):
        self.motor.stop()
        self.server.destroy()
开发者ID:nukeop,项目名称:Ci40Drone,代码行数:43,代码来源:zmqmotor.py

示例2: Motor

# 需要导入模块: from motor import Motor [as 别名]
# 或者: from motor.Motor import stop [as 别名]
from motor import Motor
import time

m = Motor('moteur 1', 5, 3, 10)
m.start()
time.sleep(3)
m.setPwmRapport(40)
time.sleep(1)
m.setPwmRapport(50)
time.sleep(1)
m.setPwmRapport(60)
time.sleep(1)
m.setPwmRapport(70)
time.sleep(1)
m.setPwmRapport(80)
time.sleep(1)
m.setPwmRapport(90)
time.sleep(1)
m.setPwmRapport(70)
time.sleep(1)
m.setPwmRapport(50)
time.sleep(1)
m.reverse(True)
time.sleep(3)
m.reverse(True)
time.sleep(3)
m.stop()
m.clear()
开发者ID:vignolet,项目名称:turbo-happiness,代码行数:30,代码来源:main.py

示例3: __init__

# 需要导入模块: from motor import Motor [as 别名]
# 或者: from motor.Motor import stop [as 别名]
class	Robot:
	"""A class to control the Robot. This class use all the other classes"""
	MoveTime = 0.1
	Speed = 50

	def __init__(self, debugMode = False):
		GPIO.setmode(GPIO.BOARD)
		GPIO.setwarnings(False)

		if debugMode:
			level = logging.DEBUG
		else:
			level = logging.CRITICAL
		logging.basicConfig(stream=sys.stderr, level=level)

		self.motor 			= Motor(GPIO, logging)
		self.panandtilt = PanAndTilt(logging)
		self.distance 	= Distance(GPIO, logging)

		self.MoveDirectionsOptions = {
			'fwd': self.motor.forward,
			'stp': self.motor.stop,
			'lft': self.motor.leftTurn,
			'rgt': self.motor.rightTurn,
			'bwd': self.motor.backward,
			'lfm': self.motor.left,
			'rgm': self.motor.right,
		}

		self.LookDirectionsOptions = {
			'fnt': self.panandtilt.front,
			'lft': self.panandtilt.left,
			'rgt': self.panandtilt.right,
			'up': self.panandtilt.up,
			'dwn': self.panandtilt.down,
		}		

	def lookTo(self, anglex, angley):
		self.panandtilt.pan(anglex)
		self.panandtilt.tilt(angley)

	def look(self, direction):
		self.LookDirectionsOptions[direction]()

	def move(self, direction, speed=Speed, moveTime=MoveTime):
		if direction == 'stp':
			logging.debug("Stopping the Robot")
			self.motor.stop()
		else:
			if speed == None:
				speed = self.Speed
			
			logging.debug("Moving %s with speed %d for %f seconds", direction, speed, moveTime)
		
			self.MoveDirectionsOptions[direction](speed)
			sleep(moveTime)

	def whereToMove(self):
		self.look('lft')
		distance_lft = self.distance.getDistance()
		logging.debug("Left distance: %d", distance_lft)

		self.look('rgt')
		distance_rgt = self.distance.getDistance()
		logging.debug("Right distance: %d", distance_rgt)

		if distance_rgt < distance_lft:
			logging.debug("Going to Right")
			return 'rgm'
		else:
			logging.debug("Going to Right")
			return 'lfm'

	def start(self):
		self.on = True
		self.look('fnt')

		while self.on:
			distance = self.distance.getDistance()
			logging.debug("Distance: %d", distance)
			# If there is no object in less than 30 cm ahead
			if distance < 50:
				self.move('stp')
				direction = self.whereToMove()
				self.look('fnt')
				self.move(direction, 40, 0.5)
				self.motor.stop()
			else:
				self.move('fwd')
				
	def stop(self):
		self.on = False

	def finish(self):
		GPIO.cleanup()
开发者ID:johandry,项目名称:RosPi,代码行数:97,代码来源:robot.py

示例4: __init__

# 需要导入模块: from motor import Motor [as 别名]
# 或者: from motor.Motor import stop [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

示例5: Motor

# 需要导入模块: from motor import Motor [as 别名]
# 或者: from motor.Motor import stop [as 别名]
gpio.setmode(gpio.BCM)

# Pins
left_a = 27
left_b = 22

right_a = 5
right_b = 6

left_motor = Motor(gpio, uid="left", pin_a=left_a, pin_b=left_b)
right_motor = Motor(gpio, uid="right", pin_a=right_a, pin_b=right_b)

for i in range(90):
	left_motor.forward()
	right_motor.forward()
	sleep(0.25)

left_motor.stop()
right_motor.stop()
sleep(1)

for i in range(90):
	left_motor.backward()
	right_motor.backward()
	sleep(0.25)

left_motor.stop()
right_motor.stop()

gpio.cleanup()
print "All done!"
开发者ID:frozenjava,项目名称:RobotDriver,代码行数:33,代码来源:driver.py


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