control of an inverted pendulum on a cart -凯发k8网页登录
this example uses systune
to control an inverted pendulum on a cart.
pendulum/cart assembly
the cart/pendulum assembly is depicted in figure 1 and modeled in simulink® using simscape™ multibody™.
figure 1: inverted pendulum on a cart
figure 2: simscape multibody model
this system is controlled by exerting a variable force on the cart. the controller needs to keep the pendulum upright while moving the cart to a new position or when the pendulum is nudged forward (impulse disturbance ).
control structure
the upright position is an unstable equilibrium for the inverted pendulum. the unstable nature of the plant makes the control task more challenging. for this example, you use the following two-loop control structure:
open_system('rct_pendulum.slx') set_param('rct_pendulum','simmechanicsopeneditoronupdate','off');
the inner loop uses a second-order state-space controller to stabilize the pendulum in its upright position ( control), while the outer loop uses a proportional-derivative (pd) controller to control the cart position. you use a pd rather than pid controller because the plant already provides some integral action.
design requirements
use tuninggoal
requirements to specify the desired closed-loop behavior. specify a response time of 3 seconds for tracking a setpoint change in cart position .
% tracking of x command req1 = tuninggoal.tracking('xref','x',3);
to adequately reject impulse disturbances on the tip of the pendulum, use an lqr penalty of the form
that emphasizes a small angular deviation and limits the control effort .
% rejection of impulse disturbance df qxu = diag([16 1 0.01]); req2 = tuninggoal.lqg('df',{'theta','x','f'},1,qxu);
for robustness, require at least 6 db of gain margin and 40 degrees of phase margin at the plant input.
% stability margins req3 = tuninggoal.margins('f',6,40);
finally, constrain the damping and natural frequency of the closed-loop poles to prevent jerky or underdamped transients.
% pole locations
mindamping = 0.5;
maxfrequency = 45;
req4 = tuninggoal.poles(0,mindamping,maxfrequency);
control system tuning
the closed-loop system is unstable for the initial values of the pd and state-space controllers (1 and , respectively). you can use systune
to jointly tune these two controllers. use the sltuner
interface to specify the tunable blocks and register the plant input f
as an analysis point for measuring stability margins.
st0 = sltuner('rct_pendulum',{'position controller','angle controller'}); addpoint(st0,'f');
next, use systune
to tune the pd and state-space controllers subject to the performance requirements specified above. optimize the tracking and disturbance rejection performance (soft requirements) subject to the stability margins and pole location constraints (hard requirements).
rng(0)
options = systuneoptions('randomstart',5);
[st, fsoft] = systune(st0,[req1,req2],[req3,req4],options);
final: soft = 1.36, hard = 0.99841, iterations = 242 final: soft = 1.44, hard = 0.99966, iterations = 250 final: soft = 1.26, hard = 0.99933, iterations = 316 final: soft = 1.37, hard = 0.99975, iterations = 316 final: soft = 1.26, hard = 0.9993, iterations = 300 final: soft = 1.36, hard = 0.99956, iterations = 318
the best design achieves a value close to 1 for the soft requirements while satisfying the hard requirements (hard
<1). this means that the tuned control system nearly achieves the target performance for tracking and disturbance rejection while satisfying the stability margins and pole location constraints.
validation
use viewgoal
to further analyze how the best design fares against each requirement.
figure('position',[100 100 575 660])
viewgoal([req1,req3,req4],st)
these plots confirm that the first two requirements are nearly satisfied while the last two are strictly enforced. next, plot the responses to a step change in position and to a force impulse on the cart.
t = getiotransfer(st,{'xref','df'},{'x','theta'}); figure('position',[100 100 650 420]); subplot(121), step(t(:,1),10) title('tracking of set point change in position') subplot(122), impulse(t(:,2),10) title('rejection of impulse disturbance')
the responses are smooth with the desired settling times. inspect the tuned values of the controllers.
c1 = getblockvalue(st,'position controller')
c1 = s kp kd * -------- tf*s 1 with kp = 5.88, kd = 1.92, tf = 0.0509 name: position_controller continuous-time pdf controller in parallel form.
c2 = zpk(getblockvalue(st,'angle controller'))
c2 = -1610.7 (s 12.91) (s 4.294) --------------------------- (s 135.1) (s-14.24) name: angle_controller continuous-time zero/pole/gain model.
note that the angle controller has an unstable pole that pairs up with the plant unstable pole to stabilize the inverted pendulum. to see this, get the open-loop transfer at the plant input and plot the root locus.
l = getlooptransfer(st,'f',-1); figure rlocus(l) set(gca,'xlim',[-25 20],'ylim',[-20 20])
to complete the validation, upload the tuned values to simulink and simulate the nonlinear response of the cart/pendulum assembly. a video of the resulting simulation appears below.
writeblockvalue(st)
figure 3: cart/pendulum simulation with tuned controllers.
close the model after simulation.
set_param('rct_pendulum','simmechanicsopeneditoronupdate','on'); close_system('rct_pendulum',0);
see also
(simulink control design) | (simulink control design)
related topics
- (simulink control design)
- (simulink control design)