timeevent with iterative process

Moderators: Frank, paul, Hiwot, Chris, peter

bendesarts
Posts: 49
Joined: Thu Mar 07, 2013 10:10 am

timeevent with iterative process

Postby bendesarts » Tue Oct 07, 2014 11:19 pm

Hello,

In a model, I programmed a little algorithm (gradient algorithm). This algorithm is not complex but it works with discrete time in a continuous simulation. So, I would like to use the timeevent function each 2s (for example) in my model and for this time, I would like to calculte my algorithm.
For the moment, as i didn't manage to do this, I repeat several times the timeevent function but I can not do it 30 times... :?
Consequently, I try to use the frequencyevent function (like explained in the discretevent model). I have used this code :

Code: Select all

output = frequencyevent (periodTime, offsetTime);
   i=0;
   if output==1 then
       i=i+1;
   end;
   next (total) = total + output*sampletime;
   sortie = total + initial;     


The problem of this code is that the sampling leads the program an error in my simulation. The error underlines me that the issue is linked to derivative functions associated to discrete time.

Consequently, I would like to use only the fonction timeevent but without having a sampling (visible with the discrete tab).

Question:

Do you have some ideas to use the timeevent function each T second but without having sampling ?

Thanks a lot for your help.

I hope my post will be clear enough.

paul
Posts: 152
Joined: Mon Sep 19, 2005 2:00 pm
Location: Controllab Products B.V.

Re: timeevent with iterative process

Postby paul » Wed Oct 08, 2014 11:01 am

Thanks for your question.

First of all: 20-sim does not crash! In fact it gives you a nice error message that tells you that your model is wrong, and why it is wrong.

Now if you really would like to emulate a discrete time part in a continuous time model, you can make this yourself with frequencyevent or timeevent functions, together with the code and the major keywords.

This is however not needed at all, since 20-sim also supports discrete time parts directly!
Please use the sample and hold functions for this, like:

Code: Select all

variables
    real a, v, x;
    real vk, xk;
equations
    // continuous time part
    a = time;
    v = int (a);

    // going to discrete time
    vk = sample (v);
    next (xk) = xk + vk * sampletime;

    // and going back to continuous time
    x = hold (xk);

Now you have in the Run settings of the Simulator a discrete system tab, where you can specify the sample rate of your discrete time part (that calculates vk and xk). Do plot v, x, vk and xk to get the idea.

Please have a look in the 20-sim help, this might save you a lot of time!
Here is a link to the topic on this: http://www.20sim.com/webhelp/editor_using_models_continuous-time_and_discrete-time_models.php

Paul
member 20-sim development team


Return to “Languages”

Who is online

Users browsing this forum: No registered users and 1 guest