Warning while calling function with self._world.step(render=self._render) in the control_frequency_inv loop

I am trying to realize a long-term decision task A in OmniIsaacGymEnvs, so I set dt to 1/60 s and control_frequency_inv to 180(execute every 3s). Besides I also want to execute another function B every world frame, so I add it to the control_frequency_inv loop. However I got the warning below.

2023-06-21 14:01:55 [69,210ms] [Warning] [omni.physx.tensors.plugin] GPU tensor function setRootTransforms: calling a setter after flush may result in incorrect values!

according to my test, the reason is the calling of set_joint_velocity_targets in function B. How can I avoid this warning?

my code where the functionB is added:

def step(self, actions):
    if self._task.randomize_actions:
        actions = self._task._dr_randomizer.apply_actions_randomization(actions=actions, reset_buf=self._task.reset_buf)

    actions = torch.clamp(actions, -self._task.clip_actions, self._task.clip_actions).to(self._task.device).clone()

    self._task.pre_physics_step(actions)
    
    for _ in range(self._task.control_frequency_inv):
        self._task.functionB()
        self._world.step(render=self._render)
        self.sim_frame_count += 1
        
    
    self._obs, self._rew, self._resets, self._extras = self._task.post_physics_step()

    if self._task.randomize_observations:
        self._obs = self._task._dr_randomizer.apply_observations_randomization(
            observations=self._obs.to(device=self._task.rl_device), reset_buf=self._task.reset_buf)

    self._states = self._task.get_states()
    self._process_data()
    
    obs_dict = {"obs": self._obs, "states": self._states}

    return obs_dict, self._rew, self._resets, self._extras

The warning message you’re seeing is indicating that you’re trying to set the joint velocity targets after the physics simulation has been updated (flushed). This can result in incorrect values because the joint velocity targets should be set before the physics simulation is updated.

Here’s how you can avoid this warning:

  1. Make sure to call set_joint_velocity_targets() before calling step(). The step() method updates the physics simulation, so any changes to the joint velocity targets should be made before calling step().
  2. If you need to call set_joint_velocity_targets() multiple times in a loop, make sure to call step() after each call to set_joint_velocity_targets(). This ensures that the physics simulation is updated after each change to the joint velocity targets.

Here’s an example of how you can modify your code:

def step(self, actions):
    # ... (same as before)

    for _ in range(self._task.control_frequency_inv):
        self._task.functionB()  # Call set_joint_velocity_targets() here
        self._world.step(render=self._render)  # Then immediately update the physics simulation
        self.sim_frame_count += 1

    # ... (same as before)

In this modified code, set_joint_velocity_targets() is called in functionB(), and then the physics simulation is immediately updated by calling step(). This ensures that the joint velocity targets are correctly applied before the physics simulation is updated.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.