Opened 4 years ago

Last modified 3 years ago

#6212 assigned defect

First tick of shiftsample is missing

Reported by: p.van.der.hulst@… Owned by: Andreas Heuermann
Priority: high Milestone:
Component: OMSimulator Version:
Keywords: shiftsample Cc:

Description

Hi,

When shifting a clock with shiftSample (as explained in Fritzson, Principles of object-oriented modeling..... 2nd ed., page 709/710) the first tick of the shifted clock y1 (expected at 0.1sec) is missing.
Below is an example model derived from Fritzson's example. I added 'Count1' and 'Count2' variables to reveal the actual sampling moment, since sampling instances are not clear from the OMedit plots.

model test3

  Clock u1 = Clock(3,10);
  Clock y1=shiftSample(u1,1,3);

  Real Count1(start=2);
  Real Count2(start=2);

initial equation
equation
  Count1 = sample(time,u1);
  Count2 = sample(time,y1);

end test3;

The first update of Count2 is at 0.4 sec instead of at 0.1 sec.
I use OpenModelica 1.16.0 (this does not seem to be an option in the drop-down list below).

Best regards,
Paul van der Hulst

PS. Note that in dymola I do get the first sample at 0.01sec.

Change History (8)

comment:1 by Francesco Casella, 4 years ago

@lochel, do you think you can fix this quickly? Otherwise please reschedule to 1.17.0.

Thanks!

comment:2 by p.van.der.hulst@…, 4 years ago

Hi,
I noticed something strange: when the shift is larger than half the period, the clock behaves ok.
So

Clock y1=shiftSample(u1,3000,6000);

is not ok, whereas

Clock y1=shiftSample(u1,3001,6000);

is fine.
I hope this gives a clue.

Paul

comment:3 by Francesco Casella, 4 years ago

Milestone: 1.16.11.17.0
Owner: changed from Lennart Ochel to Karim Adbdelhak
Status: newassigned

@Karim, would you mind having a look?

comment:4 by Francesco Casella, 4 years ago

Milestone: 1.17.01.18.0

Retargeted to 1.18.0 because of 1.17.0 timed release.

comment:5 by Andreas Heuermann, 4 years ago

Owner: changed from Karim Adbdelhak to Andreas Heuermann

comment:6 by Andreas Heuermann, 4 years ago

I'm currently working on the timers for synchronous systems and indeed the shift is wrong.

I'm adding a new log flag LOG_SYNCHRONOUS which reports the time points at which clocks are fired.

I think the example above should now work. The base clock has its first tick at time 0 and the shifted clock its first tick at 0.1.

comment:7 by Andreas Heuermann, 4 years ago

But I have a problem to understand the following model and what is expected to happen:

model ClockedTest
  Modelica.Clocked.ClockSignals.Clocks.PeriodicExactClock periodicClock(factor=20, resolution=Modelica.Clocked.Types.Resolution.ms);
  Modelica.Clocked.ClockSignals.Sampler.ShiftSample shiftSample(shiftCounter=4, resolution=3);
  Modelica.Clocked.ClockSignals.Sampler.SuperSample superSample(factor=2);
  Modelica.Clocked.RealSignals.Sampler.SampleClocked sample;
  Modelica.Blocks.Sources.Sine sine(f=2, offset=0.1, startTime=0);
equation
  connect(periodicClock.y, shiftSample.u);
  connect(shiftSample.y, superSample.u);
  connect(sine.y, sample.u);
  connect(superSample.y, sample.clock);
end ClockedTest;

We have a periodic clock which ticks every 0.02 seconds. The output of that is shifted by 4/3. And that is super sampled by a factor of 2.
So the first tick should be at 0.02*4/3 and then every 0.01 seconds.

But my log function reports that the shift is 8/3 and the factor is 1/2.
I would expect to get a shift of 4/3.

comment:8 by Francesco Casella, 3 years ago

Milestone: 1.18.0

Ticket retargeted after milestone closed

Note: See TracTickets for help on using tickets.