Ramp function in Structured text...struggling

Rogelio

Member
Join Date
Jul 2013
Location
Texas
Posts
24
I have read all the posts I can find on ramp functions. I need some help with getting a linear ramp output. I want to have a ramp function before the setpoint input to a PID controller. The formula I am using gives a decelerating ramp. Starts out quickly and then slowly approaches end_point.

Ending_Point = Beginning_Point + ((Ending_Point-Beginning_Point)*Elapsed_Ramp_Time/Total_Ramp_Time)


I'm using the current output as beginning point. because this value increases with each scan, the difference from begin to end decreases which adds a smaller amount each scan. Looks like a logarithmic graph. How do I capture the beginning point and keep it constant till ramp is complete? Also allowing it to change if setpoint is changed before ramp is complete in case of a fat finger.
I am using Tristation 1131 4.9. It does not have a ramp in its basic library.
I have a basic knowledge of structured text but not too familiar with calling other functions within my function.

The manual doesn't help much. I'm trying to use TMR so I can use TMR.ACC / TMR.PT as my multiplier.
My inputs are: Enable, Beginning_Point, Ramp_Time,
Output: Ending_Point


I know this question lacks some detail but I'm at home now. I can post my function tomorrow.
Thanks
Rogelio
 
Change your equation to this:

SetPoint = Beginning_Point + ((Ending_Point-Beginning_Point)*Elapsed_Ramp_Time/Total_Ramp_Time)

Use a single shot at the beginning of the ramp to set the Beginning_Point and the Ending_Point and don't change them until the ramp ends.
 
I have that in FB code. When IN <> OUT, it sets begin_point and starts ramp timer. It doesnt reset until IN=OUT at end of timer. But it doesnt accept a second change until IN=OUT. I am trying to learn how to do this in structured text.
I have a second function I built that just adds a small constant to the output each scan. It works OK but it takes different amounts of time to reach setpoint depending on difference in target and output.
 
Originally posted by Rogelio:

When IN <> OUT, it sets begin_point and starts ramp timer. It doesnt reset until IN=OUT at end of timer.

Well, you have HALF of what TConnolly told you to do. The reason the ramp rate is not constant is because you are overwriting the Ending_Point every scan. Both the Beginning_Point and the Ending_Point need to be fixed when you begin the ramp function. You need a separate variable (Setpoint in Tconnolly's post) to be your output, the result of the calculation. You function IN should be the Ending_Point, your function OUT should be the Setpoint. Your comparison to start ramping should be IN<>Old_In. Old_In needs to be static. If you do it that way you can re-initialize the ramp function on any change in the input at any time by redefining your Beginning_Point and Ending_Point and resetting the timer any time a change in IN is detected.

Personally I would use the second method you defined. I guess the way I look at it is you are ramping for a reason. If you optimize your ramp rate I don't see why you would want that rate to change depending on how far you have to ramp.

Keith
 
Personally I would use the second method you defined. I guess the way I look at it is you are ramping for a reason. If you optimize your ramp rate I don't see why you would want that rate to change depending on how far you have to ramp.

Keith

I do see your point. thanks
My other issue is how to write a function or function block using existing functions within it. The Tristation manual does not give much help.

Here is an example of a function block I have created:
FUNCTION_BLOCK VLO_RAMP_INTERNAL_FB
(* This block "ramps" the output up or down based on the product of the Scan_Rate and the Ramp_Time.
It adds or subtracts this value to the output until it reaches Target. Not a true time based ramp*)

(* External Interface *)
VAR_INPUT
(* Put your input variable declarations here *)
CI : BOOL; (* control in *)
TARGET : REAL; (* Target of value to be ramped *)
SCAN_RATE : REAL; (* Scan Time in Seconds (50 milliseconds = 0.05*)
RAMP_TIME : REAL; (* Time to ramp to Target in seconds *)
END_VAR

VAR_OUTPUT
CO : BOOL;
RAMPED_OUTPUT : Real;
END_VAR

(* Local Variables *)
VAR
TEMP : REAL;
END_VAR

(* Function Block Body *)
IF CI THEN (* Sets CO equal to CI *)
CO := TRUE;
ELSE CO := FALSE;
END_IF;

TEMP := TARGET;

IF CI THEN

IF RAMPED_OUTPUT < TARGET THEN
TEMP := RAMPED_OUTPUT + SCAN_RATE * RAMP_TIME;

IF TEMP > TARGET THEN
TEMP := TARGET;
END_IF;

END_IF;

IF RAMPED_OUTPUT > TARGET THEN
TEMP := RAMPED_OUTPUT - SCAN_RATE * RAMP_TIME;

IF TEMP < TARGET THEN
TEMP := TARGET;
END_IF;
END_IF;

RAMPED_OUTPUT := TEMP;

END_IF;

END_FUNCTION_BLOCK

Here is the example given in the manual for the TMR_R timer function. It doesn't seem to be a complete function.
VAR MY_TMR_R : TMR_R ; END_VAR
VAR b1, b2 : BOOL; END_VAR
MY_TMR_R ( IN := b1, RESET := NOT b1, PT := 10.0 );
b2:= MY_TMR_R.Q;

This example does not help me learn how to use it. I see where it is declared. And the .Q is used to set b2 when the timer times out and Q goes high... but is not used. And this example does not compile. Where should I look to learn Structured Text? The manual says it is similar to PASCAL.
Thanks
Rogelio
 
You should be able to use FCs and FBs within another FB.
Don't use timers. They aren't accurate. Use the system clock.
50ms scan time is very long between position, velocity and acceleration updates.
If I wouldn't even use time in this case. I would ramp down the control output as a function of position. This requires a sqrt function.
This is why people buy motion controllers.
 
Originally posted by Peter Nachtwey:

I would ramp down the control output as a function of position.

Are you seeing something I'm not? I don't see anywhere that Rogelio states he is working on a positioning application. Given hi posts it is just as likely that he is ramping the intensity of an inspection lamp as he is position profiling. I'm leaning more toward just general ramping. In fact, the general flavor of the post seems to have turned to be less about ramping and more about using the Tristation flavor of structured text in general.

Rogelio, there is a document that defines the available library functions for the Tristation. I found some links that referenced that document when I did a general web search. But you will probably get very close with the information shooter posted since the Tristation is supposed to be an 1131 language.

Keith
 
Thank you for the replies.
My original application was to be ramp setpoints over a given time but it also became an exercise in learning the triconex structured text language.
I could not understand the oscat link in german.
The basic tristation library does not have a ramp function so I was using it as a chance to practice learning it. The tristation development guide is very weak regarding ST. I was trying to learn the proper syntax for using other functions within my function. For example, how to call a TMR or use its Preset Time and Elapsed time. I did find a reference to this book: "Programming Industrial control systems" by RW Lewis
 

Similar Topics

Hi all, has anyone got a working example of the SCRV S-Curve Ramp Function Block. I cant seem to get it to run - guessing a parameter is not set...
Replies
2
Views
2,771
Good afternoon, This is my first post with this website and I am also relatively new to ladder based programming (used mostly SAMA with DCS...
Replies
3
Views
5,058
Dear All, any body execute the ramp function in Unity pro 6.1 schneider plc.plz gv me some standard ref.program backup. sandip
Replies
0
Views
3,008
can any one give me Linear ramp fuction formula to use in the PLC. pls help me out
Replies
9
Views
7,342
Hello I'm new in PLC programming, and i got a seminar work in PLC ladder programmning. I have to make a RAMP funkcion in MicroWIN 3.2 or 4.0 and...
Replies
2
Views
2,548
Back
Top Bottom