Thread Subject: Finding dt in a S-block

Subject: Finding dt in a S-block

From: Steven Evans

Date: 7 Jul, 2007 21:26:17

Message: 1 of 7

Hi,
  Can some one help I need to find t, dt in the mdlOutputs function
of an s-block. I have got t using ssGetT(S). Now I need to find dt
(the differance between the current time as the time last use).

The S-block is set to use [INHERITED_SAMPLE_TIME, 0.0].

Subject: Finding dt in a S-block

From: riccardo

Date: 9 Jul, 2007 04:09:48

Message: 2 of 7

Steven Evans wrote:
>
>
> Hi,
> Can some one help I need to find t, dt in the mdlOutputs function
> of an s-block. I have got t using ssGetT(S). Now I need to find dt
> (the differance between the current time as the time last use).
>
> The S-block is set to use [INHERITED_SAMPLE_TIME, 0.0].
  
Steve,
if you have a look in Simstruct.h there should be an entry for the
current integration time step.
Another way to get almost the same result is to define a state
variable to store the time the Output function has been last called
and take the difference to the current one before updating it.
HTH
riccardo

Subject: Finding dt in a S-block

From: riccardo

Date: 9 Jul, 2007 04:10:07

Message: 3 of 7

Steven Evans wrote:
>
>
> Hi,
> Can some one help I need to find t, dt in the mdlOutputs function
> of an s-block. I have got t using ssGetT(S). Now I need to find dt
> (the differance between the current time as the time last use).
>
> The S-block is set to use [INHERITED_SAMPLE_TIME, 0.0].
  
Steve,
if you have a look in Simstruct.h there should be an entry for the
current integration time step.
Another way to get almost the same result is to define a state
variable to store the time the Output function has been last called
and take the difference to the current one before updating it.
HTH
riccardo

Subject: Finding dt in a S-block

From: Steven Evans

Date: 9 Jul, 2007 06:17:10

Message: 4 of 7

