toddlerbot.descriptions package¶
Submodules¶
toddlerbot.descriptions.add_configs module¶
- toddlerbot.descriptions.add_configs.get_default_config(robot_name: str, root: Element, general_config: Dict[str, Any], motor_config: Dict[str, Dict[str, Any]], joint_dyn_config: Dict[str, Dict[str, float]])¶
Generates a default configuration dictionary for a robot based on its URDF structure and provided configurations.
- Parameters:
robot_name (str) – The name of the robot, used to determine specific configurations.
root (ET.Element) – The root element of the robot’s URDF XML structure.
general_config (Dict[str, Any]) – General configuration settings for the robot.
motor_config (Dict[str, Dict[str, Any]]) – Configuration settings for each motor, including control parameters.
joint_dyn_config (Dict[str, Dict[str, float]]) – Dynamic configuration settings for each joint, such as damping and friction.
- Returns:
A dictionary containing the default configuration for the robot, including general settings and detailed joint configurations.
- Return type:
Dict[str, Dict[str, Any]]
- toddlerbot.descriptions.add_configs.main() None ¶
Main function to generate and save configuration files for a specified robot.
This function parses command-line arguments to determine the robot’s name and sets up various configuration parameters based on the robot’s characteristics. It generates general, motor, joint dynamics, and collision configurations, saving them to JSON files in the appropriate directories.
- Raises:
ValueError – If the motor configuration file is not found for the specified robot.
toddlerbot.descriptions.assemble_urdf module¶
- class toddlerbot.descriptions.assemble_urdf.URDFConfig(robot_name: str, body_name: str, arm_name: str, leg_name: str)¶
Bases:
object
Data class for storing URDF configuration parameters.
- arm_name: str¶
- body_name: str¶
- leg_name: str¶
- robot_name: str¶
- toddlerbot.descriptions.assemble_urdf.assemble_urdf(urdf_config: URDFConfig)¶
Assembles a URDF file for a robot based on the provided configuration.
This function constructs a complete URDF (Unified Robot Description Format) file by combining a base body URDF with optional arm and leg components specified in the configuration. It updates mesh file paths and ensures the correct structure for simulation.
- Parameters:
urdf_config (URDFConfig) – Configuration object containing the names of the robot, body, arms, and legs to be assembled.
- Raises:
ValueError – If a source URDF for a specified link cannot be found.
- toddlerbot.descriptions.assemble_urdf.find_root_link_name(root: Element)¶
Updates link names in part_root to ensure uniqueness in body_root and updates all references.
- Parameters:
root (ET.Element) – The root XML element of the part URDF being merged.
- Returns:
The new unique name for the root link.
- Return type:
str
- toddlerbot.descriptions.assemble_urdf.main()¶
Parses command-line arguments to configure and assemble a URDF (Unified Robot Description Format) file.
This function sets up an argument parser to accept parameters for robot configuration, including the robot’s name, body, arm, and leg components. It then calls the assemble_urdf function with the parsed arguments to generate the URDF file.
- toddlerbot.descriptions.assemble_urdf.update_link_names_and_references(body_root: Element, part_root: Element)¶
Updates link names in part_root to ensure uniqueness in body_root and updates all references.
- Parameters:
body_root – The root XML element of the main URDF body.
part_root – The root XML element of the part URDF being merged.
- Returns:
The function directly modifies part_root in-place.
- Return type:
None
toddlerbot.descriptions.get_urdf module¶
- class toddlerbot.descriptions.get_urdf.OnShapeConfig(doc_id_list: List[str], assembly_list: List[str], mergeSTLs: str = 'all', mergeSTLsCollisions: bool = True, simplifySTLs: str = 'all', maxSTLSize: int = 1)¶
Bases:
object
Data class for storing OnShape configuration parameters.
- assembly_list: List[str]¶
- doc_id_list: List[str]¶
- maxSTLSize: int = 1¶
- mergeSTLs: str = 'all'¶
- mergeSTLsCollisions: bool = True¶
- simplifySTLs: str = 'all'¶
- toddlerbot.descriptions.get_urdf.is_xml_pretty_printed(file_path: str) bool ¶
Check if an XML file is pretty-printed by examining indentation.
- Parameters:
file_path (str) – The path to the XML file to be checked.
- Returns:
True if the XML file is pretty-printed with indentation, False otherwise.
- Return type:
bool
- toddlerbot.descriptions.get_urdf.main()¶
Parses command-line arguments for document and assembly names and processes them using OnShape.
This function sets up an argument parser to handle command-line inputs for document IDs and assembly names, ensuring they match the names in OnShape. It then invokes the run_onshape_to_robot function with the parsed arguments.
- Raises:
SystemExit – If required command-line arguments are not provided.
- toddlerbot.descriptions.get_urdf.prettify(elem: Element, file_path: str)¶
Formats an XML element into a pretty-printed string.
This function converts an XML element into a string and formats it with indentation for improved readability. If the XML file at the specified path is already pretty-printed, it returns the compact XML string; otherwise, it returns a pretty-printed version with indentation.
- Parameters:
elem (ET.Element) – The XML element to be formatted.
file_path (str) – The path to the XML file to check for pretty-printing.
- Returns:
A string representation of the XML element, either compact or pretty-printed.
- Return type:
str
- toddlerbot.descriptions.get_urdf.process_urdf_and_stl_files(assembly_path: str)¶
Processes URDF and STL files within a specified assembly directory.
This function performs several operations on URDF and STL files located in the given assembly path: 1. Parses the URDF file and updates the robot name to match the directory name. 2. Identifies and collects all referenced STL files from the URDF. 3. Deletes any STL or PART files in the directory that are not referenced in the URDF. 4. Moves referenced STL files to a ‘meshes’ directory, creating it if necessary. 5. Updates the URDF file to reflect the new locations of the STL files. 6. Renames the URDF file to match the base directory name if needed.
- Parameters:
assembly_path (str) – The path to the directory containing the URDF and STL files.
- Raises:
ValueError – If no URDF file is found in the specified directory.
- toddlerbot.descriptions.get_urdf.run_onshape_to_robot(onshape_config: OnShapeConfig)¶
Processes OnShape assemblies and converts them to URDF format for robotic applications.
This function iterates over a list of OnShape document IDs and corresponding assembly names, creating a directory for each assembly. It generates a configuration JSON file for each assembly, specifying parameters for URDF conversion. The function then executes a command to convert the assembly to URDF format and processes the resulting URDF and STL files.
- Parameters:
onshape_config (OnShapeConfig) – Configuration object containing lists of document IDs and assembly names, along with settings for STL merging, collision handling, simplification, and maximum STL size.
toddlerbot.descriptions.process_mjcf module¶
toddlerbot.descriptions.update_collisions module¶
toddlerbot.descriptions.update_onshape_config module¶
- toddlerbot.descriptions.update_onshape_config.get_env_path()¶
Determines the path of the current Python environment.
- Returns:
The path to the current Python environment. If a virtual environment is active, returns the virtual environment’s path. If a conda environment is active, returns the conda environment’s path. Otherwise, returns the system environment’s path.
- Return type:
str
- toddlerbot.descriptions.update_onshape_config.modify_config()¶
Modifies config.py in onshape_to_robot package if running on macOS.