# Don't want an "S" curve, need a half Cosine Curve RESOLVED

## 7 posts in this topic

I see there are some nice math instructions in the NJ's menu.    I can't use a MC_MoveAbsolute.  It must be a Cosine position curve running from zero to a positive max end position.

I imagine I can use an offset to start the curve at zero, as the COS instructions produce a wave from -1 to +1 and back again.   The trick is to start the curve at -1 and end it at +1 ...

If you know an easy way to do that, please share..     Regards, Michael

PS:   This may seem silly .. but, after finding it so easy programming a Delta Motion RMC75E motion controller to due exactly what I'm asking above... I am surprised as to the degree of difficulty dealing with Sysmac & the NJ ...  The level of complication is excessive, if one tries to go beyond the available Function Blocks, Functions and packaged math expressions.    Sure it's easy to do a trapezoidal move from one position to another.  But, I want a cosine curve (or, if you like, a sine curve) .. they are somewhat the same ... but not exactly the same .. and they are certainly not a trapezoidal move component.       I know The NJ can do sine waves ... Check this out:

Perhaps, this video will help illustrate the problem.  Regrettably, it may require some innovative programming on a complex level ... such work is often done for the programmer by other manufactures of Motion Control modules...  it is certainly beyond my experience, and ability.

Any suggestions, short of actually writing the program, would be a big help in my learning curve... Thanks much.

Edited by lamboom
to add more info about the problem

#### Share this post

##### Share on other sites

Hi again... more information about the objective.

Wanted to explain the problem better:
Imagine this Sequence: A typical "S"curve ... generally starts from zero accelerates by a specified amount, then moves at a constant velocity until nearing the end point of the move, where it decelerates by a selected amount and stops at the "end point" .. a distant positive value. Then after a few seconds, another move, slower than the first slowly ramps at a constant speed back to zero... and, awaits the next move programmed and launched by a NA HMI

That sequence is what I'm trying to do.

In Ladder (Omron), you would probably use the MC_MoveAbsolute function block to make this move. Very easy, and almost intuitive...

But.. what if that "curve has to be a "cosine wave"? It starts at zero and moves to the positive end position, and only the "path" is programmed, not the velocity or the acceleration.
Now you would have to use the MC_SincMoveAbsolute fb. And the "path" would be calculated in ST .. with the only inputs from the HMI as "Amplitude" and "Period". The final positive end position (amplitude), and the time (in seconds) it would take to get there.  As we are not moving in a complete cycle, only a half cycle ... the "time" could be thought of as half the period.
This is some brute force programming, I cannot do .. yet

I can generate a sin or cos routine in ST (With some help from Tyler Corbett):

