Skip to content

Commit

Permalink
add_wall() scene building utility
Browse files Browse the repository at this point in the history
  • Loading branch information
Victorlouisdg committed Mar 21, 2024
1 parent bd69a7b commit a45dc99
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 4 deletions.
2 changes: 2 additions & 0 deletions airo_drake/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from airo_drake.building.floor import add_floor
from airo_drake.building.manipulator import X_URBASE_ROSBASE, X_URTOOL0_ROBOTIQ, add_manipulator
from airo_drake.building.meshcat import add_meshcat
from airo_drake.building.wall import add_wall
from airo_drake.path.analysis import (
calculate_joint_path_distances,
calculate_joint_path_length,
Expand All @@ -28,6 +29,7 @@

__all__ = [
"add_floor",
"add_wall",
"add_manipulator",
"X_URBASE_ROSBASE",
"X_URTOOL0_ROBOTIQ",
Expand Down
60 changes: 60 additions & 0 deletions airo_drake/building/wall.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import airo_models
import numpy as np
from airo_typing import Vector3DType
from pydrake.math import RigidTransform
from pydrake.multibody.tree import ModelInstanceIndex
from pydrake.planning import RobotDiagramBuilder


def add_wall(
robot_diagram_builder: RobotDiagramBuilder,
type: str = "XZ",
height: float = 2.0,
width: float = 2.5,
thickness: float = 0.2,
position: Vector3DType = np.zeros(3),
name: str = "wall",
) -> ModelInstanceIndex:
"""Adds a wall to the robot diagram builder.
The wall is represented as a box with the specified dimensions, type, and position.
The wall is automatically welded to the world frame for a static setup.
Args:
robot_diagram_builder: The robot diagram builder to which the wall will be added.
type: The orientation of the wall. Must be 'XZ' (parallel to the X-Z plane)
or 'YZ' (parallel to the Y-Z plane).
height: The height of the wall.
width: The width of the wall (relevant for its orientation).
thickness: The thickness of the wall (could be relevant for collision checking).
position: The 3D position (x, y, z) of the center of the wall.
name: The name of the wall (for easy reference).
Returns:
The ModelInstanceIndex of the added wall.
"""
plant = robot_diagram_builder.plant()
parser = robot_diagram_builder.parser()
parser.SetAutoRenaming(True)

z_size = height

if type == "XZ":
x_size = width
y_size = thickness
elif type == "YZ":
x_size = thickness
y_size = width
else:
raise ValueError("Invalid wall type, must be 'XZ' or 'YZ'")

wall_urdf_path = airo_models.box_urdf_path((x_size, y_size, z_size), name)
wall_index = parser.AddModels(wall_urdf_path)[0]

wall_transform = RigidTransform(p=position)
world_frame = plant.world_frame()
wall_frame = plant.GetFrameByName("base_link", wall_index)

plant.WeldFrames(world_frame, wall_frame, wall_transform)

return wall_index
8 changes: 4 additions & 4 deletions airo_drake/scene.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ class DualArmScene:
"""The most important objects when using Drake with two robot arms."""

robot_diagram: RobotDiagram
arm_index_left: ModelInstanceIndex
arm_index_right: ModelInstanceIndex
gripper_index_left: ModelInstanceIndex | None = None
gripper_index_right: ModelInstanceIndex | None = None
arm_left_index: ModelInstanceIndex
arm_right_index: ModelInstanceIndex
gripper_left_index: ModelInstanceIndex | None = None
gripper_right_index: ModelInstanceIndex | None = None
meshcat: Meshcat | None = None

0 comments on commit a45dc99

Please sign in to comment.