I tried both you ideas by putting the following in the mdlOutputs
function.

 time_T time = ssGetT(S);
 time_T dt = time - m_lastTimeStep;

 m_lastTimeStep = time;
 ssPrintf("Task 0 sample hit in %s time = %g dt=%g
stepSize=%g\n", ssGetPath(S),time, dt, S->mdlInfo->stepSize);

this gave the following result.
 
Task 0 sample hit in A320model/J2 Active time = 0.1 dt=0.00453889
stepSize=0
Task 0 sample hit in A320model/J2 Active time = 0.1 dt=0 stepSize=0
Task 0 sample hit in A320model/J2 Active time = 0.1 dt=0 stepSize=0
Task 0 sample hit in A320model/J2 Active time = 0.113274 dt=0.0132738
stepSize=0
Task 0 sample hit in A320model/J2 Active time = 0.119911
dt=0.00663691 stepSize=0
Task 0 sample hit in A320model/J2 Active time = 0.153095 dt=0.0331845
stepSize=0
Task 0 sample hit in A320model/J2 Active time = 0.158995
dt=0.00589947 stepSize=0
Task 0 sample hit in A320model/J2 Active time = 0.166369
dt=0.00737434 stepSize=0
Task 0 sample hit in A320model/J2 Active time = 0.166369 dt=0
stepSize=0
Task 0 sample hit in A320model/J2 Active time = 0.166369 dt=0
stepSize=0

As you will see the step size was always 0 and the output was called
upto 3 times with the same time giving a dt of zero.

What have I missed?

 riccardo wrote:
>
>
> Steven Evans wrote:
>>
>>
>> Hi,
>> Can some one help I need to find t, dt in the mdlOutputs
function
>> of an s-block. I have got t using ssGetT(S). Now I need to
find
> dt
>> (the differance between the current time as the time last use).
>>
>> The S-block is set to use [INHERITED_SAMPLE_TIME, 0.0].
>
> Steve,
> if you have a look in Simstruct.h there should be an entry for the
> current integration time step.
> Another way to get almost the same result is to define a state
> variable to store the time the Output function has been last called
> and take the difference to the current one before updating it.
> HTH
> riccardo

Subject: Finding dt in a S-block

From: riccardo

Date: 9 Jul, 2007 07:22:23

Message: 5 of 7

Steven Evans wrote:
>
>
> I tried both you ideas by putting the following in the mdlOutputs
> function.
>
> time_T time = ssGetT(S);
> time_T dt = time - m_lastTimeStep;
>
> m_lastTimeStep = time;
> ssPrintf("Task 0 sample hit in %s time = %g dt=%g
> stepSize=%g\n", ssGetPath(S),time, dt, S->mdlInfo->stepSize);
>
>
> this gave the following result.
>
> Task 0 sample hit in A320model/J2 Active time = 0.1 dt=0.00453889
> stepSize=0
> Task 0 sample hit in A320model/J2 Active time = 0.1 dt=0 stepSize=0
> Task 0 sample hit in A320model/J2 Active time = 0.1 dt=0 stepSize=0
> Task 0 sample hit in A320model/J2 Active time = 0.113274
> dt=0.0132738
> stepSize=0
> Task 0 sample hit in A320model/J2 Active time = 0.119911
> dt=0.00663691 stepSize=0
> Task 0 sample hit in A320model/J2 Active time = 0.153095
> dt=0.0331845
> stepSize=0
> Task 0 sample hit in A320model/J2 Active time = 0.158995
> dt=0.00589947 stepSize=0
> Task 0 sample hit in A320model/J2 Active time = 0.166369
> dt=0.00737434 stepSize=0
> Task 0 sample hit in A320model/J2 Active time = 0.166369 dt=0
> stepSize=0
> Task 0 sample hit in A320model/J2 Active time = 0.166369 dt=0
> stepSize=0
>
> As you will see the step size was always 0 and the output was
> called
> upto 3 times with the same time giving a dt of zero.
>
> What have I missed?
>
> riccardo wrote:
>>
>>
>> Steven Evans wrote:
>>>
>>>
>>> Hi,
>>> Can some one help I need to find t, dt in the mdlOutputs
> function
>>> of an s-block. I have got t using ssGetT(S). Now I need to
> find
>> dt
>>> (the differance between the current time as the time last
> use).
>>>
>>> The S-block is set to use [INHERITED_SAMPLE_TIME, 0.0].
>>
>> Steve,
>> if you have a look in Simstruct.h there should be an entry for
> the
>> current integration time step.
>> Another way to get almost the same result is to define a state
>> variable to store the time the Output function has been last
> called
>> and take the difference to the current one before updating it.
>> HTH
>> riccardo
  

Steve,
you're running a continuous-time simulation and your print outs will
depend on the integrator used: if I remember correctly mdlOutputs is
called both at minor and major time steps, and you probably want
major steps only.
I believe - again if I remember correctly - that you should get hold
of the Simulink model's S structure if you want to print out the
stepSize, as your s-function doesn't define one.
HTH
Riccardo

Subject: Finding dt in a S-block

From: Steven Evans

Date: 9 Jul, 2007 10:52:54

Message: 6 of 7

I could not find a StepSize that was no zero so have resorted to
using the following:

time_T time = ssGetT(S);
time_T dt = time - ssGetTimeOfLastOutput(S);

I am assuimg that the intergration step used will be relative to the
time a result was output.

Can you cofirm this assumption for me thanks.

Subject: Finding dt in a S-block

From: riccardo

Date: 10 Jul, 2007 04:24:32

Message: 7 of 7

Steven Evans wrote:
>
>
> I could not find a StepSize that was no zero so have resorted to
> using the following:
>
> time_T time = ssGetT(S);
> time_T dt = time - ssGetTimeOfLastOutput(S);
>
> I am assuimg that the intergration step used will be relative to
> the
> time a result was output.
>
> Can you cofirm this assumption for me thanks.
  
You could use directly

time_T dt = ssGetT(S) - ssGetTimeOfLastOutput(S);

but you still have to make sure that you're doing that on a major
time step.

Tags for this Thread

Everyone's Tags:

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Tag Activity for This Thread
Tag Applied By Date/Time
sfunction build... Sab Bianchi 6 Dec, 2007 05:10:44
rssFeed for this Thread

Contact us at files@mathworks.com