3rd Order Polynomial

I am curious if anyone has a 3rd order polynomial equation they would be willing to share with me. I am looking to draw regression plots from x,y data generated by sensors connected to our Opto 22 PLC system. I am also looking for a Coefficient of determination that i can use to see the curve fit information.

Thanks for any help you all can provide i really appreciate it.

How about send data to python node in nodered?

Using @Eugene idea… what about passing the data from the PAC Controller and back through Node-RED and use this node here; node-red-contrib-regression (node) - Node-RED

Thanks all for the suggestions I really appreciate it and they are very good ideas. I don’t have much experience with Node-Red (only used it a couple of times). My next question with this would be do you have any examples that would work well with incorporating this in Node-Red? One thing i will add is that we just added a epic pr1 to our snap pack system (performance has sky rocketed on our system). we currently use the pr1 as the central processor and the r1 is only used to read the io on the snap rack. I’m just trying to think of the best way to call up the node-red 3rd order flow? Sorry for all the questions around Node-Red just don’t really have any good experience with it.

thanks again for all the help with this.

Before we happily go down the Node-RED rabbit hole… Re-reading your first post, you mention you want to graph the result… How are you thinking of doing that?
groov View can only trend values over time. It can not do x-y plots.
I think we can do x-y plots in PAC Display. Are you running that on site?
I also believe that Node-RED can do x-y plots. Are you against having the results shown in that Dashboard view?

Have you got some thoughts on this aspect. It could impact the path you take to get to it.

1 Like

Currently have a pac display program that graphs results for me to change to another display program will take significant time (around 60 windows in PAC Display Pro) so currently not looking to change the display program. long term (3+ years) we are looking at using ignition to run our system but even that is not a guarantee.

The way it is currently graphed is through tables and then just displaying the information from that table on the graph itself.

There are two major parts to using the regression node: the first is providing the node with data, and the second is calculating the function that it generates based on that data.

For providing the data to the flow, that will depend on whether you are watching one sensor change over time or if you are working with two sensors in relation to each other. The regression node should be able to handle either, but how the flow looks will change depending on what you need.

Once the node has determined your function you can either calculate your predictions directly in Node-RED and export the results to PAC, or move the coefficients (including the coefficient of determination) into PAC to do any calculations and graphing you need there.

To get the data INTO and OUT of Node-RED you will use these nodes here;

They link to your PAC Control variables that you set up in your strategy.
The results from the regression node will feed into them as well, and then you can link those variables in PAC Display.

All this will run on your EPIC controller, so you are set to go, @torchard and I are ready to help with example flows etc, we just need a little direction on how you need things set up (See the questions in Terry’s post above mine).

1 Like

Thank you @torchard and @Beno I am off today and tomorrow so dont have any data currently in front of me but i will get you some data from the sensor (both x,y) and how it currently is programmed so we can find the best way to incorporate this. Also it is watching two sensors in relation to each other. Thanks again for all the help with this it is greatly appreciated.

currently one table holds the x value (first sensor) another table holds the y value (2nd sensor).

1 Like

So i have done a little testing with this to get familiar with it and not really sure what I am doing wrong. I have created a very simple flow in node red where i just set an array in a function block and pass that information on to the regression node. I am not getting any output from the regression node. I have tried changing the payload from msg.payload.x to msg.payloadx and I have done the same thing to the y payload as well and not getting anything on the debug screen. It probably has something to do with the period between the payload and x and y but as i have stated before i am not familiar with node red or java script. I am probably making a very simple mistake with this and apologize before hand. As always thanks for all your help!

