Big Tricky Omron Question part 2 - RESOLVED

9 posts in this topic

In Part One of the Question: "Can the Omron NJ CPU make the Random Sea?"     There were some fine opinions about that.   This example is what it looks like using Red Lion, Delta Motion RMC75E and LinMot:

Recent edit:  The "Big Trycky Omron Question was asked many, many times not shown on this Forum.   I had a very difficult time getting a straight answer from many people at Omron and LinMot.  Probably because they really never tried to do it.  By  the end of THIS thread ( part2 ), Thanks to innoaloe I know that the NJ can generate the position signal, as streaming position data with no time limit, and produce a "randomly" generated model of the ocean's surface.  The "random" part isn't added yet, but, it will work... and the LinMot part isn't added yet .. and it is still unknown if that will work.







Edited by lamboom

Share this post

Link to post
Share on other sites

News Flash:   innoaloe  Replied to a message I sent him which summarized this thread .. well , it's not really a thread unless someone other than me comments on it.. :-)

From innoaloe :

Thanks for contacting. Sorry, I'm not really checking on the forum these days. Got some projects going on ATM.

Good thing that you've solved the homing issue.


Regarding some of your questions :

  1. I'm not really sure what went wrong with the FOR instruction in my previous example. Regardless, I attach here a new sample code (Sysmac Studio *.csm2 file). Just for simplicity, make the workaround with arrays for simpler code
  2. I didn't consider the MC_SyncMoveAbsolute function before. Indeed as Walsh mentioned it will be a better option. So velocity limit will be controlled directly from the axis setting, and no velocity input is required. I had given also example in the attached code.
  3. Regarding Frequency/Period, my previous example was using Angle as the input of the Sine function. In theory the Angle has relation to Frequency/Period as in Angle = 2.(PI).Freq.time or Angle = 2.(PI).time/Period. So in my original code, I didn't consider the current time. Basically it will continue to the next angle on each CPU cycle
  4. What I'm concerned about is the usage of Cycle Time as the "time" argument that you intended to use. There is this instruction to get the Task Period / Cycle Time of the CPU called GetMyTaskInterval, but the thing is it can randomly changed. We can put a maximum limit of Cycle Time, e.g. 1 ms, but should the execution takes shorter than 1 ms, the Task Period will change also.
  5. Let's say the cycle time is always 1 ms, putting that into the previous equation will result into a constant Angle. Because Freq/Period is also constant. That means the resulting wave amplitude will also stuck into the same value, to which no sine wave will be generated.

So my suggestion is to make a preset Timer, e.g. 1000 ms, then we use the timer current value of the timer as the "time" argument. The Timer will be auto-reset after reaching 1000 ms. I put this in the sample code also. Though, please modify the Axis Setting based on your application.

I might be misunderstood about point 4 and 5 though. Regardless you can review the sample should it suitable or not.
Oh, and you can call me Inno. Hope your project going down smoothly, Michael.


I replied:

Hello inno ..

What a wonderful reply! ...  I suspected you were very busy.  It's a fine thing you do on the Forum.  I may have said before that I'm not an automation engineer, or designer of motion control systems; however, I do know enough to get in trouble.  I'm only working on "one" project .. don't expect to ever work on another .. :-)    It's been a long process.   Started with linear actuators that could make sine waves (S-curves) but not enough power, or velocity .. 

Then, I discovered LinMot ... an awesome linear motor,  Billions of cycles, 1 moving part, very powerful, very fast, accurate, and ... their servos, along with their communication software:  "TALK",  had built in curve design functionality,  storage for 100 curves, I/O's for simple non-PLC  control, and yet, would work easily with PLC's, and motion controllers in networks.

When Omron came out with the NJ, with a Motion Control module, two network ports .. I had to find out if it could make the Random Sea.   I'm still not convinced that it can.

Thoughts about your welcomed comments and suggestions:

1) I messed up the FOR instruction because I used the wrong data type for "angle" (REAL) .. also I didn't see an "increment" part of your FOR instruction .. if angle was going to go from 1 to 360 fast was that going to happen?  so I added 1 .. which wasn't very smart, because it would only take 360 CPU cycles .. which would happen in only 360 ms!  to complete one sine sequence.. and then would stop.    I should have used an increment of .001  (will try it this morning just for fun if I can figure out the data type)

2) My frequencies (actually inputted as periods).. ocean waves have periods, never frequencies :-) fortunately, nothing should change fast enough to cause a position error/fault in one cycle time (1.0 ms)

