| | |
| | |
| | |
| | |
| |
|
| | import argparse |
| |
|
| | from isaaclab.app import AppLauncher |
| |
|
| | |
| | parser = argparse.ArgumentParser( |
| | description="This script demonstrates adding a custom robot to an Isaac Lab environment." |
| | ) |
| | parser.add_argument("--num_envs", type=int, default=1, 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 |
| |
|
| | import numpy as np |
| | import torch |
| |
|
| | import isaaclab.sim as sim_utils |
| | from isaaclab.actuators import ImplicitActuatorCfg |
| | from isaaclab.assets import AssetBaseCfg |
| | from isaaclab.assets.articulation import ArticulationCfg |
| | from isaaclab.scene import InteractiveScene, InteractiveSceneCfg |
| | from isaaclab.utils.assets import ISAAC_NUCLEUS_DIR |
| |
|
| | JETBOT_CONFIG = ArticulationCfg( |
| | spawn=sim_utils.UsdFileCfg(usd_path=f"{ISAAC_NUCLEUS_DIR}/Robots/NVIDIA/Jetbot/jetbot.usd"), |
| | actuators={"wheel_acts": ImplicitActuatorCfg(joint_names_expr=[".*"], damping=None, stiffness=None)}, |
| | ) |
| |
|
| | DOFBOT_CONFIG = ArticulationCfg( |
| | spawn=sim_utils.UsdFileCfg( |
| | usd_path=f"{ISAAC_NUCLEUS_DIR}/Robots/Yahboom/Dofbot/dofbot.usd", |
| | rigid_props=sim_utils.RigidBodyPropertiesCfg( |
| | disable_gravity=False, |
| | max_depenetration_velocity=5.0, |
| | ), |
| | articulation_props=sim_utils.ArticulationRootPropertiesCfg( |
| | enabled_self_collisions=True, solver_position_iteration_count=8, solver_velocity_iteration_count=0 |
| | ), |
| | ), |
| | init_state=ArticulationCfg.InitialStateCfg( |
| | joint_pos={ |
| | "joint1": 0.0, |
| | "joint2": 0.0, |
| | "joint3": 0.0, |
| | "joint4": 0.0, |
| | }, |
| | pos=(0.25, -0.25, 0.0), |
| | ), |
| | actuators={ |
| | "front_joints": ImplicitActuatorCfg( |
| | joint_names_expr=["joint[1-2]"], |
| | effort_limit_sim=100.0, |
| | velocity_limit_sim=100.0, |
| | stiffness=10000.0, |
| | damping=100.0, |
| | ), |
| | "joint3_act": ImplicitActuatorCfg( |
| | joint_names_expr=["joint3"], |
| | effort_limit_sim=100.0, |
| | velocity_limit_sim=100.0, |
| | stiffness=10000.0, |
| | damping=100.0, |
| | ), |
| | "joint4_act": ImplicitActuatorCfg( |
| | joint_names_expr=["joint4"], |
| | effort_limit_sim=100.0, |
| | velocity_limit_sim=100.0, |
| | stiffness=10000.0, |
| | damping=100.0, |
| | ), |
| | }, |
| | ) |
| |
|
| |
|
| | class NewRobotsSceneCfg(InteractiveSceneCfg): |
| | """Designs the scene.""" |
| |
|
| | |
| | ground = AssetBaseCfg(prim_path="/World/defaultGroundPlane", spawn=sim_utils.GroundPlaneCfg()) |
| |
|
| | |
| | dome_light = AssetBaseCfg( |
| | prim_path="/World/Light", spawn=sim_utils.DomeLightCfg(intensity=3000.0, color=(0.75, 0.75, 0.75)) |
| | ) |
| |
|
| | |
| | Jetbot = JETBOT_CONFIG.replace(prim_path="{ENV_REGEX_NS}/Jetbot") |
| | Dofbot = DOFBOT_CONFIG.replace(prim_path="{ENV_REGEX_NS}/Dofbot") |
| |
|
| |
|
| | def run_simulator(sim: sim_utils.SimulationContext, scene: InteractiveScene): |
| | sim_dt = sim.get_physics_dt() |
| | sim_time = 0.0 |
| | count = 0 |
| |
|
| | while simulation_app.is_running(): |
| | |
| | if count % 500 == 0: |
| | |
| | count = 0 |
| | |
| | root_jetbot_state = scene["Jetbot"].data.default_root_state.clone() |
| | root_jetbot_state[:, :3] += scene.env_origins |
| | root_dofbot_state = scene["Dofbot"].data.default_root_state.clone() |
| | root_dofbot_state[:, :3] += scene.env_origins |
| |
|
| | |
| | scene["Jetbot"].write_root_pose_to_sim(root_jetbot_state[:, :7]) |
| | scene["Jetbot"].write_root_velocity_to_sim(root_jetbot_state[:, 7:]) |
| | scene["Dofbot"].write_root_pose_to_sim(root_dofbot_state[:, :7]) |
| | scene["Dofbot"].write_root_velocity_to_sim(root_dofbot_state[:, 7:]) |
| |
|
| | |
| | joint_pos, joint_vel = ( |
| | scene["Jetbot"].data.default_joint_pos.clone(), |
| | scene["Jetbot"].data.default_joint_vel.clone(), |
| | ) |
| | scene["Jetbot"].write_joint_state_to_sim(joint_pos, joint_vel) |
| | joint_pos, joint_vel = ( |
| | scene["Dofbot"].data.default_joint_pos.clone(), |
| | scene["Dofbot"].data.default_joint_vel.clone(), |
| | ) |
| | scene["Dofbot"].write_joint_state_to_sim(joint_pos, joint_vel) |
| | |
| | scene.reset() |
| | print("[INFO]: Resetting Jetbot and Dofbot state...") |
| |
|
| | |
| | if count % 100 < 75: |
| | |
| | action = torch.Tensor([[10.0, 10.0]]) |
| | else: |
| | |
| | action = torch.Tensor([[5.0, -5.0]]) |
| |
|
| | scene["Jetbot"].set_joint_velocity_target(action) |
| |
|
| | |
| | wave_action = scene["Dofbot"].data.default_joint_pos |
| | wave_action[:, 0:4] = 0.25 * np.sin(2 * np.pi * 0.5 * sim_time) |
| | scene["Dofbot"].set_joint_position_target(wave_action) |
| |
|
| | scene.write_data_to_sim() |
| | sim.step() |
| | sim_time += sim_dt |
| | count += 1 |
| | scene.update(sim_dt) |
| |
|
| |
|
| | def main(): |
| | """Main function.""" |
| | |
| | sim_cfg = sim_utils.SimulationCfg(device=args_cli.device) |
| | sim = sim_utils.SimulationContext(sim_cfg) |
| | sim.set_camera_view([3.5, 0.0, 3.2], [0.0, 0.0, 0.5]) |
| | |
| | scene_cfg = NewRobotsSceneCfg(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() |
| |
|