[{"id":"14ba0769.c8d4b9","type":"tab","label":"Flow 1","disabled":false,"info":""},{"id":"c868d6f4.243778","type":"inject","z":"14ba0769.c8d4b9","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":180,"y":100,"wires":[["d24cdb79.2bde48"]]},{"id":"d24cdb79.2bde48","type":"function","z":"14ba0769.c8d4b9","name":"array of numbers","func":"x = [1,2,3,4,3,2];\ny = [1,2,3,4,3,2];\n\nmsg.payload.x = x;\nmsg.payload.y = y;\nreturn msg;","outputs":1,"noerr":0,"x":340,"y":180,"wires":[["9177c1cb.2ea78","89aa1d59.7db5d"]]},{"id":"9177c1cb.2ea78","type":"regression","z":"14ba0769.c8d4b9","name":"","dataSetSize":0,"regressionType":"polynomial","polynomialOrder":"3","precision":"5","xInputField":"payload.x","xInputFieldType":"msg","yInputField":"payload.y","yInputFieldType":"msg","yOutputField":"payload.y","yOutputFieldType":"msg","functionOutputField":"Function","functionOutputFieldType":"msg","resultOnly":true,"x":500,"y":320,"wires":[["f4fdaf46.ac7d9"]]},{"id":"f4fdaf46.ac7d9","type":"debug","z":"14ba0769.c8d4b9","name":"","active":true,"tosidebar":false,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":680,"y":400,"wires":[]},{"id":"89aa1d59.7db5d","type":"debug","z":"14ba0769.c8d4b9","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":350,"y":380,"wires":[]}]

@josh51 I hope you don’t mind, but I did a quick edit of your post…
When putting Node-RED flows in, you must use the formatted text option in the editor other wise it mangles the flow and we cant import it.

I fixed it so we could import it and look at it.

No problem at all and my apologies for not importing it correctly.

You’re on the right track here! You just need to address a little quirk of JavaScript datatypes, and reformat the data set a little.

The reason the regression node is not producing output is because it never receives the arrays – if you check the debug node you’ll see that msg.payload is still the timestamp that is initially injected. This is an integer, which does not support properties like payload.x and payload.y unless you redefine it as an object.
No worries though, it’s an easy fix: msg.payload = {}; sets the payload to be a new, empty object. After doing this you’re free to set properties and you’ll see them appear in the debug.

With that fixed, the data just needs to be formatted in a way that the regression node expects. The node info tab says that if x and y properties both contain values, then those values are saved as a point into the data set. The key here is that singluar “a point” – this means that both properties are only used for streaming in a data set one point at a time.
In order to put a whole data set in at once, use JUST the x input property, where you have each element be part of your [x,y] data set.

To see what they’re talking about, check out this flow below, it can use either the numbers you set in the function node, or read injected values directly. Also note that it will produce a straight line due to [3,3] and [2,2] being duplicate data in this set.

[{"id":"58e64c95.45b774","type":"tab","label":"Regression","disabled":false,"info":""},{"id":"336398a4.3c51c8","type":"function","z":"58e64c95.45b774","name":"array of numbers","func":"x =[[1,1],\n    [2,2],\n    [3,3],\n    [4,4],\n    [3,3],\n    [2,2]];\n\nmsg.payload = {}; \nmsg.payload.x = x;\n\nreturn msg;","outputs":1,"noerr":0,"x":330,"y":180,"wires":[["2c840963.7faf96","2044a945.c20b16"]]},{"id":"aeb1c6d5.357c18","type":"inject","z":"58e64c95.45b774","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":140,"y":180,"wires":[["336398a4.3c51c8"]]},{"id":"2c840963.7faf96","type":"regression","z":"58e64c95.45b774","name":"","dataSetSize":0,"regressionType":"polynomial","polynomialOrder":"3","precision":"5","xInputField":"payload.x","xInputFieldType":"msg","yInputField":"payload.y","yInputFieldType":"msg","yOutputField":"payload.y","yOutputFieldType":"msg","functionOutputField":"Function","functionOutputFieldType":"msg","resultOnly":false,"x":570,"y":180,"wires":[["64615ed1.df8fd"]]},{"id":"2044a945.c20b16","type":"debug","z":"58e64c95.45b774","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":550,"y":240,"wires":[]},{"id":"64615ed1.df8fd","type":"debug","z":"58e64c95.45b774","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":730,"y":180,"wires":[]},{"id":"f9a5f8e9.e6e1f8","type":"inject","z":"58e64c95.45b774","name":"","topic":"","payload":"{\"x\":5}","payloadType":"json","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":370,"y":60,"wires":[["2c840963.7faf96"]]},{"id":"b552bb3c.3cc9a8","type":"inject","z":"58e64c95.45b774","name":"","topic":"","payload":"{\"x\":[[1,1],[2,2],[3,3],[4,4],[3,3],[2,2]]}","payloadType":"json","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":370,"y":120,"wires":[["2c840963.7faf96"]]},{"id":"9332529.30173b","type":"comment","z":"58e64c95.45b774","name":"inject enitre JSON array","info":"","x":180,"y":120,"wires":[]},{"id":"c542165c.909c08","type":"comment","z":"58e64c95.45b774","name":"calculate point at x=5","info":"","x":183,"y":60,"wires":[]}]
1 Like

@torchard and @Beno

I have the flow pretty much written and am having issues with sending the data to the tables in the groov pr1. I am currently using node-red that is running on the opto 22 groov pr1 and sending it to the strategy on the same device. i get back a successful message in the body.message. My pac write to variables works no issues im only experiencing the issues with writing to tables. When i am watching the table it seems to write the whole table with 0. I have verified that my tag name is correct, i have tried changing the Value to Write from msg.x to msg.payload.x, and msg.payload.xx none of these seem to make a difference.

image

image

Quick answer, you need to make the PAC Control table ‘Public’. Specifically in your case, it needs to be read and write.
The PAC Nodes in Node-RED use the RESTful interface to send data… so you need to click the ‘Add’ button in the PAC Control Edit dialog and select read and write and then re-download your strategy.

Give that a go and lets know how you get on.

1 Like

@Beno

I actually tried that right after sending this message and it made no difference at all.

Huh, OK, that’s a little odd… so the quick answer was a no go… dig we must…

I next noticed that your PAC Write node configuration is set for ‘172.20.1.1’ rather than ‘localhost’.
Is Node-RED running the same PR1 as the PAC Strategy?

Edit. Duh, I just re-read your first post where you said as much.

yes they are running as the same strategy. the reason i am have it set as 172.20.1.1 is because i am also using node-red on my computer to send data to sql server. when i use localhost it errors out as my public script is set for use on my computer.

i want to also add this i am able to read data from the table to node-red and i am able to write data to individual variables. it is writing to the pac table as it writes over data in the table just inserts all 0 in every index.

Before node red sends data to both tables

After node red sends data to both tables

1 Like

@josh51 that seems like strange behavior – could you paste your flow here so I can take a closer look at the node configurations and try to track down what’s going on?