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


Python Motor.fire方法代碼示例

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


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

示例1: __init__

# 需要導入模塊: from motor import Motor [as 別名]
# 或者: from motor.Motor import fire [as 別名]
class Robot:
	def __init__(self, name, ammo):
		self.name = name
		self.current_degree = 0
		self.ammunition_count = ammo
		self.degrees = range(0, 101, 10)
		self.serial_connection =  serial.Serial("/dev/ttyACM0", 9600)


	
		self.seven_seg_one = Display(SDI=11, RCLK=12, SRCLK=13)
		self.seven_seg_two = Display(SDI=33, RCLK=32, SRCLK=35)
		
		self.x_axis = Servo(0, "X Axis", self)
		self.y_axis = Servo(1, "Y Axis", self)		
		self.release= Servo(2, "Release", self)
		
		self.sonic = Sonic(16, 18)
	
		self.servos = [self.x_axis, self.y_axis]
 
		self.motor = Motor(37, 38, 40)

	def demo(self):
		self.x_axis.turn(180)
		self.y_axis.turn(170)
		self.x_axis.turn(100)
		self.y_axis.turn(20)
	def calibrate(self):
		print "[*]Calibrating"
		self.x_axis.turn(180, 0.05)
		self.y_axis.turn(90, 0.05)
		#self.release.turn(180, 0.05)
		print "[*]Done"
	def output_value(self, number):
		number = str(number)
		if len(number) == 2:
			self.seven_seg_one.disp_val(int(number[0]))
			self.seven_seg_two.disp_val(int(number[1]))

		elif len(number) == 1:
			self.seven_seg_one.disp_val(0)
                        self.seven_seg_two.disp_val(int(number[0]))
		else:
			print "[-] Attempted to print non-two-digit number: {}".format(number)

	def main(self):
		"""This is to be the main method. It will do the following:
		(1) Rotate the main servo in 10 degree segments
		(2) Stops and scans for an object
		(3) If an object exists, goes into "Firing Mode"
		(4) If not, continues on
		(5) Once it hits 180, it should reverse down to 0
		"""
		while True:
			for deg in range(0, 181, 10):
				self.x_axis.turn(deg, 0.005)
				ob_pres = self.sonic.get_dist()
				if not (ob_pres is None):
					self.y_axis.turn(30)
					print "[!]Preparing to Fire"
					self.motor.fire()
					self.y_axis.turn(90)
			for deg in range(0,181, 10)[::-1]:
				self.x_axis.turn(deg, 0.005)
				ob_pres = self.sonic.get_dist()
				if not (ob_pres is None):
					self.y_axis.turn(30)
					print "[!]Preparing to Fire"
					self.motor.fire()
					self.y_axis.turn(90)
開發者ID:DavidJacobson,項目名稱:STEM-Robotics-ATDS-Mk-7,代碼行數:73,代碼來源:robot.py


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