| | |
| | |
| | |
| | |
| |
|
| | """ |
| | This script demonstrates how to use the differential inverse kinematics controller with the simulator. |
| | |
| | The differential IK controller can be configured in different modes. It uses the Jacobians computed by |
| | PhysX. This helps perform parallelized computation of the inverse kinematics. |
| | |
| | .. code-block:: bash |
| | |
| | # Usage |
| | ./isaaclab.sh -p scripts/tutorials/05_controllers/run_diff_ik.py |
| | |
| | """ |
| |
|
| | """Launch Isaac Sim Simulator first.""" |
| |
|
| | import argparse |
| |
|
| | from isaaclab.app import AppLauncher |
| |
|
| | |
| | parser = argparse.ArgumentParser(description="Tutorial on using the differential IK controller.") |
| | parser.add_argument("--robot", type=str, default="franka_panda", help="Name of the robot.") |
| | parser.add_argument("--num_envs", type=int, default=128, help="Number of environments to spawn.") |
| | |
| | AppLauncher.add_app_launcher_args(parser) |
| | |
| | args_cli = parser.parse_args() |
| |
|
| | |
| | app_launcher = AppLauncher(args_cli) |
| | simulation_app = app_launcher.app |
| |
|
| | """Rest everything follows.""" |
| |
|
| | import torch |
| |
|
| | import isaaclab.sim as sim_utils |
| | from isaaclab.assets import AssetBaseCfg |
| | from isaaclab.controllers import DifferentialIKController, DifferentialIKControllerCfg |
| | from isaaclab.managers import SceneEntityCfg |
| | from isaaclab.markers import VisualizationMarkers |
| | from isaaclab.markers.config import FRAME_MARKER_CFG |
| | from isaaclab.scene import InteractiveScene, InteractiveSceneCfg |
| | from isaaclab.utils import configclass |
| | from isaaclab.utils.assets import ISAAC_NUCLEUS_DIR |
| | from isaaclab.utils.math import subtract_frame_transforms |
| |
|
| | |
| | |
| | |
| | from isaaclab_assets import FRANKA_PANDA_HIGH_PD_CFG, UR10_CFG |
| |
|
| |
|
| | @configclass |
| | class TableTopSceneCfg(InteractiveSceneCfg): |
| | """Configuration for a cart-pole scene.""" |
| |
|
| | |
| | ground = AssetBaseCfg( |
| | prim_path="/World/defaultGroundPlane", |
| | spawn=sim_utils.GroundPlaneCfg(), |
| | init_state=AssetBaseCfg.InitialStateCfg(pos=(0.0, 0.0, -1.05)), |
| | ) |
| |
|
| | |
| | dome_light = AssetBaseCfg( |
| | prim_path="/World/Light", spawn=sim_utils.DomeLightCfg(intensity=3000.0, color=(0.75, 0.75, 0.75)) |
| | ) |
| |
|
| | |
| | table = AssetBaseCfg( |
| | prim_path="{ENV_REGEX_NS}/Table", |
| | spawn=sim_utils.UsdFileCfg( |
| | usd_path=f"{ISAAC_NUCLEUS_DIR}/Props/Mounts/Stand/stand_instanceable.usd", scale=(2.0, 2.0, 2.0) |
| | ), |
| | ) |
| |
|
| | |
| | if args_cli.robot == "franka_panda": |
| | robot = FRANKA_PANDA_HIGH_PD_CFG.replace(prim_path="{ENV_REGEX_NS}/Robot") |
| | elif args_cli.robot == "ur10": |
| | robot = UR10_CFG.replace(prim_path="{ENV_REGEX_NS}/Robot") |
| | else: |
| | raise ValueError(f"Robot {args_cli.robot} is not supported. Valid: franka_panda, ur10") |
| |
|
| |
|
| | def run_simulator(sim: sim_utils.SimulationContext, scene: InteractiveScene): |
| | """Runs the simulation loop.""" |
| | |
| | |
| | robot = scene["robot"] |
| |
|
| | |
| | diff_ik_cfg = DifferentialIKControllerCfg(command_type="pose", use_relative_mode=False, ik_method="dls") |
| | diff_ik_controller = DifferentialIKController(diff_ik_cfg, num_envs=scene.num_envs, device=sim.device) |
| |
|
| | |
| | frame_marker_cfg = FRAME_MARKER_CFG.copy() |
| | frame_marker_cfg.markers["frame"].scale = (0.1, 0.1, 0.1) |
| | ee_marker = VisualizationMarkers(frame_marker_cfg.replace(prim_path="/Visuals/ee_current")) |
| | goal_marker = VisualizationMarkers(frame_marker_cfg.replace(prim_path="/Visuals/ee_goal")) |
| |
|
| | |
| | ee_goals = [ |
| | [0.5, 0.5, 0.7, 0.707, 0, 0.707, 0], |
| | [0.5, -0.4, 0.6, 0.707, 0.707, 0.0, 0.0], |
| | [0.5, 0, 0.5, 0.0, 1.0, 0.0, 0.0], |
| | ] |
| | ee_goals = torch.tensor(ee_goals, device=sim.device) |
| | |
| | current_goal_idx = 0 |
| | |
| | ik_commands = torch.zeros(scene.num_envs, diff_ik_controller.action_dim, device=robot.device) |
| | ik_commands[:] = ee_goals[current_goal_idx] |
| |
|
| | |
| | if args_cli.robot == "franka_panda": |
| | robot_entity_cfg = SceneEntityCfg("robot", joint_names=["panda_joint.*"], body_names=["panda_hand"]) |
| | elif args_cli.robot == "ur10": |
| | robot_entity_cfg = SceneEntityCfg("robot", joint_names=[".*"], body_names=["ee_link"]) |
| | else: |
| | raise ValueError(f"Robot {args_cli.robot} is not supported. Valid: franka_panda, ur10") |
| | |
| | robot_entity_cfg.resolve(scene) |
| | |
| | |
| | |
| | if robot.is_fixed_base: |
| | ee_jacobi_idx = robot_entity_cfg.body_ids[0] - 1 |
| | else: |
| | ee_jacobi_idx = robot_entity_cfg.body_ids[0] |
| |
|
| | |
| | sim_dt = sim.get_physics_dt() |
| | count = 0 |
| | |
| | while simulation_app.is_running(): |
| | |
| | if count % 150 == 0: |
| | |
| | count = 0 |
| | |
| | joint_pos = robot.data.default_joint_pos.clone() |
| | joint_vel = robot.data.default_joint_vel.clone() |
| | robot.write_joint_state_to_sim(joint_pos, joint_vel) |
| | robot.reset() |
| | |
| | ik_commands[:] = ee_goals[current_goal_idx] |
| | joint_pos_des = joint_pos[:, robot_entity_cfg.joint_ids].clone() |
| | |
| | diff_ik_controller.reset() |
| | diff_ik_controller.set_command(ik_commands) |
| | |
| | current_goal_idx = (current_goal_idx + 1) % len(ee_goals) |
| | else: |
| | |
| | jacobian = robot.root_physx_view.get_jacobians()[:, ee_jacobi_idx, :, robot_entity_cfg.joint_ids] |
| | ee_pose_w = robot.data.body_pose_w[:, robot_entity_cfg.body_ids[0]] |
| | root_pose_w = robot.data.root_pose_w |
| | joint_pos = robot.data.joint_pos[:, robot_entity_cfg.joint_ids] |
| | |
| | ee_pos_b, ee_quat_b = subtract_frame_transforms( |
| | root_pose_w[:, 0:3], root_pose_w[:, 3:7], ee_pose_w[:, 0:3], ee_pose_w[:, 3:7] |
| | ) |
| | |
| | joint_pos_des = diff_ik_controller.compute(ee_pos_b, ee_quat_b, jacobian, joint_pos) |
| |
|
| | |
| | robot.set_joint_position_target(joint_pos_des, joint_ids=robot_entity_cfg.joint_ids) |
| | scene.write_data_to_sim() |
| | |
| | sim.step() |
| | |
| | count += 1 |
| | |
| | scene.update(sim_dt) |
| |
|
| | |
| | ee_pose_w = robot.data.body_state_w[:, robot_entity_cfg.body_ids[0], 0:7] |
| | |
| | ee_marker.visualize(ee_pose_w[:, 0:3], ee_pose_w[:, 3:7]) |
| | goal_marker.visualize(ik_commands[:, 0:3] + scene.env_origins, ik_commands[:, 3:7]) |
| |
|
| |
|
| | def main(): |
| | """Main function.""" |
| | |
| | sim_cfg = sim_utils.SimulationCfg(dt=0.01, device=args_cli.device) |
| | sim = sim_utils.SimulationContext(sim_cfg) |
| | |
| | sim.set_camera_view([2.5, 2.5, 2.5], [0.0, 0.0, 0.0]) |
| | |
| | scene_cfg = TableTopSceneCfg(num_envs=args_cli.num_envs, env_spacing=2.0) |
| | scene = InteractiveScene(scene_cfg) |
| | |
| | sim.reset() |
| | |
| | print("[INFO]: Setup complete...") |
| | |
| | run_simulator(sim, scene) |
| |
|
| |
|
| | if __name__ == "__main__": |
| | |
| | main() |
| | |
| | simulation_app.close() |
| |
|