State space feedback

Hello everyone!

I am new to julia and trying to model with 1 input and 2 output.
my problem is that i am unable to create a feedback with a pid controller in the forward path, even if i create the feedback the (first output to the first input) the 2nd output got lost.

A =
-0.06617428571428571 19.852285714285713 4.2 0.0 -0.0033551169590643275 -0.033551169590643276 0.0
0.0 0.0 0.0 0.0 0.0 0.0 0.0
0.0 0.0 0.0 0.0 0.0 0.0 0.0
0.05413766434648106 0.0 0.0 -0.05413766434648106 0.0 0.0 0.0
0.0 0.0 0.0 0.0 0.0 1.0 0.0
0.0 0.0 0.0 0.0 0.0 0.0 1.0
0.0 0.0 0.0 0.0 0.0 -22.22222222222222 -6.666666666666667
B =
C =
1.0 0.0 0.0 0.0 0.0 0.0 0.0
0.0 0.0 0.0 1.0 0.0 0.0 0.0
D =

this is system and the pid together.

C=pid(Kp, Ki, Kd; form=:parallel, Tf=0.3, state_space=true)

back=series(C, Model)


could anybody help me out, thanks in advance!

A couple of proposals:

  1. It is customary (and much better) to give (Julia) code within a block of three starting back-ticks β€œ`” followed by keywoard β€œjulia”, i.e., β€œ````julia”, and then close the code block by three backticks β€œ```”. That would make part of your code look as follows:
C=pid(Kp, Ki, Kd; form=:parallel, Tf=0.3, state_space=true)
back=series(C, Model)
  1. I’m not an expert on the control package (Fredrik is answering right now, I think). But what is your chosen values for Kp, Ki, and Kd?
  2. Remember: with two outputs and one input, you have to choose which output you want integral action for.
  3. A pid controller is normally not considered β€œstate space feedback”. Still, β€œpd” control with filtered output is somewhat similar to state space feedback with a state estimator – for the very specific case when the system is a double integrator.
  4. Along this line (#4), one could in principle consider LQG control as a particularly tuned PD controller in the multivariable case. If one one augments the system with states being the integral of output deviation and put weight on these in the cost function of LQG control, then this would be some sort of generalized multivariable PID controller.
  5. In any way, it is not possible to have more integral actions than inputs.

Hello and welcome to the forum!

Please read Please read: make it easier to help you to learn how to quote your code, and try to include code for an example that runs :slight_smile:

When you index back[1,1] you get a SISO system, you must somehow account for the second output of Model before you call feedback, i.e., by making C a 1x2 system?

Alternatively, if you want C to operate on one of the outputs only, but keep the second output when you form the closed-loop system, you need to use the advanced interface to feedback where you specify which inputs and outputs are involved in the feedback, and which are considered external.

  feedback(sys1::AbstractStateSpace, sys2::AbstractStateSpace;
           U1=:, Y1=:, U2=:, Y2=:, W1=:, Z1=:, W2=Int[], Z2=Int[],
           Wperm=:, Zperm=:, pos_feedback::Bool=false)

  Basic use feedback(sys1, sys2) forms the feedback

  ◄───────────     sys1     │◄──── Ξ£ ◄──────
      β”‚      β”‚              β”‚      β”‚
      β”‚      β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜      -1
      β”‚                            |
      β”‚      β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”      β”‚
      └─────►│     sys2     β”œβ”€β”€β”€β”€β”€β”€β”˜
             β”‚              β”‚

  Advanced use feedback also supports more flexible use according
  to the figure below

        z1◄──────     sys1     │◄──────w1
   β”Œβ”€β”€β”€ y1◄──────              │◄──────u1 ◄─┐
   β”‚            β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜            β”‚
   β”‚                                        Ξ±
   β”‚            β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”            β”‚
   └──► u2─────►│     sys2     β”œβ”€β”€β”€β”€β”€β”€β”€β–Ίy2β”€β”€β”˜
        w2─────►│              β”œβ”€β”€β”€β”€β”€β”€β”€β–Ίz2

in your case, you would have to provide Z1 = : and Y1=[1] or Y1=[2] depending on which output is fed back to the controller, e.g.,

feedback(Model, C, Y1=[1])


Thanks for the quick reply!
I am trying to control the temperature inside a relatively small space (approximately 1m3) with a perltier modul.

My proposed control setup would be the following.

I think that your suggestion place the controller in the feedback path instead of the forward path.

Thanks in advance!

You’re right, to place it in the forward path you’d have to use P*C as sys1 (like you correctly did) and ss(1) as sys2

feedback(P*C, ss(1), Y1=[1])


i have checked, the site, but i could not fully understand all the feedback function’s arguments. if you are planning to make a new video of this tool, i would definitely watch it, if it contains a more specific usage of this function (E.g. a mimo plant with a mimo feedback).

tbh, the tool all in all is awesome, great job!

Thanks for the feedback :slight_smile:
I do in fact have a number of videos in the pipeline, I hope they’ll be out within a month or so. In the meantime, there is a possibility to make use of named signals and call the function connect to form more complicated feedback interconnections. The docs for connect are here{Any}
there’s also an example making use of this functionality here

1 Like