# Simulink vector and closed-loop control

Discussion in 'Programmer's Corner' started by Xen956, Jul 8, 2012.

1. ### Xen956 Thread Starter New Member

Jul 8, 2012
3
0
Hello everybody,

Sorry to come here with a problem to solve, but I hope you can help me with it ü

Basically I have in Simulink a loop consisting of an input that I get through blocks that I've built. This input, let's call it INPUT1 must come in a section of the model where I have to call a variable which is in fact a vector (1 column, 800 rows), use the 1st row of that vector to make calculation, so I can get a new value of INPUT1, which becomes now INPUT2.

After this I am using that INPUT2 to make other calculations, and then I have to use that INPUT2 value with the 2nd row of the famous vector I talked about before so I get an INPUT3, and so on. This is my control loop.

How can I automatically make Simulink to take one row after another in the vector ? I mean the input value changes everytime the loop is completed, so I cannot make all calculations at once with all rows of the vector.

Thanks a lot in advance !

2. ### steveb Senior Member

Jul 3, 2008
2,433
469
I think you need to specify what you are trying to do in more detail.

Simulink is a time based modeling tool, so the idea of going through the loop may be described by dynamic equations, not iterations. However, it is possible to run the system as a discrete system, which is basically like an iterative loop. So, are you doing continuous time dynamic modeling, or just an iterative loop, with a fixed value for the number of iterations?

Also, it's not clear what values go into the other 799 vector inputs when each row is being fed to the next row. I can visualize several different structures that might fit your description so far. For example, I can imagine delay blocks being used to link the output vector to the input vector, with output 1 going to 2, and 2 going the 3, etc. But, I have no idea if this is what you are really after.

I think you should try to explain what you are doing in more detail. I'm willing to try to help, but so far, I dont' have a good picture of what you are doing.

Also, consider that code based programming in Matlab is sometimes much easier to implement than Simulink block diagrams for some problems. If coding is easier, but you need to be in the Simulink environment, then you can use a Matlab code block right in Simulink.

3. ### Xen956 Thread Starter New Member

Jul 8, 2012
3
0
Thank you for your interest !

Well, to give you more details, my input is a speed, and according to this speed and to a variable corner radius, I have to apply resistance to this speed.

In fact, the corner radius has been defined in advance, so I have, depending on the distance covered, a table of the radius (800 points, or rows). As time is passing by, I have to calculate the distance covered with my input speed (easy). This covered distance will tell me if I am between the 1st and 2nd point of my simulation, the 2nd and 3rd point, and so on until the 800th point.

And for example, if I am between the 2nd and the 3rd point of my simulation (according to the distance covered), I have to use the 2nd row of my corner radius vector to get the resistance. When I know this resistance, I can correct the speed and see then what new distance I have covered and check if I am still between the 2nd and 3rd point (in this case I will use the same corner radius to calculate the new resistance to apply to that speed), or between the 3rd and 4th point (I will then use the 3rd row of my vector this time).

I am also quite new to Matlab-Simulink so I don't know all functions. However, I won't have time to develop a dynamic model of this, as you wrote, I would prefer to use an iterative model. I have basically a starting point, a finish point and between this 800 different points to which I have to go through in a specified time.

Sorry if it is not clear, I'm trying my best, but English is not my native language

4. ### steveb Senior Member

Jul 3, 2008
2,433
469
Actually, your English comes across as good. It's really the technical details that need to be specified in more detail; that's all.

The new description is making it more clear and seems to indicate that a vector based variable is not what you have at all. You basically are describing a lookup table which is more like a vector parameter in Simulink. Simulink variables are time dependent signals that flow through the blocks. Various parameters are also used in Simulink, and these are what you might consider to be variables in Matlab.

Let me give this more thought and I'll either come back with some questions, or with a recommendation on how to approach this. In the mean time, you may want to look in the Simulink documentation for lookup tables and methods of interpolation.

By the way, you already have one dynamic equation, which is the definition of speed.

dx/dt=v

where x is distance and v is speed. Given an initial position, you can integrate to get the ongoing position
$x(t)=x_0+\int_0^t v(\tau) d\tau$

5. ### steveb Senior Member

Jul 3, 2008
2,433
469
OK, here is my first question about the details.

What do you mean by this statement. How to you apply the resistance to the speed?

My understanding is that you will compute position from the speed profile. Then the resistance can be calculated based on position. So, then the question becomes, how do you use the resistance?

Problems I'm familiar with might try to use the resistance in a force calculation, which then becomes an additional dynamic equation.

My feeling is that you still want to use a lookup table with interpolation to store the data in a vector and then provide a means to calculate resistance from speed.

6. ### Xen956 Thread Starter New Member

Jul 8, 2012
3
0
Thank you again for your interest !

You are seeing things right there, the resistance is going to be converted to a force that I will use to reduce the speed. Therefore a new speed calculation has to happen (which can be done) and of course I will get a new distance covered with that new speed.

So it is then possible to reach a new point where a new corner radius has to be calculated and so a new force. Or, if the speed has not been fast enough (and so the distance not great enough to reach a new corner radius point), use the same radius.

I have tried the lookup table following your advice (and as I have been using this block before, its allright), and I have been able to plot the corner radius depending on the distance covered, and using the speed to calculate the distance covered, I can know the radius ! So it is working fine !

I am going now to build the others parts and see if it all goes well together but its already a very good start !

So I just want to say thank you very much for having spent some of your time on my case, eventho I had never posted anything on this forum before. It is rare those days to have people helping each other without asking for anything back. I will let you know how the things go with this program !

I am not an electrical guy (most a mechanic) but I came across this forum while searching for some kind of Matlab functions and came on a thread here where the guy got great help, so I thought why not ?