本文整理汇总了Python中arduino.Arduino.close_claw方法的典型用法代码示例。如果您正苦于以下问题:Python Arduino.close_claw方法的具体用法?Python Arduino.close_claw怎么用?Python Arduino.close_claw使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类arduino.Arduino
的用法示例。
在下文中一共展示了Arduino.close_claw方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Driver
# 需要导入模块: from arduino import Arduino [as 别名]
# 或者: from arduino.Arduino import close_claw [as 别名]
class Driver():
# Wait .05 sec between loops
# This waits after the loop is run. This will not subtract the time it took to run loop() from the total wait time.
def __init__(self, webserver_queue=None, looprate=0.2):
self.arduino = Arduino()
self.navigation = Navigation(self.arduino)
self.state = State.COLLECT_spin_and_search_cone
# Define constants
self.looprate = looprate
# Variables updated from webserver
self.webserver_queue = webserver_queue
self.mode = "auto"
self.manual_direction = "stop"
# Variables used by states
self.start_time = None
self.ready_to_deliver = False
def start(self):
self.stop = False
s = sched.scheduler(time.time, self.arduino.board.sleep)
s.enter(0, 1, self.loop, (s,))
s.run()
def stop_on_next_loop(self):
self.stop = True
def loop(self, sc):
# Read webserver queue for new messages
while((self.webserver_queue != None) and (len(self.webserver_queue) > 0)):
self.process_message(self.webserver_queue.popleft())
# If stopped, just loop
if (self.stop):
sc.enter(self.looprate, 1, self.loop, (sc,))
return
if (self.mode == "auto"):
# ---- Collect Spin and Search Cone ----
if (self.state == State.COLLECT_spin_and_search_cone):
if (self.start_time == None):
self.start_time = time.time()
if (time.time() - self.start_time >= constants.SPIN_TIME):
self.start_time = None
self.navigation.stop()
self.change_state(State.COLLECT_wander_and_search_cone)
# TODO: Use signatures with pixy
else:
status = self.navigation.spin_and_search_cone()
if (status == "CONE_FOUND"):
self.start_time = None
self.change_state(State.COLLECT_approach_cone)
# ---- Collect Wander and Search ----
elif (self.state == State.COLLECT_wander_and_search_cone):
if (self.start_time == None):
self.start_time = time.time()
if (time.time() - self.start_time >= constants.WANDER_TIME):
self.start_time = None
self.navigation.stop()
self.change_state(State.COLLECT_spin_and_search_cone)
# TODO: Use signatures with pixy
else:
status = self.navigation.wander_and_search_cone()
if (status == "CONE_FOUND"):
self.start_time = None
self.change_state(State.COLLECT_approach_cone)
# ---- Collect Approach Cone ----
elif (self.state == State.COLLECT_approach_cone):
status = self.navigation.approach_cone()
if (status == "LOST_CONE"):
self.change_state(State.COLLECT_wander_and_search_cone)
elif (status == "CONE_IN_RANGE"):
self.change_state(State.COLLECT_acquire_cone)
# ---- Collect Acquire Cone ----
elif (self.state == State.COLLECT_acquire_cone):
self.arduino.close_claw()
ping = self.arduino.get_ping()
if (ping <= constants.PING_CONE_THRESHOLD and ping != 0):
if (self.ready_to_deliver == True):
self.change_state(State.DELIVER_spin_and_search_target)
self.ready_to_deliver = False
else:
print("Waiting for inter-bot command to deliver...")
else:
self.change_state(State.COLLECT_open_claw)
# ---- Collect Open Claw ----
elif (self.state == State.COLLECT_open_claw):
#.........这里部分代码省略.........