Hi All,
I friend of mine asked me if I can help him to monitor his CNC shop. He has a few CNC machines and was wondering if it would be possible to tell how many parts the machine have produced.
I said, let's try monitoring the power consumption with a Shelly 3EM and see if we can make some routines in node-red that understands pattern.
Shelly 3EM is running, I get the data every 5 seconds. For now I store everything in Influx so I can start looking at the data easily in Grafana. I get voltage, current, power, power factor, energy used, and energy returned (when the spindle breaks, it actual regenerates power) for all 3 phases.
This is how a 3 hour window looks like:
Top graph is the total power consumption (sum of 3 phases) and the lower one is the 3 phases separately. I think the pattern is clearly visible. I thought maybe single phase and 3 phase components in the CNC will yield different pattern, but it does not appear that way.
This is zoomed into a roughly 15 minute window:
I highlighted the 4 parts that are machined in this period. One cycle is roughly 2 minutes long. I checked it against the CCTV recording for the same period .
Also, the 3 phases separately does not give me more information, so I think it is easier to go after the total consumption.
Btw, this is how the power factor looks like (added unit of percentage by accident, these are just numbers between 0 and 1):
Again, I don't see any significant data here that I would not be able to get from the power consumption.
I think I could do the following from the total power consumption:
- Tell when the machine is on or off: >1500W is on, <1500W is off. You can see the flatline on the first picture as the shift ended.
- Looks like the idle consumption of the machine is around 2.43kW (don't ask me why that high, I guess coolant pump, compressor, chip remover, etc.). So anything below 2.6kW and the machine is idle, in between making parts.
- And within each cycle it would be nice to count the peaks. Maybe the peaks above a certain power threshold?
The immediately goal would be to count the number or parts produced. Maybe alert on excess idle time, log start/stop times.
But it would be nice, if everything could be parameterized and by changing the parameter, the code could either tell which part is being made and/or the same code could be used to monitor other CNC machine that make different part.
I am thinking about structuring the flow like this:
- Data comes in from Shelly 3EM and the first function nodes detect the on/off events.
- If on, the data passes to a second function node that looks when the cycle starts. When the cycle is on, it collects the readings in contexts. When the cycle is over, it passes the collected data down.
- The first node counts the peaks, checks the cycle length and tries to match that to a part pattern.
I would store the config parameters in an object in flow so by duplicating the flow it can be reused for another machine.
Coding step 1 and 2 is easy, I am not sure if there is an elegant code to count peaks in an array. I know if I derive the data series I just need to look for zero transitions, but that sound more complicated. Or calculate the delta between adjacent values and when the delta changes from positive to negative, that is a peak.
Do you have any other thoughts? Would you do something different? Can you spot anything in the data that I did not see?
Any feedback appreciated.
Regards,
Csongor