Want to change PI control to PD control

Hi, I am new to this area, so if someone can help me, it will be much helpful.

I have to use PD control instead of PI control, so I guess I have to change controller.cpp file. And it is exactly Stanford Doggo did. They already changed this file. But I am not sure how to use it or how to upgrade it. Do I need to flash the firmware?

You don’t need to change the firmware to do PD control. PD control is equivalent to having no integrator gain in our cascaded controller. Our position gain is similar to the P gain, and our velocity gain is similar to the D gain. More info here: https://docs.odriverobotics.com/control

1 Like

Hi @madcowswe, thank you very much for your reply. Actually, I am working on Minitaur Leg by using ODrive. Its leg just like a spring which is exactly like Doggo guys’ work. I need to use PD control because I want to mimic a spring. I want a single PD controller, so that I can exert forces that follow a single function like this:

Motor force = - kp * (position - desired position) - kd * velocity

So may I know how Doggo guys flash the firmware? Can I just follow the Firmware Developer Guide ?

Here is how to transform your gains to use the cascaded controller, assuming you don’t have any feed-forward velocity (if you do you can do the same thing but include that).

We currently have:
current = vel_gain * (desired_vel - actual_vel) and
desired_vel = pos_gain * (desired_pos - actual_pos).

Substitute in desired_vel into the 1st formula, and you get:
current = vel_gain * (pos_gain * (desired_pos - actual_pos) - actual_vel)

Multiply in vel_gain:
current = vel_gain * pos_gain * (desired_pos - actual_pos) - vel_gain * actual_vel

And now you can see this is the exactly the same control law that you wanted, if you set:
vel_gain * pos_gain = kp
vel_gain = kd

Hence you can use the existing cascaded controller just set the appropriate gains.

1 Like

Hi @madcowswe, thank you very much ! Now I am trying to find the largest gain I can set. In other words, how large the current can be ? Is there any document I can refer ?