Polynomial fitting on Mitsubishi FX5u

luca72

Member
Join Date
Apr 2024
Location
Italy
Posts
11
Hello there is a way to do the polyfit on 3rd degree on this plc.
for imput i have a munimum value of 5 X and 5 Y value for example

Measured value

X y
350 10250
460 9870
530 8536
680 7653
800 5560

What i need is to obtain an y value entering an x value that is included in the range of the measured value, i able to do with python but the problem is that i can't connect the plc to a pc because the customer don't what to have a pc connected.
Thanks for your reply
 
Code:
X        Y          ▲X    ▲Y
350      10250
460       9870      +110  - 380
530       8536      + 70  -1334
680       7653      +150  - 883
800       5560      +120  -  93

How often do the five pairs of [X,Y] values change?

In other words, do you want to
  • BOTH fit the sampled X,Y value pairs to a polynomial with coefficients on-the-fly in the PLC AND then evaluate the polynomial i.e. calculate Y = P(X), in the PLC program, or
  • calculate the fit coefficients external to the PLC once, and then hard-code those coefficients into the PLC program and do only evaluations of the polynomial in the PLC?
 
Another option: does the target PLC have motion control? Can the desired function be entered as a "cam profile," or whatever the target PLC calls it?

Also, look into splines; they will yield simpler interpolation algorithms between pairs of points on that profile than a single set of third-order polynomial coefficients fit to all the data for the entire span.
 
Hello drbitboy i need to do all inside the plc i can't use external PC, I don't have motion control in this plc sorry
Luca

 
The FX5 is quite a powerful PLC I cannot load an FX5 Project at the moment as my GXW3 is broken only load GXW2 which does not support the FX5, however, if I remember correctly it has plenty of memory & a rich set of instructions probably 200 + so I think you can do almost anything, it is part of the I/Q/F series I know I did a horizontal tank level calculation plus quite a large recipe system stored in some retentive memory.
 
Can the FX5 do matrix math? Does it have structured text? Otherwise, you will need to type in some long equations in ladder. Not fun.
Also, this is made harder because the x locations are not evenly spaced.
Can't you just translate the python code into ladder or are you using a python library.
Also must the third order equation go through each point or just to a best fit.
It takes only 4 points and 4 equations to calculate the 4 coefficients for a 3rd order equation. The system of equations is over determined so you need to settle for a best fit.
 
The FX5 is quite a powerful PLC I cannot load an FX5 Project at the moment as my GXW3 is broken only load GXW2 which does not support the FX5, however, if I remember correctly it has plenty of memory & a rich set of instructions probably 200 + so I think you can do almost anything, it is part of the I/Q/F series I know I did a horizontal tank level calculation plus quite a large recipe system stored in some retentive memory.

Doing it inside the PLC may be less than ideal, as @Peter Nachtwey mentioned, but if that is the only option this post by @parky should give you some hope. How good are your math skills? As @Peter Nachtwey mentioned, a third-order polynomial with five samples is most likely a least-squares fit, but there are other options.

Is there a specific algorithm and parameters to use that define the desired fit?

Can you show the Python code you used to fit data (e.g. did you use numpy.linalg.leastsq?), along with a plot (if you cannot plot, I can take your code and add a plot)?
 
The FX5 will have limited maths to the functions availlable in the IDE, As I stated, my GXWorks3 is broken at the moment need to dig out my instasll disk, but in the older FX3U the instructions are quite good although there are some not listed, i.e. cos-1 is one I can think of. I would imagine that the FX5 is an upgrade of the FX3 so it could contain many more maths functions & yes it can be programmed in ST, however, some of the functions do require specific FB's as these may not be availlable like in C or othe languages for example a pulse function is not PLS M2 but PLS[M1,M2] in other words when M1 goes true M2 is pulsed for one scan. As the ST language was introduced later in their IDE it had to be compatible with the ladder and existing platforms so rather than the functions returning the result the result is within the brackets i.e. what would normally X = cos[D0] it is Cos[D0,X] so you need to do some calcs & put them into temps then use them that is what I had to do in my Horiz tank level calculation.
 
