29
29
import isaaclab .utils .string as string_utils
30
30
from isaaclab .actuators import ActuatorBase , IdealPDActuatorCfg , ImplicitActuatorCfg
31
31
from isaaclab .assets import Articulation , ArticulationCfg
32
+ from isaaclab .envs .mdp .terminations import joint_pos_out_of_limit
33
+ from isaaclab .managers import SceneEntityCfg
32
34
from isaaclab .sim import build_simulation_context
33
35
from isaaclab .utils .assets import ISAAC_NUCLEUS_DIR
34
- from isaaclab .managers import SceneEntityCfg
35
- from isaaclab .envs .mdp .terminations import joint_pos_out_of_limit
36
36
37
37
##
38
38
# Pre-defined configs
@@ -659,7 +659,16 @@ def test_out_of_range_default_joint_vel(sim, device):
659
659
@pytest .mark .parametrize ("device" , ["cuda:0" , "cpu" ])
660
660
@pytest .mark .parametrize ("add_ground_plane" , [True ])
661
661
def test_joint_pos_limits (sim , num_articulations , device , add_ground_plane ):
662
- """Test write_joint_limits_to_sim API and validate limits via joint_pos_out_of_limit()."""
662
+ """Test write_joint_limits_to_sim API and when default pos falls outside of the new limits.
663
+ This test verifies that:
664
+ 1. Joint limits can be set correctly
665
+ 2. Default positions are preserved when setting new limits
666
+ 3. Joint limits can be set with indexing
667
+ 4. Invalid joint positions are properly handled
668
+ Args:
669
+ sim: The simulation fixture
670
+ num_articulations: Number of articulations to test
671
+ """
663
672
# Create articulation
664
673
articulation_cfg = generate_articulation_cfg (articulation_type = "panda" )
665
674
articulation , _ = generate_articulation (articulation_cfg , num_articulations , device )
@@ -674,6 +683,7 @@ def __init__(self, art):
674
683
675
684
# Play sim
676
685
sim .reset ()
686
+ # Check if articulation is initialized
677
687
assert articulation .is_initialized
678
688
679
689
# Get current default joint pos
@@ -689,6 +699,7 @@ def __init__(self, art):
689
699
torch .testing .assert_close (articulation ._data .joint_pos_limits , limits )
690
700
torch .testing .assert_close (articulation ._data .default_joint_pos , default_joint_pos )
691
701
702
+ # Set new joint limits that invalidate default joint pos
692
703
# Validate via function: no joint should be out of limits
693
704
out = joint_pos_out_of_limit (env , robot_all ) # [N]
694
705
assert torch .all (~ out )
@@ -731,6 +742,39 @@ def __init__(self, art):
731
742
assert torch .all (~ out )
732
743
733
744
745
+ @pytest .mark .parametrize ("num_articulations" , [1 , 2 ])
746
+ @pytest .mark .parametrize ("device" , ["cuda:0" , "cpu" ])
747
+ @pytest .mark .parametrize ("add_ground_plane" , [True ])
748
+ def test_joint_effort_limits (sim , num_articulations , device , add_ground_plane ):
749
+ """Validate joint effort limits via joint_effort_out_of_limit()."""
750
+ # Create articulation
751
+ articulation_cfg = generate_articulation_cfg (articulation_type = "panda" )
752
+ articulation , _ = generate_articulation (articulation_cfg , num_articulations , device )
753
+
754
+ # Minimal env wrapper exposing scene["robot"]
755
+ class _Env :
756
+ def __init__ (self , art ):
757
+ self .scene = {"robot" : art }
758
+
759
+ env = _Env (articulation )
760
+ robot_all = SceneEntityCfg (name = "robot" )
761
+
762
+ sim .reset ()
763
+ assert articulation .is_initialized
764
+
765
+ # Case A: no clipping → should NOT terminate
766
+ articulation ._data .computed_torque .zero_ ()
767
+ articulation ._data .applied_torque .zero_ ()
768
+ out = joint_effort_out_of_limit (env , robot_all ) # [N]
769
+ assert torch .all (~ out )
770
+
771
+ # Case B: simulate clipping → should terminate
772
+ articulation ._data .computed_torque .fill_ (100.0 ) # pretend controller commanded 100
773
+ articulation ._data .applied_torque .fill_ (50.0 ) # pretend actuator clipped to ±50
774
+ out = joint_effort_out_of_limit (env , robot_all ) # [N]
775
+ assert torch .all (out )
776
+
777
+
734
778
@pytest .mark .parametrize ("num_articulations" , [1 , 2 ])
735
779
@pytest .mark .parametrize ("device" , ["cuda:0" , "cpu" ])
736
780
def test_external_force_buffer (sim , num_articulations , device ):
0 commit comments