Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix spacemouse action transformation direction #38

Merged
merged 4 commits into from
Apr 25, 2024
Merged

Conversation

charlesxu0124
Copy link
Collaborator

Hi all, this includes the fix for the spacemouse intervention action transformation bug that was found this week. The spacemouse actions are given in the base frame, so it should be transformed into the end-effector frame to be learned by the policy. Previously, the transformation from end-effector frame to base frame was applied to this action.

@@ -94,3 +94,12 @@ def transform_action(self, action: np.ndarray):
action = np.array(action) # in case action is a jax read-only array
action[:6] = self.adjoint_matrix @ action[:6]
return action

def transform_action_inv(self, action: np.ndarray):
"""
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you add description that this assumes last dimension is gripper open/close?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's actually description in the docstring for the entire wrapper class. It just requires the first 6 dimensions to be translation+rotation, and does not assume anything about gripper dimension.

class RelativeFrame(gym.Wrapper):
    """
    This wrapper transforms the observation and action to be expressed in the end-effector frame.
    Optionally, it can transform the tcp_pose into a relative frame defined as the reset pose.

    This wrapper is expected to be used on top of the base Franka environment, which has the following
    observation space:
    {
        "state": spaces.Dict(
            {
                "tcp_pose": spaces.Box(-np.inf, np.inf, shape=(7,)), # xyz + quat
                ......
            }
        ),
        ......
    }, and at least 6 DoF action space with (x, y, z, rx, ry, rz, ...)
    """

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, then what's the assumption for the 7th>?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't assume anything for the 7th. It can also be non-existant. All the code only indices the first 6 dimensions action[:6]

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

then can we add a simple description of the expected 7th dimension? e.g., discrete/continuous gripper status

@jianlanluo
Copy link
Collaborator

please also fix the precommit error

actions = np.zeros((6,))
next_obs, rew, done, truncated, info = env.step(action=actions)
if "intervene_action" in info:
actions = info["intervene_action"]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how does this code run correctly without issues previously?

if "intervene_action" is None, the previous code always assumes
actions = info["intervene_action"]

and this doesn't throw out errors?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My bad, there was a change in the IntervenetionWrapper that I missed. Now it puts intervene_action in info only if intervene_action is nonzero

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i was more talking the code in the left

        next_obs, rew, done, truncated, info = env.step(action=np.zeros((7,)))
        actions = info["intervene_action"]

does this code run without issues previously? the actions can be unassigned in certain cases

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it used to be always assigned. If no intervention was provided, then the policy action is just put in info['intervene_action'], but this meant the intervene_action were in two different frames depending on whether it's from the policy or the spacemouse

serl_robot_infra/franka_env/envs/relative_env.py Outdated Show resolved Hide resolved

def step(self, action):
new_action = self.action(action)

new_action, replaced = self.action(action)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

replaced is always False?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's set to true in line 205, which is when the current time is within 0.5 seconds of the previous nonzero spacemouse action (0.5 sec delay until the control is handed back to the policy)

@jianlanluo
Copy link
Collaborator

did you get this code tested on real robot ?

@jianlanluo jianlanluo merged commit 2196685 into main Apr 25, 2024
1 check passed
@jianlanluo jianlanluo deleted the action_fix branch April 25, 2024 22:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants