toddlerbot.tools package¶
Submodules¶
toddlerbot.tools.audio_player_async module¶
toddlerbot.tools.calibrate_zero module¶
- toddlerbot.tools.calibrate_zero.calibrate_dynamixel(port: str, robot: Robot, group: str)¶
Calibrates the Dynamixel motors for a specified group of joints in a robot.
This function retrieves the necessary configuration and state information for the Dynamixel motors associated with a specified group of joints in the robot. It then calculates the initial positions for these motors and updates the robot’s joint attributes accordingly.
- Parameters:
port (str) – The communication port used to connect to the Dynamixel motors.
robot (Robot) – The robot instance containing joint and configuration data.
group (str) – The group of joints to be calibrated.
- toddlerbot.tools.calibrate_zero.main(robot: Robot, parts: List[str])¶
Calibrates the robot’s motors based on specified parts and updates the configuration.
This function prompts the user to confirm the installation of calibration parts, calibrates the Dynamixel motors if present, and updates the motor configuration file with the initial positions of the specified parts.
- Parameters:
robot (Robot) – The robot instance containing configuration and joint attributes.
parts (List[str]) – A list of parts to calibrate. Can include specific parts like ‘left_arm’, ‘right_arm’, or ‘all’ to calibrate all parts.
- Raises:
ValueError – If an invalid part is specified in the parts list.
FileNotFoundError – If the motor configuration file is not found.
toddlerbot.tools.edit_keyframe module¶
toddlerbot.tools.joystick module¶
- class toddlerbot.tools.joystick.AsusAxis(value)¶
Bases:
Enum
ROG Ally X Controller axis mapping.
- L2 = 4¶
- LEFT_JOYSTICK_HORIZONTAL = 0¶
- LEFT_JOYSTICK_VERTICAL = 1¶
- R2 = 5¶
- RIGHT_JOYSTICK_HORIZONTAL = 2¶
- RIGHT_JOYSTICK_VERTICAL = 3¶
- class toddlerbot.tools.joystick.AsusButton(value)¶
Bases:
Enum
ROG Ally X Controller button mapping.
- A = 0¶
- B = 1¶
- DPAD_DOWN = (0, -1)¶
- DPAD_LEFT = (-1, 0)¶
- DPAD_RIGHT = (1, 0)¶
- DPAD_UP = (0, 1)¶
- L1 = 4¶
- MENU = 7¶
- R1 = 5¶
- VIEW = 6¶
- X = 2¶
- Y = 3¶
- class toddlerbot.tools.joystick.DeckAxis(value)¶
Bases:
Enum
Steam Deck Controller axis mapping.
- L2 = 9¶
- LEFT_JOYSTICK_HORIZONTAL = 0¶
- LEFT_JOYSTICK_VERTICAL = 1¶
- R2 = 8¶
- RIGHT_JOYSTICK_HORIZONTAL = 2¶
- RIGHT_JOYSTICK_VERTICAL = 3¶
- class toddlerbot.tools.joystick.DeckButton(value)¶
Bases:
Enum
Steam Deck Controller button mapping.
- A = 3¶
- B = 4¶
- DPAD_DOWN = 17¶
- DPAD_LEFT = 18¶
- DPAD_RIGHT = 19¶
- DPAD_UP = 16¶
- L1 = 7¶
- L4 = 20¶
- L5 = 22¶
- MENU = 12¶
- R1 = 8¶
- R4 = 21¶
- R5 = 23¶
- VIEW = 11¶
- X = 5¶
- Y = 6¶
- class toddlerbot.tools.joystick.Joystick(dead_zone: float = 0.1)¶
Bases:
object
Joystick controller class for handling input from a connected joystick.
- get_controller_input() Dict[str, float] ¶
Retrieves and processes input from a connected joystick, mapping it to control actions.
This function reads the current state of the joystick, including button presses and axis movements, and translates these inputs into a dictionary of control actions with corresponding float values. It handles both button and axis inputs, applying a dead zone threshold to filter out minor movements. Special handling is applied for D-pad directions and trigger buttons (L2, R2).
- Returns:
A dictionary where keys are control action names and values are the processed input values from the joystick.
- Return type:
Dict[str, float]
- update_walk_command(control_inputs: Dict[str, float])¶
Updates the walk command inputs by interpolating control values to specified ranges.
- Parameters:
control_inputs (Dict[str, float]) – A dictionary containing control tasks as keys (‘walk_x’, ‘walk_y’, ‘walk_turn’) and their corresponding input values. The input values are expected to be in the range [-1, 1].
- Modifies:
control_inputs: The input values for each task are updated by interpolating them to the respective ranges defined by self.walk_x_range, self.walk_y_range, and self.walk_turn_range.
- class toddlerbot.tools.joystick.JoystickAction(value)¶
Bases:
Enum
Joystick action mapping.
- A = 'look_down'¶
- B = 'look_right'¶
- DPAD_DOWN = 'lean_right'¶
- DPAD_LEFT = 'twist_left'¶
- DPAD_RIGHT = 'twist_right'¶
- DPAD_UP = 'lean_left'¶
- L1 = 'hug'¶
- L2 = 'push_cart'¶
- L4 = 'push_up'¶
- L5 = 'dance_2'¶
- LEFT_JOYSTICK_HORIZONTAL = 'walk_y'¶
- LEFT_JOYSTICK_VERTICAL = 'walk_x'¶
- MENU = 'teleop'¶
- R1 = 'pick'¶
- R2 = 'cuddle'¶
- R4 = 'dance_1'¶
- R5 = 'dance_3'¶
- RIGHT_JOYSTICK_HORIZONTAL = 'walk_turn'¶
- RIGHT_JOYSTICK_VERTICAL = 'squat'¶
- VIEW = 'reset'¶
- X = 'look_left'¶
- Y = 'look_up'¶
- class toddlerbot.tools.joystick.StadiaAxis(value)¶
Bases:
Enum
Google Stadia Controller axis mapping.
- L2 = 4¶
- LEFT_JOYSTICK_HORIZONTAL = 0¶
- LEFT_JOYSTICK_VERTICAL = 1¶
- R2 = 5¶
- RIGHT_JOYSTICK_HORIZONTAL = 2¶
- RIGHT_JOYSTICK_VERTICAL = 3¶
- class toddlerbot.tools.joystick.StadiaButton(value)¶
Bases:
Enum
Google Stadia Controller button mapping.
- A = 0¶
- B = 1¶
- DPAD_DOWN = 12¶
- DPAD_LEFT = 13¶
- DPAD_RIGHT = 14¶
- DPAD_UP = 11¶
- L1 = 9¶
- MENU = 6¶
- R1 = 10¶
- VIEW = 4¶
- X = 2¶
- Y = 3¶
toddlerbot.tools.keyboard module¶
- class toddlerbot.tools.keyboard.Keyboard¶
Bases:
object
A class for handling keyboard input events.
- check(name: str, **kwargs)¶
Checks and updates the state of a key input, triggering associated functions.
This method evaluates the current state of a specified key input. If the key input is active and has not been flagged, it triggers the associated function and updates the flag. If the key input is inactive and has been flagged, it resets the flag.
- Parameters:
name (str) – The name of the key input to check.
**kwargs – Additional keyword arguments to pass to the associated function.
- get_keyboard_input() Dict[str, float] ¶
Retrieve the current state of keyboard inputs.
- Returns:
A dictionary mapping key identifiers to their respective input values.
- Return type:
Dict[str, float]
- on_press(key)¶
Handle key press events to update key input states.
This method updates the key_inputs dictionary based on the character of the key pressed. Specifically, it sets the value to 1.0 for the ‘save’ key when ‘s’ is pressed and for the ‘next’ key when ‘n’ is pressed. Special keys are ignored.
- Parameters:
key – The key event object containing information about the key press.
- on_release(key)¶
Handle key release events to update key input states.
This method is triggered when a key is released. It specifically checks for the ‘s’ and ‘n’ keys and resets their corresponding states in the key_inputs dictionary to 0.0. If the released key does not have a character attribute, the exception is caught and ignored.
- Parameters:
key – The key event object containing information about the released key.
- register(name: str, func: Callable)¶
Registers a function to a specified key if the key is already present in key_inputs but not in key_funcs.
- Parameters:
name (str) – The key associated with the function to be registered.
func (Callable) – The function to be registered under the specified key.
toddlerbot.tools.run_sysID module¶
toddlerbot.tools.sim2real_eval module¶
- toddlerbot.tools.sim2real_eval.evaluate(robot: Robot, sim_data: Dict[str, Dict[str, ndarray[Any, dtype[float32]]]], real_data: Dict[str, Dict[str, ndarray[Any, dtype[float32]]]], exp_folder_path: str)¶
Evaluates the performance of a robot by comparing simulated and real-world data, and generates plots to visualize the differences.
- Parameters:
robot (Robot) – The robot object containing motor ordering and joint limits.
sim_data (Dict[str, Dict[str, npt.NDArray[np.float32]]]) – Simulated data for each motor, including position, velocity, action, and time sequences.
real_data (Dict[str, Dict[str, npt.NDArray[np.float32]]]) – Real-world data for each motor, including position, velocity, action, and time sequences.
exp_folder_path (str) – The path to the folder where the evaluation plots will be saved.
- toddlerbot.tools.sim2real_eval.load_datasets(robot: Robot, sim_data_path: str, real_data_path: str)¶
Loads and processes simulation and real-world datasets for a robot.
This function reads simulation and real-world data from specified file paths, processes the data, and returns it in a structured format. The data includes observations and motor angles, which are organized into dictionaries for easy access.
- Parameters:
robot (Robot) – The robot object containing motor ordering information.
sim_data_path (str) – The file path to the simulation data.
real_data_path (str) – The file path to the real-world data.
- Returns:
A tuple containing two dictionaries. The first dictionary contains the processed simulation data, and the second contains the processed real-world data. Each dictionary is structured with keys for IMU data and motor data, organized by motor name.
- Return type:
Tuple[Dict[str, Dict[str, npt.NDArray[np.float32]]], Dict[str, Dict[str, npt.NDArray[np.float32]]]]
- toddlerbot.tools.sim2real_eval.main()¶
Runs the SysID optimization process by parsing command-line arguments, validating data paths, and evaluating optimized parameters.
This function sets up the environment for system identification by accepting command-line arguments for robot name, task policy, and paths to simulation and real-world data. It validates the existence of the specified data directories, initializes the robot, and creates a results directory with a timestamp. The function then loads the datasets and evaluates the optimized parameters.
- Raises:
ValueError – If the specified simulation or real experiment folder paths do not exist.
toddlerbot.tools.teleoperate module¶
- toddlerbot.tools.teleoperate.main(ip: str)¶
Initializes and runs a teleoperation control loop, sending joystick inputs over a ZMQ connection.
- Parameters:
ip (str) – The IP address for the ZMQ connection.
The function sets up a ZMQ sender node and a joystick interface, then enters a loop to continuously read joystick inputs. It toggles logging based on a specific button press and sends control inputs as messages over the ZMQ connection. The loop runs at a fixed control rate, updating a progress bar to indicate activity. The loop can be interrupted with a keyboard interrupt, which gracefully closes the progress bar.
toddlerbot.tools.zmq_jpeg_receiver module¶
- toddlerbot.tools.zmq_jpeg_receiver.main()¶
Continuously receives and processes image data from a ZMQNode receiver.
This function initializes a ZMQNode as a receiver and enters an infinite loop to receive messages containing image data. The image data is decoded and converted to BGR format for display. The function also calculates and prints the latency of the received message.
Note
The function runs indefinitely and requires a proper setup of a ZMQNode to function correctly. It also requires OpenCV and NumPy for image processing and display.