當前位置: 首頁>>代碼示例>>Python>>正文


Python Motor.check方法代碼示例

本文整理匯總了Python中motor.Motor.check方法的典型用法代碼示例。如果您正苦於以下問題:Python Motor.check方法的具體用法?Python Motor.check怎麽用?Python Motor.check使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在motor.Motor的用法示例。


在下文中一共展示了Motor.check方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: parameters

# 需要導入模塊: from motor import Motor [as 別名]
# 或者: from motor.Motor import check [as 別名]

#.........這裏部分代碼省略.........

	def __exit__(self, exc_type, exc_value, traceback):
		self.interface.terminate()

	#####################
	### Motor control ###
	#####################
	
	"""
	Sets PID values for all motors
	"""
	def setPID(self, p, i, d):
		self.motorL.setPID(p, i, d)
		self.motorR.setPID(p, i, d)
	
	"""
	Whether any of the motors are rotating
	"""
	def isMoving(self):
		return self.motorL.isRotating() or self.motorR.isRotating()

	"""
	Moves the given distance forwards or backwards
	"""
	def move(self, distance):
		# distance specified in metres
		wheel = distance * self.movementCoeff
		self.startLogging(['move', distance])
		self.motorL.rotate(self.powerL * wheel)
		self.motorR.rotate(self.powerR * wheel)
		self.stopLogging()
	
	"""
	Rotates the whole robot by the given angle clockwise
	"""
	def rotate(self, angle):
		# angle specified in degrees
		wheel = self.rotatePower * angle * (math.pi/180) * self.botRadius * self.movementCoeff
		self.startLogging(['turn', angle])
		self.motorL.rotate( self.powerL * wheel)
		self.motorR.rotate(-self.powerR * wheel)
		self.stopLogging()

	def drive(self, speedL, speedR):
		self.motorL.setSpeed(speedL)
		self.motorR.setSpeed(speedR)

	def arcPath(self, theta):
		# theta = 0 returns to straight path
		# Positive theta => too far to the right => turn left
		if theta <= 0 :
			self.powerL = 1 
			self.powerR = 1 + theta
		else: 		
			self.powerL = 1 - theta
			self.powerR = 1 
	
	"""
	Blocks the program until the robot stops moving
	"""
	def wait(self):
		while self.isMoving():
			time.sleep(self.deltaTime)

	######################
	### Sensor control ###
	######################

	"""
	Starts the main loop, checking sensors and responding to events until
	`running` is false
	"""
	def mainLoop(self):
		self.running = True
		while self.running:
			self.touchSensorL.check()
			self.touchSensorR.check()
			self.ultraSonic.check()
			self.motorL.check()
			self.motorR.check()
			time.sleep(self.deltaTime)

	def sensorAction(self, params):
		if(params['position'] != 'either' or not params['down']):
			return
		self.wait()
		# function triggered by the event handler when the touchsensor values are changed.
		if (self.touchSensorL.getState() == EventState.SENSOR_TOUCH_DOWN) \
			and (self.touchSensorR.getState() == EventState.SENSOR_TOUCH_DOWN):
			self.move(-20)
			self.wait()
			self.rotate(self, 90)
		elif self.touchSensorL.getState() == EventState.SENSOR_TOUCH_DOWN:
			self.move(-10)
			self.wait()
			self.rotate(self, 45)
		elif self.touchSensorL.getState() == EventState.SENSOR_TOUCH_DOWN:
			self.move(-10)
			self.wait()
			self.rotate(self, -45)
開發者ID:patengelbert,項目名稱:robotics-CO333,代碼行數:104,代碼來源:robot.py


注:本文中的motor.Motor.check方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。