Skip to content

Control

This module defines varuous language controls.

  1. CommandControl: Basic commands such as 'start', 'stop', 'restart', etc.
  2. MobileControl: Commands for mobile movement like 'move forward', 'move backward', etc.
  3. HeadControl: Commands for head movements such as 'look up', 'look down', etc.
  4. HandControl: Commands for hand movements like 'open hand', 'move hand forward', etc.
  5. MobileSingleArmControl: Comprehensive commands for a mobile single-arm robot, including movements and rotations.

The dynamically created Enums are: - LangControl: Combines CommandControl, MobileControl, HeadControl, and HandControl. - MobileSingleArmLangControl: Based on MobileSingleArmControl.

Example usage:

execute_command(LangControl.START)  # Output: Starting the system...
execute_command(LangControl.MOVE_FORWARD)  # Output: Moving forward...

command_str = "move forward"
command = get_command_from_string(command_str)
execute_command(command)  # Execute: Moving forward...

create_enum_from_list(name, string_list)

Dynamically create an Enum type from a list of strings.

Parameters:

Name Type Description Default
name str

The name of the Enum class.

required
string_list list[str]

The list of strings to be converted into Enum members.

required

Returns:

Name Type Description
Enum Enum

A dynamically created Enum type with members based on the string list.

Source code in mbodied/types/language/control.py
27
28
29
30
31
32
33
34
35
36
37
def create_enum_from_list(name, string_list) -> Enum:
    """Dynamically create an Enum type from a list of strings.

    Args:
        name (str): The name of the Enum class.
        string_list (list[str]): The list of strings to be converted into Enum members.

    Returns:
        Enum: A dynamically created Enum type with members based on the string list.
    """
    return Enum(value=name, names=[(item.replace(" ", "_").upper(), item) for item in string_list])

get_command_from_string(command_str)

Get the Enum member corresponding to a given command string.

Source code in mbodied/types/language/control.py
45
46
47
48
49
50
def get_command_from_string(command_str) -> Enum:
    """Get the Enum member corresponding to a given command string."""
    try:
        return LangControl[command_str.replace(" ", "_").upper()]
    except KeyError:
        return None

language_control_to_list(enum)

Convert an Enum type to a list of its values. So it's easier to pass i.e. as prompt.

Source code in mbodied/types/language/control.py
40
41
42
def language_control_to_list(enum: Enum) -> list[str]:
    """Convert an Enum type to a list of its values. So it's easier to pass i.e. as prompt."""
    return [command.value for command in enum]