frankaemika / franka_ros

ROS integration for Franka research robots
https://frankaemika.github.io
Apache License 2.0
364 stars 313 forks source link

Why no gravity term when computing tau in cartesian_impedance_example_controller? #340

Open Yitian-Xian opened 1 year ago

Yitian-Xian commented 1 year ago

Hello, may I know why there is no gravity term when computing 'tau_d'?

This term is added by tau_d << tau_task + tau_nullspace + coriolis, which are from Cartesian PD control, nullspace PD control, and the coriolis effect.

Could anyone explain that? Thank you very much.

rickstaa commented 1 year ago

Hey @Yitian-Xian,

I just noticed that your last response got lost in my mailbox. I hope you've resolved your issues, and I apologize for the delay in getting back to you 😅. If it's okay with you, I'll provide an answer here so that others can also refer to it. However, please remember that I'm not part of the @frankaemika team but an end user. So, there's a chance I may have misunderstood certain aspects.


Regarding your question above and the following question in the email:

Does this mean that gravity is always compensated in simulation, so we don't need to include the gravity term when calculating the torque? I've reviewed all the examples in the franka_example_controllers package and have yet to find any of them, including the gravity term.

You are correct in observing that gravity compensation is applied in the simulation (specifically, franka_gazebo). You can see it in the code snippet here:

https://github.com/frankaemika/franka_ros/blob/d439fc7d66a3edb890eefb0fa955f6d7042cac12/franka_gazebo/src/franka_hw_sim.cpp#L512

As a result, if you also account for gravity when calculating the desired torque (e.g., tau_d), as seen in the cartesian_impedance_example_controller code snippet here:

https://github.com/frankaemika/franka_ros/blob/553e18217ef3c7b702872c7f67450f832a3d7952/franka_example_controllers/src/cartesian_impedance_example_controller.cpp#L181

You would essentially be adding the gravity component twice. From what I recall in my conversation with @gollth, he explained that gravity compensation is handled within the franka control unit for the real robot, leading to the same conclusion.

An important point to note is that, for the simulation, when tau_external is calculated, you do need to include the gravity component:

https://github.com/frankaemika/franka_ros/blob/553e18217ef3c7b702872c7f67450f832a3d7952/franka_gazebo/src/franka_hw_sim.cpp#L493

This is because the code snippet mentioned above applies the gravity component just before the control is applied to the simulation. Consequently, the value returned by the self->effort member doesn't include the gravity.

If there are any inaccuracies in my response, @gollth, @marcbone, or @Maverobot, please correct me 👍🏻.

gollth commented 1 year ago

Thanks @rickstaa, you nailed it perfectly =)