Home Questions Moving targets

Moving targets

Michael Huang asked 7 years ago
Hi, I am trying to make the target moving straight. I noticed that in the moving target sample. The way to make it moving is to change VCODE(3) and VCCODE(4). In my case it will be VCODE(4)=VCODE(4)-speed*counter. The problem is the counter cannot reset when it turns to second target. I have tried to use mod, but this will not solve the problem eventually Thanks, Michael
2 Answers
Duncan McLean Staff answered 7 years ago

Hi Michael,

The moving target sample was really just intended as an example - the use of the counter in this case was a convenience.

You could make your own counter with a bit of embedded MATLAB. Something like this should work:

function counter=Counter(reset)
persistent value

if isempty(value) || reset == 1
value = -1;

value = value + 1;
counter = value;

In your Stateflow you would need to send the "reset" input on this code to 1 briefly at the start of each trial.

This counter would run at the default speed of the model. i.e. 2 or 4 kHz. If you want the counter to run at 1 kHz then you would need to right click on the MATLAB block, get properties, and explicitly set the update rate to 0.001 (i.e. 1 ms).

There are many other ways to solve this problem, it just depends on the specifics of what you want to do.


Michael Huang replied 7 years ago

Hi Duncan,
When I right click the MATLAB function block, properties, there are general, block annotation and callbacks. There is no option to set the update rate

Duncan McLean Staff answered 7 years ago
Hi Michael, Sorry, rather than "properties" you should open "block parameters".