3) I should go back to your original plan to see how that would work.  It looked to me like all three waves would be the same period, just displaced in phase.

4) & 5) Yes.. We couldn't use task period cycle time (or task interval).. But, I understand the CPU cycle time is constant, and can be set for 1ms, 2ms or 4ms.  which is fine.  I was actually going to use WaveTime := Wavetime + Cycle time  at the end of each loop, so the only thing that changes in my large summing equation is time by, 1ms.    

By the way.. there has to be some amplitude control.  I would put a "percentage" multiplier at the head of the summing equation that could modify the position result from 0 to 150%

Also, to prevent violent starting, splashing, and discontinuities at the beginning.. especially when phases are being used, a ramping function for the first 3 seconds of wave calculation would be necessary.. perhaps something like:


    //Phx is in degrees
    //WTime is in seconds
    //CxPer is in seconds
    //CxAmp is in inches
    // M_Pi  is Pi (3.34159)
    //Percent    (inputted as: 0 to 150)
    //Height     (0 to 1.5)   equals Percent factor, multiplying the summing position result.
    CycleTime:= INT#0.001? This data type is wrong.. but I can't remember at this moment what it should be.. DUH
    Num := INT#0
    WaveTime:= 0.0

// Assume Percent is equal to 25 .. Height must grow from 0 to 1 in 3 seconds from start_wave. or 3000 cycles

// The following is a 3 second ramping time for the variable “Height", making it go from 0 to "Percent" in 3 seconds.

          Num:= INT#0

          Num := Num + INT #0.001 (must fix data type)

          UNTIL  Num > 3       // it will take (3000) 1ms cycles to reach 3 seconds


        Height := Percent * Num / 3.0;

        WAmp := Height * ( C1Amp * SIN( 2.0 * M_PI / C1Per * WTime + Ph1 * M_PI/180.0) +
                        C2Amp * SIN( 2.0 * M_PI / C2Per * WTime + Ph2 * M_PI/180.0) +;
                              C3Amp * SIN( 2.0 * M_PI / C3Per * WTime + Ph3 * M_PI/180.0) +;
                              C4Amp * SIN( 2.0 * M_PI / C4Per * WTime + Ph4 * M_PI/180.0) +;
                              C5Amp * SIN( 2.0 * M_PI / C5Per * WTime + Ph5 * M_PI/180.0) +;
                              C6Amp * SIN( 2.0 * M_PI / C6Per * WTime + Ph6 * M_PI/180.0) +;
                              C7Amp * SIN( 2.0 * M_PI / C7Per * WTime + Ph7 * M_PI/180.0) +;
                              C8Amp * SIN( 2.0 * M_PI / C8Per * WTime + Ph8 * M_PI/180.0) +;
                              C9Amp * SIN( 2.0 * M_PI / C9Per * WTime + Ph9 * M_PI/180.0) + ;
                              C10Amp * SIN( 2.0 * M_PI / C10Per * WTime + Ph10 * M_PI/180.0));

       WTime:= WTime + CycleTime;

// the servo position calculation continues until stopped, with the WaveTime incrementing each cycle time of 0.001 seconds        


Yes ... I think the NJ doesn't calculate sines this way... I will have to adapt...    Hopefully, your example will help.

Thanks so much for an example code....  I'm going to owe ya big time :-)

6) PS:   We should keep this on the Forum.. for the members benefit.  Although, I suspect position as a function of time is not often a factor in machine design.

He Then replied:

Hi Michael,

it's about midnight in my place now, so I'll look more into your algorithm later on :D


I still had a little doubt though about the idea to use 1 ms as increment value by depending only with the CPU cycle time. As I stated before, even though we set up CPU cycle time to 1 ms, it may goes faster than that if the whole program execution doesn't need that much time.

Let's say the actual cycle is only 0.5 ms, you'll still adding 1 ms to the sine wave time counter, which will cause the sine to progress faster than it actually is.

You can check the actual/minimum Cycle Time from the Task Settings. I attached an image to find where.

So if you need to really kept the increment time to 1 ms, it's better to use the TON function that I provided before on the sample with Set Time to 1 ms.

Regarding *.csm2 file, it is a compact version of Sysmac Studio project file which only contain programs and hardware setups.

The *.smc2 file will also contain Data Trace Logs (yes, Sysmac can do that, you can check whether your sine goes correctly by simulation first) and Event Logs. This usually takes 2 MB file size at minimum. On the contrary *.csm2 files would goes around hundreds of KB at most.

