def GetAskWantTourStateMachine():
    sm = smach.StateMachine(
        outcomes=["want_tour", "dont_want_tour", "silence"])

    with sm:
        smach.StateMachine.add(
            "reset_ask_want_tour_retried",
            general_states.ResetRetryCounter("ask_want_tour_retry", 2),
            transitions={"next": "decrease_and_test_ask_want_tour"},
            remapping={"ask_want_tour_retry": "ask_want_tour_retry"})
        sm.set_initial_state(["reset_ask_want_tour_retried"])

        smach.StateMachine.add(
            "decrease_and_test_ask_want_tour",
            general_states.DecreaseAndTestRetry("ask_want_tour_retry"),
            transitions={
                "continue": "ask_want_tour",
                "give_up": "silence"
            },
            remapping={"ask_want_tour_retry": "ask_want_tour_retry"})

        smach.StateMachine.add("ask_want_tour",
                               AskWantTourState(),
                               transitions={
                                   "want_tour": "want_tour",
                                   "dont_want_tour": "dont_want_tour",
                                   "silence": "decrease_and_test_ask_want_tour"
                               })
    return sm
def GetAutoChargingStateMachine():
    sm = smach.StateMachine(outcomes=[
        "no_need_charge", "finished_charging", "already_charging", "interrupt",
        "failed"
    ])
    with sm:
        smach.StateMachine.add("check_trigger_cmd",
                               wait_trigger_states.TriggerCmdState(
                                   ["prep_serve"]),
                               transitions={
                                   "prep_serve": "interrupt",
                                   "none": "test_already_charging"
                               })
        sm.set_initial_state(["check_trigger_cmd"])

        smach.StateMachine.add("test_already_charging",
                               TestBatteryIsChargingState(),
                               transitions={
                                   "charging": "already_charging",
                                   "not_charging": "decide_need_charging",
                                   "unknown": "failed",
                               })

        smach.StateMachine.add("decide_need_charging",
                               TestBatteryLevelState(),
                               transitions={
                                   "full": "no_need_charge",
                                   "normal": "no_need_charge",
                                   "low": "go_dock_retry_reset",
                                   "unknown": "failed",
                               })

        smach.StateMachine.add("go_dock_retry_reset",
                               general_states.ResetRetryCounter(
                                   "go_dock_retry", 3),
                               transitions={"next": "go_dock_retry_test"},
                               remapping={"go_dock_retry": "go_dock_retry"})

        smach.StateMachine.add(
            "go_dock_retry_test",
            general_states.DecreaseAndTestRetry("go_dock_retry"),
            transitions={
                "continue": "go_dock",
                "give_up": "failed"
            },
            remapping={"go_dock_retry": "go_dock_retry"})

        smach.StateMachine.add("go_dock",
                               GoDockingState(),
                               transitions={
                                   "done": "test_is_charging",
                                   "failed": "go_dock_retry_test"
                               })

        smach.StateMachine.add("test_is_charging",
                               TestBatteryIsChargingState(),
                               transitions={
                                   "charging": "test_finished_charging",
                                   "not_charging": "go_dock_retry_test",
                                   "unknown": "failed"
                               },
                               remapping={"tour_point_id": "tour_point_id"})

        smach.StateMachine.add("test_finished_charging",
                               TestBatteryLevelState(),
                               transitions={
                                   "full": "finished_charging",
                                   "normal": "wait_finish_charging",
                                   "low": "wait_finish_charging",
                                   "unknown": "failed"
                               },
                               remapping={"tour_point_id": "tour_point_id"})

        smach.StateMachine.add("wait_finish_charging",
                               general_states.WaitTimeState(5),
                               transitions={"next": "test_finished_charging"})

    return sm
