55Example:
66```python
77from crisp_gym.envs import make_env
8+ :wa
89
910env = make_env(
1011 env_type="manipulator_cartesian",
@@ -150,7 +151,6 @@ def __init__(
150151 }
151152 )
152153 self ._previous_rotation_vector : NDArray | None = None
153- self ._previous_target_rotation_vector : NDArray | None = None
154154 self ._uninitialized = True
155155
156156 def _should_check_proper_orientation_representation (self ) -> bool :
@@ -590,6 +590,17 @@ def __init__(self, config: ManipulatorEnvConfig, namespace: str = ""):
590590 ),
591591 },
592592 )
593+ if ObservationKeys .TARGET_DISPLACEMENT_OBS in self .config .observations_to_include_to_state :
594+ self .observation_space : gym .spaces .Dict = gym .spaces .Dict (
595+ {
596+ ** self .observation_space .spaces ,
597+ ObservationKeys .TARGET_DISPLACEMENT_OBS : gym .spaces .Box (
598+ low = - np .ones ((target_dim + 1 ,), dtype = np .float32 ), # +1 for gripper
599+ high = np .ones ((target_dim + 1 ,), dtype = np .float32 ),
600+ dtype = np .float32 ,
601+ ),
602+ },
603+ )
593604
594605 # Create action space with appropriate rotation dimension
595606 rot_low = - np .ones ((rot_dim ,), dtype = np .float32 ) * np .pi
@@ -619,10 +630,19 @@ def __init__(self, config: ManipulatorEnvConfig, namespace: str = ""):
619630 dtype = np .float32 ,
620631 )
621632
633+ self ._previous_target_rotation_vector : NDArray | None = None
634+ self ._previous_target_displacement_rotation_vector : NDArray | None = None
635+
622636 @override
623637 def _get_obs (self ) -> dict :
624638 obs = super ()._get_obs ()
625- # Get target pose with configured orientation representation
639+ if (
640+ ObservationKeys .TARGET_DISPLACEMENT_OBS
641+ not in self .config .observations_to_include_to_state
642+ and ObservationKeys .TARGET_OBS not in self .config .observations_to_include_to_state
643+ ):
644+ return obs
645+
626646 if ObservationKeys .TARGET_OBS in self .config .observations_to_include_to_state :
627647 target_pose_array = self .robot .target_pose .to_array (
628648 representation = self .config .orientation_representation
@@ -633,6 +653,25 @@ def _get_obs(self) -> dict:
633653 )
634654 self ._previous_target_rotation_vector = target_pose_array [3 :]
635655 obs [ObservationKeys .TARGET_OBS ] = target_pose_array .astype (np .float32 )
656+
657+ if ObservationKeys .TARGET_DISPLACEMENT_OBS in self .config .observations_to_include_to_state :
658+ delta_pose = self .robot .target_pose - self .robot .end_effector_pose
659+ delta_pose_array = delta_pose .to_array (
660+ representation = self .config .orientation_representation
661+ )
662+ if self ._should_check_proper_orientation_representation ():
663+ delta_pose_array = self ._flip_rotation_vector_if_needed (
664+ self ._previous_target_displacement_rotation_vector , delta_pose_array
665+ )
666+ self ._previous_target_displacement_rotation_vector = delta_pose_array [3 :]
667+ gripper_value = (
668+ self .gripper .target - self .gripper .value if self .gripper is not None else 0.0
669+ )
670+ obs [ObservationKeys .TARGET_DISPLACEMENT_OBS ] = np .concatenate (
671+ [delta_pose_array , np .array ([gripper_value ], dtype = np .float32 )],
672+ axis = 0 ,
673+ ).astype (np .float32 )
674+
636675 return obs
637676
638677 @override
0 commit comments