Since you're the topic owner, feel free to share this thoughts on the forum :D

Cheers, I'm gonna hit the sack atm


Edited by lamboom

Share this post

Link to post
Share on other sites
On 2/24/2017 at 10:29 AM, lamboom said:

Let's say the actual cycle is only 0.5 ms, you'll still adding 1 ms to the sine wave time counter, which will cause the sine to progress faster than it actually is.

But..isn't the cycle time fixed at 1ms..? (or 2ms or 4ms)

Does Sysmac have sine function block, that would work with my linear equation: Amp * SIN( 2.0 * PI / Period * Time + Phase * PI/180.0) ...   I'll see if I can find one....  (still, would like to make this one work ...)

Edited by lamboom

Share this post

Link to post
Share on other sites

Hello Michael,

glad to see you've been testing it. I had seen flaws on the code that I sent to you last night... you know, brain cannot functions really well during when we're about to sleep :slydog:

This kind of project piques my interest better compared to machine automations actually. Of course many new things come out to the automation world, but this kind of proving theories is more fun to me. Well, maybe I can say that for now since I just finished my degree 3 years ago. I dunno whether I can say that in the next 5 years. Hahahah... :shifty:

Anyways, I had create another revision for the code. I don't have hardwares with me to actually test it, but the simulation result seems to be good enough as you can see on the following Data Trace result. Here I just put 3 Sine components to be seen, but actually there are already 10 components that makes the resulting Axis Position. I didn't show them all just to keep the tracing result look readable. You can look more into it in the program.

I am using Amplitude and Period as the parameters. No phase shifts added so far, you can add it later on.

And just for further references on why the previous sample didn't worked :

  1. The MC_SyncMoveAbsolute only accept _mc_Aborting Buffer Mode. My previous one was using _mc_BlendingNext that's why it returns an error. A quack with Sysmac Studio is that it doesn't really limit what input are you giving to the FB as long as the data type matched, so unexpected misses like that can be expected if we're not really reading the manuals thoroughly.
  2. The FOR Loop was made from counter from 0 TO 10 to which the actual array index was 1 to 10. I forgot to set the FOR Loop limit from 1. Already fixed that in the current program
  3. The previous example was using a fixed 1 ms Timer to control time value. This was actually a mistake since I forgot that for different Periods, a Sine Wave will end on the time that is the same to its Period. The other that I forgot is also we're talking about Discrete Signal here, so the time parameter should be an increment of a certain Sampling Time. This was actually mentioned in your algorithm before.
  4. The calculation for Sine in the previous program is using DegToRad function. It was actually not necessary since 2*pi*t/T is already resulting into a radian and not degree. It was also what makes the CSine value looks weird before. I had removed it in the new program.
  5. In the new program we define first the Sampling Time, then increment the SineWave Time for each SineWave components. We need to have separate counters for that because we need to reset the time to 0 for each SineWave is reaching its Period, which should be different for each.
  6. I was using Omron newest servo, the 1S-series as my Axis in mind, that's why the encoder count is much more higher (about 8 Million). Fixed that in the new program to G5 encoder count (1048576)

You still need to edit the Axis setting since mine is Virtual Axis in degree units. Also the Homing function is not yet there. It might also require another tweaks here and there.

Since you're seems to quite OK with the Ladder, I changed my program to be based on Ladder also. Frankly speaking, to me the readability to human is much more easier compared to ST. Hope it helps


Edited by innoaloe
Adding notes

Share this post

Link to post
Share on other sites

Hello again inno  -  I'm so happy that you appreciate looking at this project.   It's been a goal for me since mid 2010 ...   I helped design this "tsunami" tank for the Museum of Science and Industry .. in Chicago, Illinois

