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.

Regards,
Csongor

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 q.id = p.id +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 r.id > p.id -- 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 r.id > p.id

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 ?

Craig

Hi,
Did you manage tonget this up and running. ?

Im looking at the same thing but uptime so simpler on the input. Spindle on for example.

Yes, I did. I made this for a friend, it is still running, but I don't think he is using it much. But seems to be working OK.

Thanks, yes all in or all out on this monitoring. You use the data or you dont.

Cheers

Here the idea was that if this method is reliable enough, it would give a precise count of how many parts have been machined in a shift. And I am not sure if that was ever tested properly. The 1 second resolution may be too course for such measurement.
My code also allowed more parts to be configured, but again just by looking at the runtime parts have to be sufficiently different (different in terms of how much time it takes to machine them) in order to correctly identify them.

Yes i was trying to do something similar but it was heating cycle and to count the cycles completed by using the peak temp but it was not completed as i couldnt figure out how to count the peak value as it kept bouncing on this.

Temps, pressures, vacuums ext all of interest to me for system understanding.

Yes, the next idea would have been to also measure peaks in current and also use that as a indicator for identifying parts. Like how many times the current peaks (e.g. like when the spindle spins up, and winds down). I am not aware of a logic to do that. I would need to somehow remove the higher frequency fluctuations from the readings to accuratly determine a significant peak in the the readings. And again the question is if the sampling frequency is adequate for something like this or not.

Yes, difficult. I couldnt find a good query to do this in influx or grafana either so i now just look at the graph in grafana and count the peaks. Luckily for me its a few hours per cycle plus my interest is maintenance so im just looking for consistancy in the cycle rather than how many so i know the machine is working well. I just eanted the availability for the production team.