unitreerobotics / unitree_legged_sdk

SDK tools for control robots.
BSD 3-Clause "New" or "Revised" License
283 stars 156 forks source link

Feed-forward torque control mode? #41

Closed egordv closed 2 years ago

egordv commented 2 years ago

Hello! I want to use the feed-forward torque control method on Go1 robot with unitree_legged_sdk v3.4.1 The control law that I need is: tau = tau_des + P * (q_des - q) + D * (v_des - v)

As far as I understood from the examples, I can do the classic torque control (tau = tau_des) with:

cmd.motorCmd[k].q = PosStopF;
cmd.motorCmd[k].dq = VelStopF;  
cmd.motorCmd[k].Kp = 0;  
cmd.motorCmd[k].Kd = 0;  
cmd.motorCmd[k].tau = tau_des;  

Also I can do the classic position control (tau = P * (q_des - q) + D * (v_des - v)) with:

cmd.motorCmd[k].q = q_des;
cmd.motorCmd[k].dq = v_des;
cmd.motorCmd[k].Kp = Kp;
cmd.motorCmd[k].Kd = Kd;
cmd.motorCmd[k].tau = 0;

But is there any specific structure of motorCmd designed to perform a feed-forward torque control mode with the control law tau = tau_des + P * (q_des - q) + D * (v_des - v)?

TrivasZhang commented 2 years ago

Yes, you are right. A notable point is, the control bandwidth is different. The motor driver runs on MCU and has high control bandwidth, about 10~20kHz, so when [q dq Kp Kd tau] is set to motor, then the final torque responds rapidly. But when you use a feedback value to generate torque, as you said 'classic position control'

cmd.motorCmd[k].q = 0;
cmd.motorCmd[k].dq = 0;
cmd.motorCmd[k].Kp = 0;
cmd.motorCmd[k].Kd = 0;
cmd.motorCmd[k].tau = P * (q_des - q) + D * (v_des - v);

The control bandwidth will down to about 1khz cause of communication speed.

egordv commented 2 years ago

Thank you for your quick reply!

But it's not clear for me - can I achieve the control law that I need (tau = tau_des + P * (q_des - q) + D * (v_des - v)) with the following structure of motorCmd:

cmd.motorCmd[k].q = q_des;
cmd.motorCmd[k].dq = v_des;
cmd.motorCmd[k].Kp = Kp;
cmd.motorCmd[k].Kd = Kd;
cmd.motorCmd[k].tau = tau_des;

And what will be the control bandwidth in that case? 1kHz or 10kHz?

TrivasZhang commented 2 years ago

Sure you can. It will be 10kHz.

pab47 commented 2 years ago

I think it would be a mix of the two: the PD control will be at 10 KHz assuming (Kp, Kd, q, dq are not being updated) but the tau_des will be at 1 Khz (assuming that is is updated in the main loop).

TrivasZhang commented 2 years ago

I think it would be a mix of the two: the PD control will be at 10 KHz assuming (Kp, Kd, q, dq are not being updated) but the tau_des will be at 1 Khz (assuming that is is updated in the main loop).

Yes, if tau is a variety then tau is 1khz, if tau is constant then is 10khz.

TrivasZhang commented 2 years ago

Feel free to reopen it.

egordv commented 2 years ago

Hello! I've checked this approach on real Go1 and everything works as expected. Control bandwidth for q/dq commands is 10kHz, and for tau is 1kHz, which really helps to solve stability issues when working with high control gains. Thank @TrivasZhang @pab47 for your support!