They only wanted a few different waves to inundate two shore designs.  I was hired by the company tasked with building the tank, to do the engineering, and design of the wave maker, tank and shore designs.  I built many models of the shores.  At first the museum didn't want the water to splash the back of the tank, so the shore models were a little longer, and more complicated, with various land formations, and objects that would mitigate flooding, yet permit a very large wave to hit.  When they saw how big the wave could be made (The largest wave took about 800 pounds of force to generate)  They loved the big splash at the back.  However, that's not a Tsunami.. it's just a "big wave"  A tsunami is a very "long" wave with a period in the 10's of minutes.   I managed to talk them in to having many  normal "regular" waves, which could be made at the highest possible amplitude the laws of physics would allow... and yet none of these waves would inundate the shore models.  The cliff model even had islands, a cave.. and a "blow hole" .. but, the museum thought that was too complicated for young minds trying to contemplate tsunamis... so the shore with a cliff became only 2 dimensional, and simple ... I also wanted them to show the "Random Sea" when no one was using the tank.. just to have the normal ocean ... that way, kids could see how waves travel at different speeds, and form up now an them as "Rogue waves"   The tank is 33 feet long! ... plenty of time for that to happen... again.. too complicated... sigh! 

Anyway...  Once again, you significantly show the possibilities of Omron's NJ to do this job...  There's no big money here .. in fact, there's probably none.  I'm just trying to make a system that is affordable to schools, and museums.   (the wave tank at MSI was enormously expensive!)

1)  I tried other buffer modes,, but not that one.. I find the manuals somewhat overwhelming .. but, there's always some good stuff there if you keep reading them.. over an over.. :-)

2)  I should have caught that too.. for now, one sine wave was enough.. if that worked, then on to 10 .. or more.

3)  Yup... :-)

4)  Yup... :-)

5)  Sounds complicated.. but I appreciate where you are going with this.

6)  I didn't try to run your original program.. I can't, because my CPU is a NJ101-1000, and using the G5 motor & drive  (I'm already set for 8388608  where did ya get 1048576) ... I changed to 1048576.   works OK.

7)  I made Pi := LREAL#3.14159  :-)  what's with this 22/7 stuff?

I really like ST... I only shifted the FB out to look at it better .. Remember.. I'm the ultimate nubie .. you probably shouldn't be seen talking to me...

By the way... I am amazed by your "Data Tracer"  above.. GADZOOKS! ... is that something in Sysmac?

Bye for now.. off to explore your work... Thanks again.   Michael

PS:  You will notice my MC axis is Ax0 .. that's from the program that Michael Walch gave me for homing the G5 incremental motor .. I was just adding your program to his for testing.


Edited by lamboom

Share this post

Link to post
Share on other sites

Hello Michael,

yes, the Data Trace is indeed inside Sysmac. You can look on the left window somewhere near to Axis Settings. We can choose what to be recorded, then start recording the data. Once we stop it, the plot will be shown (yes, the plot cannot be updated in real-time).

Being a newbie is always a start... give me something other than Omron and maybe I'll lose my mind :D. In fact by looking into your project I've got a new idea for our exhibition, making sine wave trajectory control. It's not something common in automation, but in terms of exhibition is always to show-off, so something out of the ordinary is always better :D

Whenever possible I'll gladly assist

Edited by innoaloe

Share this post

Link to post
Share on other sites

Gadzooks!   you're up at midnight +   it's 9:28 AM here.. ooops.. I just noticed you sent this 44 minutes ago... (I've edited my reply)

Observations:  Program is working (sort of) .. and It's interesting what is happening.

1) There were only 2 warnings for your program, after I added the HMI:


I made them Global Variables, an that made Sysmac happy.

2) I've noticed the TON is active all the time, starting with P_On, and so CSine is always changing value, before one activates the axis:


3)  activating the axis can be tricky.. with CSine not at zero.. a discontinuity can be large enough to cause an error when Axis is activated..   I added a "Axis_Activate" to the input line on both TON and the ST below it.. Works great now.. However, when random phase drift is added.. the output "CSINE" must be at zero, and slowly ramp to full Amplitude in about 3 seconds. That way starting discontinuities are never a problem.  Also, there is the necessity to manage the final output amplitude, with a percentage modifier, slide or input on the HMI ... which will make quick changes to the average amplitude of the Sea, without adding any changes to the component's relative amplitudes.  FYI: The amp/per component relationship is critical to the authenticity of the Sea state... nice to have an FFT component on the HMI too.

4)  I'm curious why we don't see any information in any of the other boxes (notice the exclamation marks)   Also, in the picture, the CSine on the left side of the final equation is equal to the CSine on the right.... I guess things are happening so fast, they don't register at all?    It looks like CSine is changing by magic... :-)

With the inputs as follows:


The motor is making a nice sine summation response ... Congratulations!

By the way.. watching the seemingly random way the TON is working ..  and this program is working .. I still have very little understanding as to why it is working .. I must play with the Data Trace feature of Sysmac...    I get the feeling that the NJ is either brilliant, or excessively complicated  .. to be continued.

