Reproduce to specific state doesn't work

I want to see the effect of actions from the same state in isaac gym. (box pushing task to goal position)
So, I made ‘back to state’ function to go back to previous state (before action done) like below

    def back_to_state(self, state, goal, target_pos):

    env_ids = torch.arange(self.num_envs, device=self.device)
    env_ids_int32 = env_ids.to(dtype=torch.int32)

    # reset robot
    self.robot_dof_pos[env_ids, :] = state[:,:self.num_robot_dofs]
    self.robot_dof_vel[env_ids, :] = state[:,self.num_robot_dofs:2*self.num_robot_dofs] 

    # target 
    multi_env_ids_int32 = self.global_indices[env_ids, 0:1].flatten()
    self.gym.set_dof_state_tensor_indexed(self.sim,
                                          gymtorch.unwrap_tensor(self.dof_state),
                                          gymtorch.unwrap_tensor(multi_env_ids_int32), len(multi_env_ids_int32))
    
    self.gym.set_dof_position_target_tensor_indexed(self.sim,
                                                     gymtorch.unwrap_tensor(target_pos),
                                                     gymtorch.unwrap_tensor(multi_env_ids_int32), len(multi_env_ids_int32))

    # reset box & goal random position
    self.goal_states[env_ids,:, :7] = goal[:,:]
    self.object_states[env_ids,:, :13] = state[:,2*self.num_robot_dofs:2*self.num_robot_dofs+13]
    setting_indices = self.global_indices[env_ids, 2:].flatten()
    self.gym.set_actor_root_state_tensor_indexed(self.sim,
                                                    gymtorch.unwrap_tensor(self.root_state_tensor),
                                                    gymtorch.unwrap_tensor(setting_indices), len(setting_indices))
    
    self.compute_observations()
    self.render()

The target pos is the previous target pos.
In compute_observation, every refrech function exist.

    self.gym.refresh_actor_root_state_tensor(self.sim)
    self.gym.refresh_rigid_body_state_tensor(self.sim)
    self.gym.refresh_dof_state_tensor(self.sim)

    # refresh force sensor & net contact force
    self.gym.refresh_force_sensor_tensor(self.sim)
    self.gym.refresh_net_contact_force_tensor(self.sim)

I found that root state and dof state is changed to previous state.
but I cant reproduce the same state because of rigid body states.
It means that robot’s root body state is changed, but remain body states are not changed to previous step.

I know there are set rigid_body_state(_tensor). but it works only in FLEX engine or cpu.
(I’m using ‘PHYSX’ to use some functions)
I also try in ‘cpu’ pipe line, but it said I can’t set rigid body states except root body.

Is there any method to reproduce the specific state?

2 Likes