Module misty2py_skills.demonstrations.explore
This module implements a SLAM mapping skill.
Global variables
var HELP_KEY-
The key to print for help information.
var INFO_KEY-
The key to print for SLAM information.
var START_KEY-
The key to print to start exploring.
var TERM_KEY-
The key to print to terminate the skill.
Functions
def explore()-
Expand source code
def explore(): """Attempts to perform SLAM mapping.""" get_instructions() with keyboard.Listener( on_press=handle_press, on_release=handle_release ) as listener: listener.join()Attempts to perform SLAM mapping.
def get_instructions()-
Expand source code
def get_instructions(): """Prints the instructions.""" print( f"\n>>> INSTRUCTIONS <<<\n \ - press {START_KEY} to start exploring (SLAM mapping) \n \ - press {INFO_KEY} to see current exploration status (SLAM status) \n \ - press {TERM_KEY} to stop this program; do not force-quit \ " )Prints the instructions.
def get_slam_info()-
Expand source code
def get_slam_info(): """Obtains and prints the SLAM status.""" enabled = misty.get_info("slam_enabled").parse_to_dict().get("rest_response", {}) if enabled.get("success"): print("SLAM enabled.") else: print("SLAM disabled.") return status = misty.get_info("slam_status").parse_to_dict().get("rest_response", {}) result = status.get("success") if result: info = status.get("result") if info: print(f"SLAM status: {info}") else: print("SLAM status unknown.")Obtains and prints the SLAM status.
def handle_press(key: pynput.keyboard._xorg.Key | pynput.keyboard._xorg.KeyCode) ‑> bool-
Expand source code
def handle_press(key: Union[keyboard.Key, keyboard.KeyCode]) -> bool: """Handles responses to pressing a key. Args: key (Union[keyboard.Key, keyboard.KeyCode]): The pressed key. Returns: bool: `False` upon termination. """ print(f"{key} registered.") stat = misty.get_info("slam_enabled").parse_to_dict().get("rest_response", {}) if not stat.get("success"): print("SLAM disabled, terminating the program.") return False if key == START_KEY: resp = misty.perform_action("slam_mapping_start").parse_to_dict() print(resp) print(f"{key} processed.") elif key == INFO_KEY: get_slam_info() print(f"{key} processed.") elif key == HELP_KEY: get_instructions() print(f"{key} processed.") elif key == TERM_KEY: resp = misty.perform_action("slam_mapping_stop").parse_to_dict() print(resp) print(f"{key} processed.") return FalseHandles responses to pressing a key.
Args
key:Union[keyboard.Key, keyboard.KeyCode]- The pressed key.
Returns
boolFalseupon termination.
def handle_release(key: pynput.keyboard._xorg.Key)-
Expand source code
def handle_release(key: keyboard.Key): """The method required by the keyboard package but not used in this skill.""" passThe method required by the keyboard package but not used in this skill.