GADZOOKS! .... as i look at this thread.. it's enormous ...  I'm thinking of removing much the problems.  unless you like it as is... ?


Edited by lamboom

Share this post

Link to post
Share on other sites

Hi Michael,

good to hear things are progressing well. Some notes I can add :

  1. Warnings not necessarily a problem. In case of my example, those two Local Variables got nothing to control them, that's why Sysmac warns us. Clearing such warnings can either by making them a Global Variables (Sysmac will suspect they're being controlled from HMI), or making a Coil for the same Local Variable (that way Sysmac knows that the variable can be controlled).
  2. In the example I did not control the TON activation, so it starts straight when the CPU is booted. As to why CSine kept on changing before Axis was activated is because the TON will keep giving increments on the cycle time, and thus it will be recalculated.
  3. In case of activation timing, I suggest you make an interlock to the MC_SyncMoveAbsolute when the servo is not yet in Home Position. Means we need to finish Homing first before starting the CSine. Also when triggering the Homing, you should reset CSine, all FSine, and all SineTime to zero. Looking at your video, the Home Position is not in the middle of the tank, more like in the far back. In that case maybe we should add a centering offset to the CSine, like : CSine = Offset + CSine + FSine[j] to prevent negative position value.
  4. The reason some boxes are not changing is because they're in a FOR Loop which is indexed by the j parameter. Because j kept on changing, Sysmac will not show each array index values. You can however see each array index values changing from the Watch Window (IIRC the shortcut is Alt+F3, the toolbar icon is glasses with a square behind it), or just use Data Trace. The reason CSine to the left is the same as CSine to the right is because Sysmac can only monitor the latest value of the variable, so it won't store the previous value in the right equation.

On the other note, the TON is not working randomly. It basically starts when the In input is activated. I interlocked it with it's own output Q using normally-closed contact. That's why it will disconnect itself when the set time is reached. Disconnecting In will results to Q turning off, locking back the normally-closed contact, then the timer will restart.


EDIT : Maybe you can remove the first two posts, since we resolved the issues already, just to make things cleaner :shifty:

Edited by innoaloe

Share this post

Link to post
Share on other sites

G'Evening Inno ...  Thanks for more good stuff...   By the way.. I think it's working great!  (I just have to study more, to understand why)  It was probably working the first time.. but the buffer mode was probably wrong then .. sigh!     This stuff is really difficult..   It works fine now with no errors..  

The next challenge is the addition of slowly drifting phase angles ... very slow changes, so that no discontinuities occur .. might work in the RAND Function  (page 2-218 of manual W502-E1-18  NJ Reference)   Comments on your comments:

1)  I took care of the warnings by making the variables Global .. 

2)  I  added the input "Axis_Activate" to both the TON and the ST below it.  

3)  I think activation timing is OK, for now... because I always home before doing anything. However, a "real" programmer would make it impossible too screw up the proper sequence of events.  I will follow your instructions.  I'm also going to do much much more .. like alarm warnings, and adding alarm reset functions (I won't bug you about that.. I know how to do that part.. :-)    I Like the idea of reset CSine, all FSine, and all SineTime to zero, when homing.  ..... will do.     

Home position is as far as possible to the left of the tank.   When wave sequences like Regular Waves trains,  Rogue Waves, and Tsunamis run, they start from the far left position of the wave generator, and are defined with positive positioning from zero (initial position).   The Random Sea must be made with positive and negative positioning.   In order to avoid calculating a proper clearance "offset" move, so the generator doesn't hit the negative limit.. I just use an estimated "Offset" prior to wave start,    When making the Random Sea, the generator cannot get too close to the back wall of the tank, or the water level behind the generator (wall) will rise above the tank.     Some Wave making facilities continuously pump water from behind the moving wall, to avoid this problem.

After thinking about your "Offset" equation  .. Methinks it will work to  move the CSine up (or to the right) by a fixed distance, that would be good....

4) Thanks for the 'Watch Window" idea.. I have used it before  .. and need practice  ...

The reason I thought TON was "Kinda" Random.. is because it looks that way.. when "on-line"  I see the green lines go on.. for a while, then off then On (like they should).. but they seemed not to be "regular"  

By the way.. perhaps we should take this back to Messaging... now I'm sure no one in the Forum wants to read what we are talking about.       

check this out:



So much wonderfulness... :-)



Edited by lamboom

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now