How do I run parallel dependent loops?

I have a simulation that has two parts. A control loop and an identification loop. The control loop runs at a high sampling rate. The identification loop is computationally intensive. The information generated by the identification loop is helpful but not necessary for the control loop to run.
Ideally, I would like to have a simulation where the identification loop sends information to the control loop whenever its done computing. The control loop uses whichever latest identification information it has.
Is there a way I can do this?

댓글 수: 2

José-Luis
José-Luis 2013년 5월 20일
What does your code look like? Could you give an example? How do you intend to perform parallelization of the tasks?
Here is a small example
First task (control loop)
[x_dot, theta_dot] = function1(x,theta,c)
% code to compute the derivatives x_dot and theta_dot
Second task
c=function2(x,theta)
%computationally intensive function to compute c
Now, the first function is implemented in a simulink block. The outputs x_dot, theta_dot pass through integration blocks and back to the inputs x and theta. This block runs every 1/1000th second.
The second function is also a simulink block that accepts x and theta as inputs and computes 'c'.
What I want is for function1 to use the currently available value of 'c' till function2 is executed, and then switch over to the new value when available.
I have made function2 into a subsystem and am running it at a lower rate but that is not the ideal solution.

댓글을 달려면 로그인하십시오.

답변 (1개)

Walter Roberson
Walter Roberson 2013년 5월 20일

1 개 추천

If you were to use smpd then you could use labsend() to send values from the identification worker to the control worker.
The traditional structure would be to construct the control loop as a BytesAvailableFcn callback or timer callback (as appropriate) that would interrupt the main computation as necessary, and would draw upon the current values of variables stored by the identification loop. You would, I figure, need at least two buffers of the variables, one being read from and one being written to.

댓글 수: 1

I do not know many of the programs you mentioned. I will do my research and report back in a few days. Thank you for your answer.

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Linear Model Identification에 대해 자세히 알아보기

질문:

2013년 5월 20일

Community Treasure Hunt

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

Start Hunting!

Translated by