Module misty2py_skills.remote_control

This module contains a skill that allows the user to remotely control Misty using a keyboard.

Global variables

var BACK_KEY

The key for driving backward.

var BASE_ANGLE

The default angle of turning.

var BASE_VELOCITY

The default velocity of the remote-controlled Misty.

var FORW_KEY

The key for driving forward.

var L_KEY

The key for driving left.

var R_KEY

The key for driving right.

var STOP_KEY

The key for stopping Misty's movement.

var TERM_KEY

The key for terminating the skill.

var TURN_VELOCITY

The default turning velocity of the remote-controlled Misty.

Functions

def handle_input(key: pynput.keyboard._xorg.Key | pynput.keyboard._xorg.KeyCode)
Expand source code
def handle_input(key: Union[keyboard.Key, keyboard.KeyCode]):
    """Receives the kyboard inputs and transforms them into Misty's actions.

    Args:
        key (Union[keyboard.Key, keyboard.KeyCode]): the key pressed.
    """
    if key == L_KEY:
        actions.append_(
            {"drive_left": moves.drive_left(misty, TURN_VELOCITY, BASE_ANGLE)}
        )
    elif key == R_KEY:
        actions.append_(
            {"drive_right": moves.drive_right(misty, TURN_VELOCITY, BASE_ANGLE)}
        )
    elif key == FORW_KEY:
        actions.append_({"drive_forward": moves.drive_forward(misty, BASE_VELOCITY)})
    elif key == BACK_KEY:
        actions.append_({"drive_backward": moves.drive_backward(misty, BASE_VELOCITY)})
    elif key == STOP_KEY:
        actions.append_({"stop_driving": moves.stop_driving(misty)})
    elif key == TERM_KEY:
        return False

Receives the kyboard inputs and transforms them into Misty's actions.

Args

key : Union[keyboard.Key, keyboard.KeyCode]
the key pressed.
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."""
    pass

The method required by the keyboard package but not used in this skill.

def remote_control() ‑> Dict
Expand source code
def remote_control() -> Dict:
    """A skill that allows the user to remotely control Misty using a keyboard.

    Returns:
        Dict: The dictionary with `"overall_success"` key (bool) and keys for every action performed (dictionarised Misty2pyResponse).
    """
    cancel_skills(misty)
    print(
        f">>> Press {TERM_KEY} to terminate; control the movement via {L_KEY}, {BACK_KEY}, {R_KEY}, {FORW_KEY}; stop moving with {STOP_KEY}. <<<"
    )
    with keyboard.Listener(
        on_press=handle_input, on_release=handle_release
    ) as listener:
        listener.join()

    return success_of_action_list(actions.get_())

A skill that allows the user to remotely control Misty using a keyboard.

Returns

Dict
The dictionary with "overall_success" key (bool) and keys for every action performed (dictionarised Misty2pyResponse).