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

Access joint limit violation force without using xml sensors. #126

Closed
P-Schumacher opened this issue Dec 22, 2023 · 4 comments
Closed

Access joint limit violation force without using xml sensors. #126

P-Schumacher opened this issue Dec 22, 2023 · 4 comments
Labels
enhancement New feature or request

Comments

@P-Schumacher
Copy link
Collaborator

Hi everyone,
several people have approached me to ask how to implement joint limit violation forces, as used in my recent preprint

My implementation uses limit force sensors embedded in the xml files. These are quite inconvenient and it's not always possible to edit the xml files for every model.

I'm wondering if there is a programmatic way of accessing this information? I think it would be a great service to the community to implement a function like

force_value = get_limitfrc(joint_name)

But I'm a bit unsure how to do it. I tried starting with efc_type and efc_force, but it's unclear how you would relate this to the joint name.

@P-Schumacher P-Schumacher added the enhancement New feature or request label Dec 22, 2023
@elladyr
Copy link
Collaborator

elladyr commented Dec 23, 2023

One suggested way in this issue here, might help. Essentially, you measure the joint torque with qfrc_constraint and qfrc_smooth in the joint data structure, then manually check if your joint exceeds the limits.

@P-Schumacher
Copy link
Collaborator Author

P-Schumacher commented Dec 23, 2023

This would get you the total force acting on the joint, right? It’s a proxy, but not perfect.

EDIT: Let me try, might be a solution

@P-Schumacher
Copy link
Collaborator Author

P-Schumacher commented Dec 29, 2023

The posted solution works when there ar eno additional constraints, e.g. an arm that is suspended in the air. Still have to test in the case of contact forces etc

EDIT: Doesn't seem to work when other constraints are present. I think we would need to filter all constraints by joint limit constraints and assign the right joint to each one at each time step

@P-Schumacher
Copy link
Collaborator Author

Got it:

def get_limitfrc(joint_name, mj_model, mj_data):
    non_joint_limit_efc_idxs = np.where(mj_data.efc_type != mujoco.mjtConstraint.mjCNSTR_LIMIT_JOINT)[0]
    only_jnt_lim_efc_force = mj_data.efc_force.copy()
    only_jnt_lim_efc_force[non_joint_limit_efc_idxs] = 0.0
    joint_force = np.zeros((mj_model.nv,))
    mujoco.mj_mulJacTVec(mj_model, mj_data, joint_force, only_jnt_lim_efc_force)
    return joint_force[mj_model.joint(joint_name).dofadr]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants