Problem with SimEvents regarding the simulation of a inverted Pendulum with round robin network
1 view (last 30 days)
I have a simulink model of a inverted pendulum. Now I want to simulate this with a wireless network with a round-robin network. The inverted pendulum has two sensors, for the cart position and angle of the pendulum. Now in practice this means that at a certain time t,
- Cart position is send
- Controller computes control effort based on the new cart position and a previous pendulum angle
- Pendulum angle is send
- Controller computes control effort based on the new pendulum angle and a previous cart position
Now I use the SimEvents toolbox to Simulate the network. The problem I am facing is in a Matlab function I created which is a internal memory so to speak for the previous pendulum angle/cart position. This code is placed at the end of the network, see image, and its output is directed to the controller.
The function looks like as follows:
function y = fcn(message,type)
mem = [0; 0];
mem(type) = message;
y = mem;
The problem is in the fact that it appears to be that the getAttribute Simulink block does not return a type of the message (type = 1 for cart position, type = 2 for pendulum angle), which I initialize when I create the corresponding entity. The Matlab function does then generate a error since of course it cannot set a index 0.
I hope somebody can help me with this problem.
The files: Initialization file: https://dl.dropboxusercontent.com/u/20782274/init.m Main file: https://dl.dropboxusercontent.com/u/20782274/main.m Control design: https://dl.dropboxusercontent.com/u/20782274/controlDesign.m Simulink file: https://dl.dropboxusercontent.com/u/20782274/invertedPendulum.slx
Download the 4, then run the main file and afterwards the Simulink file.