Värvisegu suhe läks paigast ära märkamatult: kuidas Grafana selle nähtavaks tegi
A paint mixing ratio drifted unnoticed — how Grafana made it visible
Viimistlusliinil segatakse kahekomponendilist värvi retsepti järgi: põhivärv ja kõvendi. Kui suhe hakkab aeglaselt nihkuma, ei märka seda keegi enne, kui kvaliteediga tekib mure. Robotite tegelikest doseeringutest tehtud graafik näitab nihet palju varem.
On a finishing line, two-component paint — base and hardener — is mixed by recipe. When the ratio starts to drift slowly, nobody notices until quality suffers. A chart of the robots’ actual dosed amounts shows the drift much earlier.
Probleem
The problem
Doseerimine on automaatne ja retsept on paigas, nii et kõik eeldavad, et suhe on õige. Tegelikkuses mõjutavad seda pumbad, voolikud, temperatuur ja materjali viskoossus. Väike nihe ei torka ühelgi päeval silma, aga nädalatega see koguneb.
Dosing is automatic and the recipe is set, so everyone assumes the ratio is right. In reality pumps, hoses, temperature and material viscosity all affect it. A small drift never stands out on any single day, but it adds up over weeks.
Lahendus: üks kitsas tabel ja üks graafik
The fix: one narrow table and one chart
Täismahulist MES-i (tootmise juhtimissüsteemi) polnud vaja. Piisas väikesest kogujast, mis loeb robotite tegelikud doseeringud ja kirjutab need PostgreSQL-i, ning Grafanast, mis joonistab suhte koos retsepti sihi ja tolerantsiribaga.
No full MES was needed. A small collector reads the robots’ actual dosed amounts into PostgreSQL, and Grafana plots the ratio together with the recipe target and tolerance band.
Ilma sihi ja tolerantsita on number graafikul lihtsalt number.
A number without a target on the same chart is just a number.
Andmemudel: kitsas tabel võidab laia
Data model: narrow beats wide
Üks rida iga väärtuse kohta: aeg, liin, seade, signaal, väärtus. Uus andur või masin ei nõua skeemi muutmist. Lai tabel, kus iga andur on eraldi veerg, läheb katki iga kord, kui liin muutub.
One row per value: time, line, device, signal, value. A new sensor or machine needs no schema change. A wide table with one column per sensor breaks every time the line changes.
- lisa reale retsept ja tellimus, siis saab hiljem küsida, kas nihe on seotud ühe retseptiga;
- pane ühik signaali nimesse:
temp_c,base_g,speed_m_min. Ühikute segadus on kõige levinum analüüsiviga; - andmebaasis UTC, Grafanas kohalik aeg;
- Grafanale ainult lugemisõigusega kasutaja.
- put recipe and order number on the row, so you can later ask whether the drift is tied to one recipe;
- name signals with units:
temp_c,base_g,speed_m_min. Unit confusion is the most common analysis error; - UTC in the database, local time in Grafana;
- a read-only database user for Grafana.
-- segusuhe roboti kaupa vs retsepti siht ja tolerants (Grafana, PostgreSQL)
WITH dosed AS (
SELECT date_trunc('minute', ts) AS t, device, recipe,
sum(value) FILTER (WHERE signal = 'base_g') AS base_g,
sum(value) FILTER (WHERE signal = 'hardener_g') AS hardener_g
FROM measurement
WHERE $__timeFilter(ts) AND signal IN ('base_g', 'hardener_g')
GROUP BY 1, 2, 3
)
SELECT d.t AS time, d.device,
d.hardener_g / NULLIF(d.base_g, 0) AS ratio,
r.target_ratio - r.tolerance AS lower_limit,
r.target_ratio + r.tolerance AS upper_limit
FROM dosed d JOIN recipe_target r USING (recipe)
ORDER BY 1;
-- mixing ratio per robot vs recipe target and tolerance (Grafana, PostgreSQL)
WITH dosed AS (
SELECT date_trunc('minute', ts) AS t, device, recipe,
sum(value) FILTER (WHERE signal = 'base_g') AS base_g,
sum(value) FILTER (WHERE signal = 'hardener_g') AS hardener_g
FROM measurement
WHERE $__timeFilter(ts) AND signal IN ('base_g', 'hardener_g')
GROUP BY 1, 2, 3
)
SELECT d.t AS time, d.device,
d.hardener_g / NULLIF(d.base_g, 0) AS ratio,
r.target_ratio - r.tolerance AS lower_limit,
r.target_ratio + r.tolerance AS upper_limit
FROM dosed d JOIN recipe_target r USING (recipe)
ORDER BY 1;
Kogumine
Collection
- loe nii tihti, kui protsess muutub, mitte nii tihti, kui PLC lubab. Enamikule liini signaalidele piisab 1–10 sekundist, sündmused (start, stopp, alarm) logi muutuse hetkel;
- puhverda kohapeal, kui andmebaas pole kättesaadav. Tootmisandmed ei tohi võrgukatkestuse tõttu kaduma minna;
- eelista MQTT-d või OPC UA-d. Otsesed TCP-ühendused töötavad, aga taasühendumisel on need hapramad;
- koguja ainult loeb masinast. Seadeväärtuste tagasi kirjutamine on teine projekt ja teise riskiga.
- sample at the rate the process changes, not the rate the PLC allows. Most line signals are fine at 1–10 s; log events (start, stop, alarm) on change;
- buffer locally when the database is unreachable. Production data must not be lost because of a network hiccup;
- prefer MQTT or OPC UA. Raw TCP socket integrations work but are more fragile on reconnects;
- the collector is read-only towards the machine. Writing setpoints back is a different project with different risk.
Õppetunnid
Lessons
- Üks dashboard ühe küsimuse kohta, mitte ühe masina kohta. „Kas suhe on stabiilne?“ on parem kui „Robot 1 ülevaade“.
- Häired ainult asjadele, millele keegi reageerib, tööajal ja liini omanikule.
- Arvestid nullivad end (näiteks PLC taaskäivitusel) ja tekitavad negatiivseid vahesid. Arvesta sellega päringus.
- Taasühenduv koguja võib tekitada topeltajatempleid. Lisa unikaalsuse piirang või eemalda duplikaadid päringus.
- OEE puhul alusta kättesaadavusest ühe
running-signaali põhjal. Seda on kõige lihtsam saada ja see on tavaliselt ka suurim kadu.
- One dashboard per question, not per machine. “Is the ratio stable?” beats “Robot 1 overview”.
- Alert only on things someone will act on, during working hours, routed to the line owner.
- Counters reset (e.g. on a PLC restart) and create negative deltas. Handle resets in the query.
- Reconnecting collectors can create duplicate timestamps. Add a unique constraint or deduplicate in the query.
- For OEE, start with availability from a single
runningsignal. It is the easiest to get and usually the biggest loss.
Sarnane mure liinil?
A similar problem on your line?