I have a solution. There is an interpolation technique called Lagrange interpolation or polynomial.
This works well if you don't have cubic spline capability.
It also works well if the distance between the points is not equal and the polynomial WILL go through all the points.
Given the numbers above, if the current x value is between 460 and 530 you would use the 4 points at 350 460 530 and 680
If x is between 350 and 460 you would still use the same 4 points. Ideally you want to have two points to the left(neg) and two to the right(pos).
the PLC would need to do some checks to see what interval it is in and then execute the formula.

The positions, velocities and accelerations will be continuous at the points ( knots) and the position and velocity and acceleration will be smooth.
A long time ago before our motion controller had cubic splines we could do basically the same thing with Lagrange interpolation.
 
Doing it inside the PLC may be less than ideal, as @Peter Nachtwey mentioned, but if that is the only option this post by @parky should give you some hope. How good are your math skills? As @Peter Nachtwey mentioned, a third-order polynomial with five samples is most likely a least-squares fit, but there are other options.

Is there a specific algorithm and parameters to use that define the desired fit?

Can you show the Python code you used to fit data (e.g. did you use numpy.linalg.leastsq?), along with a plot (if you cannot plot, I can take your code and add a plot)?
Hello i use numpy plyfit and polyval
 
Hello, I don't know of anything like this in FX5, and as mentioned above, you'll have to use your math skills instead of premade library, but I tried to achieve something similar but much simpler (1st degree) but I was forced to move the calculations out of plc anyway because it burnt out on operations with decimals.
 

Attachments

  • mitsu1.PNG
    mitsu1.PNG
    32.2 KB · Views: 21
I asked some questions in #6 that weren't answered. I have solutions if a least squares are required.
The OP didn't say if the resulting equations need to go through the points. IT MAKES A HUGE DIFERERENCE!

The OP highlighted what I don't like about using libraries or packages. They are great at getting answers AS LONG AS YOU CAN USE THE LIBRARIES.
I see the same thing happen on other forums where they use Matlab to solve their problem but have NO CLUE as to how to move their solution to a different platform. Getting answers without understanding isn't much good.

I know the algorithm that is used in np.polyfit(). One can look up the source code. The easiest way to implement it is to use matrix math. However, I have generated the solutions symbolically.
Look at the solution %04. It is the symbolic solution ( the perfect solution ) to fitting a 11 points to a 3rd order polynumial. The difference is that I have assumed that all the points are equations spaced by interval T. If the points aren't evenly spaced then I must use intervals like T12 for the distance between point 1 and point 2. Now the symbolic solution is much more complicated.
If you don't have matrix multiplication, then you need to computer the symbolic solution like in %04. Then you can plug those formulas into the PLC and solve for the 4 coefficients for least squares fit 3rd order polynomial

%O30 has a the equations for computing the coefficients for a 3rd order polynomial using 5 points but again, I assumed all the points are equally spaced. The equation gets to be much more complicated when there are intervals like T01,T12,T23, T34, I would calculate the coefficients for the third order polynomial and then just execute the 3rd order polynomial in the PLC. This works as long as the points don't change.

Why can't the OPs give us the info we need in the first post instead of wasting everyone's time. I could have had the OP's solution computed within an hour of his first post. Instead a lot of time has been wasted.
 
They are great at getting answers AS LONG AS YOU CAN USE THE LIBRARIES.
Such a fiery speech...
Although I have to admit that I agree with this speech... (Although the Runge-Kuta method...)
In any case, the engineer would have stated the requirements and constraints from the process side, rather than what is stated in #1….
But you know this without me - so the question is: why did you burst into such a fiery speech?
PS I don’t entertain myself with the illusion of being able to change the world. Human laziness is a circumstance that cannot be overcome
 

Similar Topics

If a polynomial is used in a cam-profile for motion control, you normally have the option to displace the inflection point from the standard 0.5...
Replies
1
Views
1,448
We recently purchased a used piece of equipment and i am trying to modernize the control system, but I'm not very familiar with it. This machine...
Replies
8
Views
2,356
I have two NEMA cabinets that I need to pass some cables between. The two cabinets are mounted on the outside, either side of a 90 degree corner...
Replies
5
Views
2,714
Hi There, We have a hydraulic power unit we are building for a Class 1 Div 1 application. The customer wanted a specific kind of proportional...
Replies
0
Views
5,144
Back
Top Bottom