Monitor CNC machine production

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 :slight_smile: .

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:

  1. Data comes in from Shelly 3EM and the first function nodes detect the on/off events.
  2. 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.
  3. 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.


1 Like

It looks like you can identify the completion of a part by a peak above 5.5kW followed within about 20s by a value below 3kW.

If you had an sql database you could count them by something like

select count(*) from power_readings p, power_readings q
where p.consumption > 5.5          -- A high value
and = +1                 -- The next reading ...
and q.consumption < p.consumption  -- ... has a lower consumption (ie it's past the peak)
and exists (select id from power_readings r where time_to_sec(timediff(r.timestamp, p.timestamp)) > 20)
                   and > -- ensure the low point is after thepeak
                   and r.consumption < 3)  -- There is a low value within 20 seconds

Edit - in the cold light of dawn I realised my SQL needs one more AND clause >

Presumably you could do something similar with Influx?

Thanks, it is a very interesting SQL query. I never though about selecting different records from the same table like this.

You seem to only get two readings for an average peak in consumption, which is barely enough.
I wonder if your first graph shows an instance at around 20:34 where you missed the peak and perhaps at 20:07 you happened to catch just one very short term spike.

Is it possible to process readings more frequently? That might help with identifying the fingerprint of a particular part too.

If you have got CCTV access could you not do something with machine learning from the Camera feed to identify the start and stop of a cycle.

Not having done much with CNC - but there is usually a "Go Home" routine at the end a production run where the cutter/laser is moved to its resting location prior to starting on the next run ?