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

feat: add clip range of JointAction #1476

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

fan-ziqi
Copy link
Contributor

@fan-ziqi fan-ziqi commented Nov 28, 2024

Description

Add action clip to all mdp/actions

Type of change

  • New feature (non-breaking change which adds functionality)
  • This change requires a documentation update

Checklist

  • I have run the pre-commit checks with ./isaaclab.sh --format
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • I have updated the changelog and the corresponding version in the extension's config/extension.toml file
  • I have added my name to the CONTRIBUTORS.md or my name already exists there

@jtigue-bdai
Copy link
Collaborator

Currently limits are handled by the actuators. Primarily this is done on the effort.

@fan-ziqi
Copy link
Contributor Author

fan-ziqi commented Dec 5, 2024

So how can I clip actions in isaaclab like in legged_gym?

@jtigue-bdai
Copy link
Collaborator

Hmm I guess if you are using joint position commands the actuator limits won't really handle that. Actuator limits really only do effort.

I will take another look at the current api and get back to you.

@fan-ziqi
Copy link
Contributor Author

fan-ziqi commented Dec 5, 2024

Thanks for reply!
Yes, I use Δjoint_pos as actions

@kellyguo11
Copy link
Contributor

The discussion in this PR may be relevant - #984. This seems like something that would make more sense for the wrappers.

@fan-ziqi
Copy link
Contributor Author

fan-ziqi commented Dec 5, 2024

Which method is better? I don't know if this should be an env feature or an action feature

@jtigue-bdai
Copy link
Collaborator

jtigue-bdai commented Dec 5, 2024

Yeah #984 makes the clip for all actions where this PR will makes the clip configurable for each action separately. To me it makes sense to have the action handle the clipping rather than the environment.

@jtigue-bdai
Copy link
Collaborator

I guess this one only handles the joint_actions.

@fan-ziqi
Copy link
Contributor Author

fan-ziqi commented Dec 5, 2024

For me, this allows more flexibility in configuring each joint individually.

So is this PR necessary?
Should we adopt this or #984?

@kellyguo11
Copy link
Contributor

That's a good point, this could be useful for configuring the joints separately, but only applicable for joint actions. Perhaps there's value in adopting both approaches.

@jtigue-bdai
Copy link
Collaborator

I could see both and also adding the clip configuration at the base ActionTerm/Cfg. It would just require that the actual processing be added to all provided actions.

@jtigue-bdai
Copy link
Collaborator

Hey @fan-ziqi would you be willing to add the clipping cfg to the top level ActionTermCfg, the clip checking in the top level ActionTerm.init , and then add the clipping execution to all the provided actions in the envs/mdp/actions directory?

@fan-ziqi fan-ziqi requested a review from jtigue-bdai as a code owner December 7, 2024 03:45
@fan-ziqi
Copy link
Contributor Author

fan-ziqi commented Dec 7, 2024

I have added clip to ActionTermCfg and added clip action to all mdp/actions

But I have a question, is clip: dict[str, tuple] necessary?

@configclass
class ActionsCfg:
    """Action specifications for the MDP."""

    joint_pos = mdp.JointPositionActionCfg(
        asset_name="robot", joint_names=[".*"], scale=0.5, use_default_offset=True, clip={".*": (-100.0, 100.0)}
    )

or clip: tuple[float, float] is enough

@configclass
class ActionsCfg:
    """Action specifications for the MDP."""

    joint_pos = mdp.JointPositionActionCfg(
        asset_name="robot", joint_names=[".*"], scale=0.5, use_default_offset=True, clip=(-100.0, 100.0)
    )

@jtigue-bdai
Copy link
Collaborator

I think being able to do clip=dict[str,tuple] is necessary to be able to set clips on a per joint basis.

@kellyguo11
Copy link
Contributor

Thanks a lot for the feature! would it be possible to add some unit tests for it as well?

@@ -115,6 +123,13 @@ def process_actions(self, actions: torch.Tensor):
binary_mask = actions < 0
# compute the command
self._processed_actions = torch.where(binary_mask, self._close_command, self._open_command)
# clip actions
if self._clip is not None:
# resolve the dictionary config
Copy link
Contributor

Choose a reason for hiding this comment

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

is it possible to resolve this once at initialization and convert to a torch tensor to avoid more overhead with the loop?

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.

3 participants