Problem with SimEvents regarding the simulation of a inverted Pendulum with round robin network

1 次查看(过去 30 天)
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,
  1. Cart position is send
  2. Controller computes control effort based on the new cart position and a previous pendulum angle
  3. Pendulum angle is send
  4. Controller computes control effort based on the new pendulum angle and a previous cart position
  5. Etc.
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)
%#codegen
persistent mem;
if isempty(mem)
mem = [0; 0];
end
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.

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Discrete-Event Simulation 的更多信息

产品

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by