當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。