Reset the joints position of a manipulator, to implement 'reset' function of Gymnasium

Typically: "How do I... ", "How can I... " questions
Post Reply
Jiaxin
Posts: 2
Joined: 01 Mar 2022, 08:26

Reset the joints position of a manipulator, to implement 'reset' function of Gymnasium

Post by Jiaxin »

Requirements: Reset the position of 6 joints

My solution (Problem: joint position is not aligned with the value we set. We can raise the times of calling sim.step(), but it is inefficient)

Code: Select all

	initial_positions = self.np_random.uniform(-np.pi / 3, np.pi / 3, size=6)

        self._set_joint_mode('position')
        for i, joint in enumerate(self.general_joints):
            self.sim.setJointTargetPosition(joint, float(initial_positions[i]))

        for i in range(20):
            self.sim.step()
        
Scene: A UR5 manipulator
Coppeliasim: v4.10 Edu
Windows 11
Additional info: Dyn control enabled
fferri
Posts: 1339
Joined: 09 Sep 2013, 19:28

Re: Reset the joints position of a manipulator, to implement 'reset' function of Gymnasium

Post by fferri »

If I understood correctly, you want to reset simulation to a given state, without stopping and starting the simulation, so in that case don't set joint target position, which would take several simulation steps to reach; instead, set joint position directly (sim.setJointPosition) and then call sim.resetDynamicObject
Post Reply