(1) Pi:=3.141592;
(2) SampleTimeSec:=TOLREAL(TimeToNanoSec(GetMyTaskInterval()))*1e-9;
(3) SinTime:=ModReal(SinTime+SampleTimeSec, Period);
(4) FSin:=(Amplitude * SIN( 2 * Pi * SinTime/Period);
(5) Sine:= Sine + Fsine

The global variable Sine is sent to the Position input of the MC_SyncMoveAbsolute (or some Final_Move sequence in ST)

Now, The trick is to use 1/2 a Cosine wave (a 90 degree phase shift of a sine wave), and only use the first 180 degrees of the wave.. where it goes from zero to maximum positive (yes, it really goes from -1.0 to +1.0 .. but.. there will be an final rung for OFFSET (6) Final_Move:= Offset + Sine so that all moves are positive)

This equation must run only once, unlike the above example which would run forever. After doing that one move.. there is a time delay (TON) then the position ramps slowly back to zero .. and waits for another run.

I'm asking for any programming ideas that would control the equation for using only a half cycle.. which starts at zero and moves positive to the input: Amplitude. I don't expect the actual program.. just some text explaining a good method to control the process. Please.

I assume the COS instruction would work just as well .. I just don't know how to use the best instructions to control the position equation...

Thanks Much, Regards, Michael

PS:   The equation (4)  isn't the problem.. to be clear ... My problem is in managing the equation in ST or Ladder programming .. something most everyone here is well versed in.. 'cept me.

I'm imagining IF-THAN, and other expressions that will start and stop that equation's position feed to the ME_SyncMoveAbsolute function block which is talking to the LinMot drive via EtherCAT.
The perfect sequence (with out the  glitch)

There are 3 moves: the cosine SyncMoveAbsolute, the Delay and hold, and the MoveAbsolute back to zero

Edited by lamboom
spelling correction

#### Share this post

##### Share on other sites

Doesn't look like anyone is gonna comment on this post ..  I guess this Forum is mostly for the professionals .. That's OK..  I'll keep reading the manuals ..

Looks like this should be done in three rungs of the ladder .. I'm close to figuring out how to make the Cosine position curve above.. Got some good help on PLCs.net Forum

working now on the way to "jump" out of the calculation for the curve when the amplitude equals 2 * Amp..  .. Sure, might use an IF Amplitude < (2 * Amp) THEN quit calculating the cos curve, and hold for a while (go to a TON,, then after a few seconds.. use a MC_MoveAbsolute to get back to zero... but, ya can't use a "Jump" in an ST IF-THEN expression.

Even  if one could use a "Greater than or equal to" FUN in Ladder ... How you would stop the position equation at a paticular point ,   continues to elude me...    Later.

Edited by lamboom

#### Share this post

##### Share on other sites

I want to look at this, just have not had the time to really dig in, sorry.  Perhaps soon.

1 person likes this

#### Share this post

##### Share on other sites

Hi Michael ...  Glad you are still out there... When you can.. this is what I've got so far:

Line  6 generates the cosine curve, and makes all points positive because of the + TsunamiAmp at the end  (help from "Dirt" from Stockholm, on PLCs.net) ...

I tried an inverted "Stop_Tsunami" to turn off the MC_SyncMoveAbsolute Fb.. but.. it didn't work...

Interesting that there doesn't appear to be a way to jump from an ST line to a ladder rung...  or from an  IF   FSine_Tsunami => 2*TsunamiAmp  (or PeakToPeak) THEN stop calculating FSine_Tsunami and hold at that last position...& start a timer ...  how hard could it be...

I'm trying to jump out of the ST when the cosine wave is finished, and hold for 4 seconds

This program almost works ..

The cosine wave starts at zero (+ a small offset) and, I believe reaches the max positive (2 * TsunamiAmp) .. The GE instruction (Greater than or equal to) should go true when the peak positive is reached..  But, this probably isn't the correct way to stop an hold a position when using a MC_SyncMoveAbsolute.

The TON is intended to hold for 4 seconds, then trigger a MC_MoveAbsolute from wherever the hold position is,  back to the offset.

instead, when the cosine move should stop ....  the motor quickly moves negatively to the hard stop, way past the offset, or zero position.  sigh!

Ya think this has something to do with pulling the plug on the ST that's running the position stream to the MC_SyncMoveAbsolute?   That function block is still on, and generating position data... but, the data isn't changing .. it should be: Offset+ TsunamiSine , which should be Offset + (2 * TsunamiAmp) .. The last calculation of that ST line (6) would be the max positive position (2*TsunamiAmp)

Edited by lamboom
make corrections

#### Share this post

##### Share on other sites

Tried some other options .. also didn't work well .. one thing for sure,  the equation for FSine_Tsunami is correct ..it provides a new position every 1.0ms to the LinMot Drive.. That part is working well.. just things go badly after the position equals (2*Amplitude) .. the peak to peak value of the 1/2 cosine plot.

Using an IF-THEN to jump out of the position calculation.. Turn off the ST (which is not a good idea.. but, what else)  The T-Hold starts a timer for 4 seconds, below:

Turning off Tsunami_Run also kills Delay_Timer.Q .. which powers off the MC_SyncMoveAbsolute with brute force .. probably should use MC_STOP,  but that brings problems too.

This causes the linear motor to jump a little in the negative direction, but 4 seconds later the MC_MoveAbsolute fb kicks in and the position ramps to zero or Offset, if an offset is selected.   After the return to zero, MC_STOP is activated by TON:

MC_Stop is reset by TON:

This still doesn't work... because there isn't a way, known be me.. that will permit this sequence of moves to be done in 3 stages.  Omron doesn't have stages.. but, it does have tasks... perhaps, i should look into that more closely... to be continued..

Edited by lamboom

#### Share this post

##### Share on other sites

STATUS:    Changed to using State Trackers  .. That worked well .. No clunks, and the sequence runs fine; but, only up to a point.  There is a point at short periods (0.3 sec) to the positive peak of the cosine ramp up, when the control fails and the linear motor runs away negatively into the hard stop. (have nice shock pads for that..     This may be due to the position equation itself.  By creating only 180 degrees of motion mathematically ( SIN(2 * Pi * Time increments/Period) + 270 degree Offset)  The 2 is not in this equation)  The equation is only for a half cycle...  perhaps it should be in the equation... or something a little larger than 1 .   Because, the "end" timing is too critical.  In only one CPU cycle, (0.001sec) the curve will go from + peak(max) to zero!.     Probably, better to make the cycle go slightly past + Peak(max), but try to catch the + Peak(max) with the IF-THEN statement.

UPDATE:   RESOLVED... both Tsunami and the Rogue wave series:

Found a way to use Inc in ST ..  makes for easy jumping to various states.. or stages..     Thanks all!

Edited by lamboom

## 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