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


Python Arduino.shutdown方法代码示例

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


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

示例1: Driver

# 需要导入模块: from arduino import Arduino [as 别名]
# 或者: from arduino.Arduino import shutdown [as 别名]

#.........这里部分代码省略.........
          self.change_state(State.DELIVER_wander_and_search_target)
        elif (status == "TARGET_IN_RANGE"):
          self.change_state(State.DELIVER_verify_target)

      # ---- Deliver Verify Target ----

      elif (self.state == State.DELIVER_verify_target):
        self.change_state(State.DELIVER_release_cone)

      # ---- Deliver Release Cone ----

      elif (self.state == State.DELIVER_release_cone):
        self.arduino.open_claw()
        self.arduino.board.sleep(1)

        self.navigation.reverse()
        self.arduino.board.sleep(2)

        self.navigation.spin_clockwise()
        self.arduino.board.sleep(3)

        print("Starting over...")
        self.change_state(State.COLLECT_spin_and_search_cone)

        try:
          endpoint = "http://" + constants.GROUP10_IP + constants.GROUP10_ENDPOINT_READY
          print("Hitting endpoint: " + endpoint)
          # requests.get(endpoint, timeout=0.001)
          urlopen(endpoint)
        except:
          print("Failed to hit Group10 Endpoint, trying again...")
          print("Just kidding, I'm giving up!")


    elif (self.mode == "manual"):
      # print("In manual mode")
      if (self.manual_direction == "stop"):
        (left_motor, right_motor) = (0.0, 0.0)
      elif (self.manual_direction == "forward"):
        (left_motor, right_motor) = (0.2, 0.2)
      elif (self.manual_direction == "backward"):
        (left_motor, right_motor) = (-0.2, -0.2)
      elif (self.manual_direction == "right"):
        (left_motor, right_motor) = (0.2, 0.0)
      elif (self.manual_direction == "left"):
        (left_motor, right_motor) = (0.0, 0.2)

      print("L: " + str(left_motor) + " R: " + str(right_motor))
      self.arduino.set_motors(left_motor, right_motor)

    elif (self.mode == "kill"):
      self.shutdown()
      sys.exit(0)

    # Loop again after delay
    sc.enter(self.looprate, 1, self.loop, (sc,))

  def change_state(self, new_state):
    print("[State Change] " + str(self.state) + " -> " + str(new_state))
    self.state = new_state

  def process_message(self, message):
    if (message == "stop"):
      self.stop_on_next_loop()
    elif (message == "start"):
      self.start()
    elif (message == "print"):
      print("Print!")

    # Modes
    elif (message == "auto"):
      self.mode = "auto"
    elif (message == "manual"):
      self.mode = "manual"
    elif (message == "kill"):
      self.mode = "kill"

    # Inter-Bot commands
    elif (message == "bot_ready_to_deliver"):
      print("Received inter-bot communication: ready_to_deliver")
      self.ready_to_deliver = True

    # Manual Directions
    elif (message == "manual_forward"):
      self.manual_direction = "forward"
    elif (message == "manual_backward"):
      self.manual_direction = "backward"
    elif (message == "manual_right"):
      self.manual_direction = "right"
    elif (message == "manual_left"):
      self.manual_direction = "left"
    elif (message == "manual_stop"):
      self.manual_direction = "stop"
    elif (message == "manual_claw_open"):
      self.arduino.open_claw()
    elif (message == "manual_claw_close"):
      self.arduino.close_claw()

  def shutdown(self, signal=None, frame=None):
    self.arduino.shutdown()
开发者ID:zacharylawrence,项目名称:ENEE408I-Team-9,代码行数:104,代码来源:driver.py


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