haosulab / SAPIEN

SAPIEN Embodied AI Platform
https://sapien.ucsd.edu/
MIT License
427 stars 41 forks source link

Fail to completely execute the desirable action in sapien env #144

Closed piao-0429 closed 11 months ago

piao-0429 commented 12 months ago

System:

Describe the bug I create an env with sapien but when I execute a planned action with env.step(action), where action is the target pose of the end effector (8-dim: 3 for pos, 4 for quat, 1 for gripper), it cannot reach my desired pose (but it manages to move in the correct direction). I guess it may be some problem with my simulation time or planning timestep, etc. But I cannot discover how to fix this problem.

Additional context Some reference code here:

self._sim_freq = 500
self._control_freq = 100
self._sim_steps_per_control = self._sim_freq // self._control_freq
self.dt = 1.0 / (self._control_freq / self._sim_freq)

    def step(self, action): 
        self.current_step += 1
        self.success_planned = self.move_to_pose(action)

    def move_to_pose(self, action):
        pose = action[:-1]   
        open_gripper = action[-1]  
        self.plan_timestep = 0.1
        result = self.planner.plan_screw(pose, self.agent.get_qpos(), time_step=self.plan_timestep) # mplib.Planner
        if result["status"] != "Success":
            self.scene.step()
            return 1
        self.follow_path(result)
        return 0

    def follow_path(self, result):
        n_step = result["position"].shape[0]
        assert n_step > 0, "no path"
        min_step = int(self._sim_freq * self.plan_timestep * 2)
        for i in range(min(min_step, n_step)):
            for j in range(7):
                self.active_joints[j].set_drive_target(result["position"][i][j])
                self.active_joints[j].set_drive_velocity_target(result["velocity"][i][j])
            self.scene.step()
fbxiang commented 11 months ago

Based on the description, it sounds like the most probably cause is that you did not balance passive force. Can you verify you have followed the tutorial here? https://sapien.ucsd.edu/docs/2.2/tutorial/robotics/basic_robot.html#compensate-passive-forces-e-g-gravity

piao-0429 commented 11 months ago

I've fixed this problem by balancing passive force! Thanks for your help!