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

In the example above, it seems that the fingers move independently. If one finger is obstructed and unable to reach the target position, the other finger will continue to move towards it’s own target position. Is it possible to create a constraint so that the gripper fingers to move and stop together?

Hi

It’s possible, but I think the above script makes the action of “2 gripper” the action of “1 gripper(finger?)”.
Therefore, it seems that abovescript have already achieved what you want to do.

Taking “franka_cabinet.py” as an example, it reduces the action of “rfinger” and makes “rfinger” follow “lfinger” in the opposite direction.
Below are some changes.

self.cfg [“ env”] [“ numActions”] = 9

self.cfg [“ env”] [“ numActions”] = 8

self.franka_default_dof_pos = to_torch([1.157、-1.066、-0.155、-2.239、-1.841、1.003、0.469、0.035、0.035]、device = self.device)

self.franka_default_dof_pos = to_torch([1.157、-1.066、-0.155、-2.239、-1.841、1.003、0.469、0.035]、device = self.device)

franka_dof_stiffness = to_torch(
[400、400、400、400、400、400、400、1.0e6、1.0e6]、dtype = torch.float、device = self.device)
franka_dof_damping = to_torch(
[ 80、80、80、80 、80、80、80、1.0e2、1.0e2]、dtype = torch.float、device = self.device)

franka_dof_stiffness = to_torch(
[400、400、400、400、400、400、400、1.0e6]、 dtype = torch.float、device = self.device)
franka_dof_damping = to_torch(
[80、80、80、80、80、80、80、1.0e2]、dtype = torch.float、device = self.device)

self.franka_dof_speed_scales [[7、8]] = 0.1
franka_dof_props [‘effort’] [7] = 200
franka_dof_props [‘effort’] [8] = 200

self.franka_dof_speed_scales [[7]] = 0.1
franka_dof_props [‘effort’ ] [7] = 200