Exemple #3
0
def GetQuizStateMachine():
  sm_quiz = smach.StateMachine(outcomes=["finished", "silence"])

  sm_quiz.userdata.available_quiz = []
  sm_quiz.userdata.selected_quiz = None
  sm_quiz.userdata.silence_retry = False

  with sm_quiz:
    smach.StateMachine.add(
        "load_quiz", LoadQuizState(),
        transitions={"next": "select_quiz"},
        remapping={"available_quiz": "available_quiz"})
    sm_quiz.set_initial_state(["load_quiz"])

    smach.StateMachine.add(
        "select_quiz", SelectQuizState(),
        transitions={"next": "ask_quiz", "no_quiz": "load_quiz"},
        remapping={"available_quiz": "available_quiz",
                   "selected_quiz": "selected_quiz"})

    smach.StateMachine.add(
        "reset_silence_retried",
        general_states.ResetRetryCounter("silence_retry", 2 - 1),
        transitions={"next": "ask_quiz"},
        remapping={"silence_retry": "silence_retry"})

    smach.StateMachine.add(
        "ask_quiz", AskQuizState(),
        transitions={"next": "check_answer"},
        remapping={"selected_quiz": "selected_quiz"})

    smach.StateMachine.add(
        "check_answer", CheckAnswerState(),
        transitions={"correct": "congratulate_correct_answer",
                     "wrong": "respond_wrong_answer",
                     "repeat": "ask_quiz",
                     "silence": "test_silence_retry",
                     "dont_know": "respond_dont_know"},
        remapping={"selected_quiz": "selected_quiz"})

    smach.StateMachine.add(
        "congratulate_correct_answer", CongratulateCorrectAnswerState(),
        transitions={"next": "decide_to_ask_want_more"},
        remapping={"selected_quiz": "selected_quiz"})

    smach.StateMachine.add(
        "respond_wrong_answer", RespondWrongAnswerState(),
        transitions={"next": "decide_to_ask_want_more"},
        remapping={"selected_quiz": "selected_quiz"})

    smach.StateMachine.add(
        "respond_dont_know", RespondDontKnowState(),
        transitions={"next": "decide_to_ask_want_more"},
        remapping={"selected_quiz": "selected_quiz"})

    smach.StateMachine.add(
        "test_silence_retry",
        general_states.DecreaseAndTestRetry("silence_retry"),
        transitions={"continue": "say_repeat_question",
                     "give_up": "silence"},
        remapping={"silence_retry": "silence_retry"})

    smach.StateMachine.add(
        "say_repeat_question", SayRepeatQuestionState(),
        transitions={"next": "ask_quiz"})

    smach.StateMachine.add(
        "decide_to_ask_want_more", DecideToAskWantMoreState(),
        transitions={"ask_want_more": "ask_want_more",
                     "no_more": "no_more_quiz"},
        remapping={"available_quiz": "available_quiz"})

    smach.StateMachine.add(
        "ask_want_more", AskWantMoreState(),
        transitions={"want_more": "select_quiz",
                     "silence": "say_goodbye",
                     "no_more": "say_goodbye"},
        remapping={"available_quiz": "available_quiz"})

    smach.StateMachine.add(
        "no_more_quiz", SayNoMoreQuizState(),
        transitions={"next": "say_goodbye"},
        remapping={"available_quiz": "available_quiz"})

    smach.StateMachine.add(
        "say_goodbye", SayGoodbyeState(),
        transitions={"next": "finished"})

  return sm_quiz
Exemple #4
0
def GetTourGuideStateMachine():
    sm = smach.StateMachine(outcomes=["finished", "failed"])
    with sm:
        smach.StateMachine.add("say_follow_me",
                               SayFollowMe(),
                               transitions={"next": "prepare_to_move"})
        sm.set_initial_state(["say_follow_me"])

        smach.StateMachine.add(
            "prepare_to_move",
            robot_pose_states.GetPrepareToMoveStateMachine(),
            transitions={
                "success": "load_tour_points",
                "fail": "apologize_error"
            })

        smach.StateMachine.add(
            "load_tour_points",
            LoadTourPointsList(),
            transitions={"next": "get_next_tour_point"},
            remapping={"remaining_tour_points": "remaining_tour_points"})

        smach.StateMachine.add("get_next_tour_point",
                               GetNextTourPoint(),
                               transitions={
                                   "next": "reset_go_to_tour_point_retry",
                                   "empty": "say_thats_all"
                               },
                               remapping={
                                   "tour_point_id": "tour_point_id",
                                   "remaining_tour_points":
                                   "remaining_tour_points"
                               })

        smach.StateMachine.add(
            "reset_go_to_tour_point_retry",
            general_states.ResetRetryCounter("go_to_tour_point_retry", 3 - 1),
            transitions={"next": "go_to_tour_point"},
            remapping={"go_to_tour_point_retry": "go_to_tour_point_retry"})

        smach.StateMachine.add("go_to_tour_point",
                               GoToTourPointState(),
                               transitions={
                                   "done": "say_tour_words",
                                   "failed":
                                   "decrease_and_test_go_to_tour_point"
                               },
                               remapping={"tour_point_id": "tour_point_id"})

        smach.StateMachine.add(
            "decrease_and_test_go_to_tour_point",
            general_states.DecreaseAndTestRetry("go_to_tour_point_retry"),
            transitions={
                "continue": "say_move_away",
                "give_up": "apologize_error"
            },
            remapping={"go_to_tour_point_retry": "go_to_tour_point_retry"})

        smach.StateMachine.add("say_move_away",
                               SayMoveAwayState(),
                               transitions={"next": "go_to_tour_point"})

        smach.StateMachine.add("say_tour_words",
                               SayTourWords(),
                               transitions={"next": "get_next_tour_point"},
                               remapping={"tour_point_id": "tour_point_id"})

        smach.StateMachine.add("say_thats_all",
                               SayThatsAll(),
                               transitions={"next": "finished"})

        smach.StateMachine.add("apologize_error",
                               ApologizeErrorState(),
                               transitions={"next": "failed"})

    return sm
