-
Notifications
You must be signed in to change notification settings - Fork 506
Fix projected gravity calculation in legged_robot.py #54
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
base: master
Are you sure you want to change the base?
Conversation
Update legged_robot.py
No. It is quat_rotate_inverse. |
@SUZ-tsinghua, I wanted to bring your attention to a specific line of code in the NVIDIA-Omniverse IsaacGymEnvs repository. Have you had a chance to review it? Here is the link for reference: https://github.com/NVIDIA-Omniverse/IsaacGymEnvs/blob/aeed298638a1f7b5421b38f5f3cc2d1079b6d9c3/isaacgymenvs/tasks/anymal.py#L372. In this updated version of the repository, you'll notice that the function |
@curieuxjy But you can directly verify the correctness of the code by running base_quat = torch.tensor([[0.0, 0.7071, 0.0, 0.7071]]) projected_gravity_inverse = quat_rotate_inverse(base_quat, gravity_vec) print("projected gravity inverse",projected_gravity_inverse) It rotates the base frame so the x axis of the base frame is the -z axis of the env frame. And projected_gravity_inverse is [1,0,0] but projected_gravity is [-1,0,0]. |
@SUZ-tsinghua @curieuxjy The x and y components of the former are related to the yaw rotation, while the x and y components of the latter are unrelated to yaw. Additionally, the z components of both are actually equal. It should be more reasonable to exclude the yaw component because locomotion is essentially unrelated to yaw. In the latest IsaacLab implementation, quat_rotate_inverse is used. As for why IsaacGymEnvs can also use quat_rotate—adding yaw merely introduces irrelevant information, which may make training slightly more difficult, but it still works. quat_rotate得到的是全局坐标系下 机器人法线(机器人坐标系中的[0,0,-1]指向身体下方的向量, 跟随机器人运动)的坐标 |
@SUZ-tsinghua @curieuxjy use this to test import isaacgym
from isaacgym.torch_utils import *
yaw=torch.tensor([0,35.]).deg2rad()
roll=torch.tensor([10,10.]).deg2rad()
pitch=torch.tensor([15,15.]).deg2rad()
zero=torch.zeros(2)
q1=quat_from_euler_xyz(zero,zero,yaw)
q2=quat_from_euler_xyz(roll,pitch,zero)
q=quat_mul(q1,q2)
g = torch.tensor([0,0,-1.]).unsqueeze(0).repeat(2,1)
print(quat_rotate(q,g))
print(quat_rotate_inverse(q,g)) output
|
@luoye2333 This vector will be input into the observation vector. Guess how you get this vector during deployment? |
@SUZ-tsinghua Do you mean yaw? Yaw is available in most imu. though this may accumlate error when time increases. |
@luoye2333 I mean projected_gravity. If you use quat_rotate_inverse(), this vector can be directly obtained by imu. That's why we use quat_rotate_inverse() instead of quat_rotate(). |
@luoye2333 I just want to say, quat_rotate() might work when training, but quat_rotate_inverse() is more intuitive considering deployment. |
I agree. |
(Update legged_robot.py)
The misfunction for calculating projected gravity should be resolved by changing
quat_rotate_inverse
to thequat_rotate
function for calculating the projected_gravity vector.