# Remove big valley in phase plot

I am working on a speed controller for a robot and it's for when the robot is balancing on its wheels. I am designing the controller as part of a project in a linear control design course. However, the controller has to be implemented on a robot and in software delivered by my instructor, so I don't have infinite room of freedom. The way I implement my controller can be seen here:-

As you can see, I can add a gain $$\K_p \$$, an integrator and post-integrator, a lead/lag-term in both forward and feedback path, a prefilter and a feed-forward. And that's it. I can't change what feedback I'm receiving, I can only add and adjust terms of the controller.

## Edit - Finding the new transfer function

Doing what AJN suggests gives me a much nicer bode plot:-

The bode plot is much nicer, but I still have some trouble. I want to smooth out the hill in the phase plot, but I am not sure how to do so.

The new transfer function:

num = [0 0 0 -3.5113e+07 -3.7165e+10 -2.0902e+12 -3.8701e+13 -1.5402e+14 2.5341e+15 2.2109e+16 3.3405e+16];
den = [1 2.4731e+03 1.4491e+06 2.5930e+08 1.2622e+10 9.9503e+10 -1.8488e+12 -1.0302e+13 0 0 0];
G2 = tf(num,den);


## Earlier form of the question containing some outdated info

num = [0 0 0 0 -2.3409e+07 -2.4777e+10 -1.3935e+12 -2.5801e+13 -1.0268e+14 1.6894e+15 1.4740e+16 2.2270e+16];
den = [1 2.4738e+03 1.4508e+06 2.6223e+08 1.5442e+10 6.8736e+11 2.6563e+13 5.2944e+14 4.0900e+15 8.1300e+15 3.7708e+15 1.1220e+13];
G2 = tf(num,den);


The open and closed loop bode plot for the transfer function is here:-

As you can see in the closed loop bode plot, there is a big valley in the phase, and this causes the system to be unstable (I think), and I don't want that.

My inital idea was to add a lag-term to the forward path. A lag-term removes phase, so if I place it right where the valley is the peak should get smaller. My lag-term looks like this:-

But even after adding the lag-term the phase still looks very weird. Here is the new closed loop bode plot:-

Is there a way to remove this phase valley and get a proper stable system?

• This looks like hysteresis induced resonances that cause the phase reversal. And reminds me of graduate inverted broom servo train thesis. This has been done many times. Eliminating the slack (hysteresis) with push or pull tension and a velocity and position feedback loop will give better results. Commented Apr 19, 2021 at 13:53
• Using position control with the 2nd integral of current makes for poor phase margin. Try to use 1st order feedback, velocity arm angle then Position of angle and vehicle. I.e. multiple loops as the load changes with angle is nonlinear Commented Apr 19, 2021 at 13:56
• I plotted the poles and zeros of the plant and noticed; a zero on the RHP and two complex conjugate poles on the RHP. The system will be quite difficult to stabilize as you need to bring the poles to the RHP while keeping the open loop poles from migrating towards the RHP zero in the loop closing process.
– AJN
Commented Apr 19, 2021 at 14:38
• "As you can see in the closed loop bode plot, there is a big valley in the phase, and this causes the system to be unstable (I think), and I don't want that." The phase plot of the closed loop plot may not be the way to think about this problem.
– AJN
Commented Apr 19, 2021 at 14:39
• this looks more reasonable. however, be careful! I dont know how simulink works, but you may be plotting -G(s)H(s) now. Simulink doesn't know that it has to ignore the -ve sign in the summing junction when opening a loop (At least older simulink version didn't; I think). The positive shape of the phase plot makes me believe that to be the case. Be cautious.
– AJN
Commented Apr 19, 2021 at 15:29