Exemple #5
0
def GetGreetPeopleWithFaceOrRememberFaceStateMachine():
  sm = smach.StateMachine(
      outcomes=["known_person", "unknown_person", "error"],
      output_keys=["human_name"])

  sm.userdata.last_seen_human_uuid = None
  sm.userdata.last_seen_human_timestamp = None
  sm.userdata.last_seen_human_nicknames = None
  sm.userdata.human_name = None

  with sm:
    smach.StateMachine.add(
        "greet_people_state1", GreetPeopleState1(),
        transitions={"next": "lookup_recent_seen_human_id_1"})

    smach.StateMachine.add(
        "lookup_recent_seen_human_id_1", LookUpRecentSeenIdentityState(),
        transitions={"known_person": "greet_known_people",
                     "unknown_person": "greet_people_state2",
                     "error": "apologize_error"},
        remapping={"last_seen_human_uuid": "last_seen_human_uuid",
                   "last_seen_human_timestamp": "last_seen_human_timestamp",
                   "last_seen_human_nicknames": "last_seen_human_nicknames"})
    sm.set_initial_state(["greet_people_state1"])

    smach.StateMachine.add(
        "greet_people_state2", GreetPeopleState2(),
        transitions={"next": "lookup_recent_seen_human_id_2"})

    smach.StateMachine.add(
        "lookup_recent_seen_human_id_2", LookUpRecentSeenIdentityState(),
        transitions={"known_person": "greet_known_people",
                     "unknown_person": "greet_people_state3",
                     "error": "apologize_error"},
        remapping={"last_seen_human_uuid": "last_seen_human_uuid",
                   "last_seen_human_timestamp": "last_seen_human_timestamp",
                   "last_seen_human_nicknames": "last_seen_human_nicknames"})

    smach.StateMachine.add(
        "greet_people_state3", GreetPeopleState3(),
        transitions={"next": "lookup_recent_seen_human_id_3"})

    smach.StateMachine.add(
        "lookup_recent_seen_human_id_3", LookUpRecentSeenIdentityState(),
        transitions={"known_person": "greet_known_people",
                     "unknown_person": "ask_for_name",
                     "error": "apologize_error"},
        remapping={"last_seen_human_uuid": "last_seen_human_uuid",
                   "last_seen_human_timestamp": "last_seen_human_timestamp",
                   "last_seen_human_nicknames": "last_seen_human_nicknames"})
    smach.StateMachine.add(
        "greet_known_people", GreetKnownPeopleState(),
        transitions={"next": "known_person"},
        remapping={"last_seen_human_nicknames": "last_seen_human_nicknames"})

    smach.StateMachine.add(
        "ask_for_name", AskForNameState(),
        transitions={"next": "reset_ask_name_retry"})

    smach.StateMachine.add(
        "reset_ask_name_retry",
        general_states.ResetRetryCounter("ask_name_retry", 2 - 1),
        transitions={"next": "listen_for_human_name"},
        remapping={"ask_name_retry": "ask_name_retry"})

    smach.StateMachine.add(
        "listen_for_human_name", ListenForHumanNameState(),
        transitions={
          "got_name": "greet_unknown_person_with_name",
          "dont_understand": "decrease_and_test_ask_name_retry_dont_understand",
          "silence": "decrease_and_test_ask_name_retry_silence"},
        remapping={"human_name": "human_name"})

    smach.StateMachine.add(
        "decrease_and_test_ask_name_retry_dont_understand",
        general_states.DecreaseAndTestRetry("ask_name_retry"),
        transitions={"continue": "ask_name_again_for_dont_understand",
                     "give_up": "apologize_error"},
        remapping={"ask_name_retry": "ask_name_retry"})

    smach.StateMachine.add(
        "decrease_and_test_ask_name_retry_silence",
        general_states.DecreaseAndTestRetry("ask_name_retry"),
        transitions={"continue": "ask_name_again_for_silence",
                     "give_up": "apologize_error"},
        remapping={"ask_name_retry": "ask_name_retry"})

    smach.StateMachine.add(
        "ask_name_again_for_dont_understand",
        AskNameAgainForDontUnderstandState(),
        transitions={"next": "listen_for_human_name"})

    smach.StateMachine.add(
        "ask_name_again_for_silence",
        AskNameAgainForSilenceState(),
        transitions={"next": "listen_for_human_name"})

    smach.StateMachine.add(
        "greet_unknown_person_with_name",
        GreetHumanWithNameState(),
        transitions={"next": "unknown_person"},
        remapping={"human_name": "human_name"})

    smach.StateMachine.add(
        "apologize_error", ApologizeErrorState(),
        transitions={"next": "error"})

  return sm