# Using lag-compensator to get good system response - RHP zero

I am designing a velocity controller for a balancing robot. The most important thing for the robot is to maintain balance, so I would prefer a slower response velocity response in turn for a steady system. I have the transfer function between tilt angle and velocity:

s = tf('s');
G =(-5.042e07*s^7 -7.152e10*s^6 -2.179e13*s^5 -7.015e14*s^4 -5.508e15*s^3 +2.899e16*s^2+5.128e17*s+1.603e18)/(s^10 +2801*s^9 +2.243e06*s^8 +7.199e08*s^7 +1.125e11*s^6 +9.739e12*s^5 +5.027e14*s^4 +1.1e16*s^3 +9.397e16*s^2 +2.7e17*s +8.076e14)


It has no poles in the RHP (which is good), although it has one zero in the RHP. It has the bode plot:-

I want to place the crossover frequency at 5 rad/s, $$\\omega_c=5\$$. However, if I just do this with a P-controller, I end up with two crossover frequencies due to the peak at 100 rad/s. I tried to remove that peak with a lag-compensator $$\C_l = \frac{0.01s+1}{0.1s+1} \$$ and then adding a gain of $$\K_p = 0.7 \$$ to get the desired crossover frequency. I end up with this bode plot:-

However, when I apply a step input, I get this step response with a nasty undershoot (which I believe is due to the RHP zero):-

Is there any way I can fix this? And is my design approach okay, with the lag-compensator and all?

Edit

As requsted by VoltageSpike, here are the step responses for the plant alone, and the controller alone (without any feedback loops). The blue is the plant, the orange is the controller.

• Try squaring the denominator (and possibly adding another low zero) to make the flat region fall off in a ramp below zero. Though it looks like the RHP zero will bite you no matter what. – a concerned citizen Jun 1 at 14:58
• @aconcernedcitizen Damn, that is too bad. Would you recommend that I redesign the balance controller, such that I get no RHP zeroes or poles in the transfer function for the velocity controller? Or is there a way I can attenuate the effect of the RHP zero? – Carl Jun 1 at 15:02
• It might be better, RHPs are always a bad omen. To compensate you'll need a lead-lag which, due to the lead, will apply a derivative to your response. But better wait for an answer (these are just comments). – a concerned citizen Jun 1 at 15:14
• I know of some students that built a robot like this and the controller didn't work until they put it into positive feedback. – Voltage Spike Jun 1 at 18:39
• @VoltageSpike Huh? Positive feedback? I don't understand how that is ever going to work for a controller. Because if there is an error in the output from the reference, then that error is sent back and with positive feedback it will be added to the reference, causing an even bigger error in the output to be send back, and so forth eventually exploding the output and destroying your system. Are you sure about that? – Carl Jun 1 at 19:18