How to implement gripper open/close action?

I try to implement a custom robot model to grasp a cube object base on FrankaCabinet Example.
I want to present the action of the gripper with open/close instead of the continuous joint state.Is there some example that using the 0/1 action tensor?

I have tried doing that by multiplying -1 or 1 to the gripper joint position according to the action tensor like this:

def set_gripper(self,gripper_action):
    gripper_state = torch.where(gripper_action <= 0.0,-1.0,1.0) #if action tensor <= 0 return -1
    self.sia5_dof_targets[:, 8:] = 0.785398*gripper_state #set -45 or 45 degree to gripper joint
    self.gym.set_dof_position_target_tensor(self.sim,
                                            gymtorch.unwrap_tensor(self.sia5_dof_targets))
    
def pre_physics_step(self, actions):
    num_non_gripper_dofs = self.num_sia5_dofs-2
    self.actions = actions.clone().to(self.device) #numAction is 9 for 8 joints and 1 gripper
    self.set_gripper(self.actions[:,8:]) #pass last action to open/close gripper
    targets = self.sia5_dof_targets[:, :num_non_gripper_dofs] + self.sia5_dof_speed_scales[:num_non_gripper_dofs] * self.dt * self.actions[:,:num_non_gripper_dofs] * self.action_scale  
    self.sia5_dof_targets[:, :num_non_gripper_dofs] = tensor_clamp(
        targets, self.sia5_dof_lower_limits[:num_non_gripper_dofs], self.sia5_dof_upper_limits[ :num_non_gripper_dofs])
    
    self.gym.set_dof_position_target_tensor(self.sim,
                                            gymtorch.unwrap_tensor(self.sia5_dof_targets))

Is there a more proper way to implement an open/close gripper?

1 Like

Hi @chana.pol.peter,

I think it’s a totally valid way of doing it. Some tuning of the position controller (motor) parameters - stiffness, damping, max force (effort), joint friction as well as of sia5_dof_speed_scales could be required to match the behaviour of the real robot, but overall it looks good.

Thank you for your reply.
I will try tuning as you suggested.

1 Like