Step codes, phases and the cross-check against HDTools
Monitoring is split up by step code: every code gets its own averaged spectrum, its own band values and its own reference. This document records where the code logic comes from, what has been verified about it and what remains open at the machine.
Why codes and not block numbers
A grinding cycle consists of phases that are different processes, not sections of the same process. In the simulator, roughing and spark-out differ by a factor of 4,4 in overall level. A spectrum averaged over the cycle is dominated by the longest phase and describes none of them.
The block number (prog.seq) would be the obvious anchor, but it is unsuitable: it changes several times within one phase and depends on program revisions. The step code is made for exactly this — it is the quantity that the cycle time analysis evaluates as well.
Where the codes come from
The part program writes them into a macro variable:
#[23628 + [[#10348 - 1] * 10]] = 999991 (T2X MIT_ABTRAG)
#[23629 + [[#10348 - 1] * 10]] = 999991 (TIME-SCHLEIFEN)
So a block of stride variables per station index, starting at base. This is configured under focas.markers; which slot is evaluated is set in codes.marker_slot. The whole marker range is read with one cnc_rdmacror2 call, regardless of the number of stations.
To check at the machine:
hdtrace probe --ip <internal IP>
The “Step codes” section shows which value is in which variable and how it is resolved. If the addresses are wrong, you see it there immediately.
The code logic — adopted, not reinvented
src/hdtrace/core/codes.py is a port of the code resolution from HDTools/plugins/04_taktzeit.py, which is itself a verified reconstruction of the VBA macro Dict_Daten / Daten_Erzeugen from Taktzeitanalyse.xlsm. The dictionary itself (src/hdtrace/data/taktzeit_dict.json) is an unaltered copy of HDTools/databases/taktzeit_dict.json.
What was adopted:
| Rule | Meaning |
|---|---|
typ < 2 | loading |
typ >= 3 | main time |
otherwise (typ == 2) | auxiliary time |
| range entries | from code_von up to but excluding code_bis, text with a running counter: 924001 → “E. Nr. 1” |
| Op/Afo default | 101–9090 without an entry of its own → Op-<n> Afo-<m>, type 3 |
999990 | is folded onto 999000 “approach” |
923000.xx | decodes to Op·100+Afo |
| not six digits | discarded |
999991–999994 | cycle type markers, not a step of their own |
There are no hard-coded code ranges for categories. The type comes entirely from the dictionary — which is why the totals agree with the Excel template (913020 “dressing circumference right” has type 3 and is therefore main time; 914001 “tool no. 1” has type 2 and is auxiliary time).
What the cross-check produced
tests/test_codes_gegen_hdtools.py loads the Qt-free analysis part of the HDTools plugin directly and compares both implementations across the whole code space: 900000–999999, the Op/Afo range 100–9099 and all 9801 decimal forms 923001.01–923099.99.
checked: 118808 resolved: 109702 deviations: 0
Resolved code, type, designation and category agree in every case. The test skips itself if HDTools is not present on the computer.
One deliberate deviation
“Dressing” is a colour in HDTools, but not a category that _kategorie_aus_typ ever returns — the dressing codes carry the ordinary types 2 and 3. Spectrally, however, a dressing stroke is a different machine state from a grinding stroke.
Solved as a flag alongside the category, not as a replacement for it: codes 913000–913099 get is_dressing = true, the category stays exactly what HDTools calculates. That keeps the time totals comparable while dressing remains separately identifiable.
Cycle boundary
Without a boundary there is no “one taught cycle”. The primary means are the cycle type markers 999991–999994, because the cycle time analysis uses the same ones. Machines whose program does not write them enter their own start codes in codes.cycle_start_codes.
If no boundary is detected, the interface says so explicitly and teaching produces no result, rather than putting out an arbitrary excerpt as a cycle.
Timestamp convention — to be checked at the machine
In _sub_org_filter, the cycle time analysis pairs the code of row i with the timestamp of row i+1. A code therefore applies from its own timestamp until the next one — it is a state, not an event. The macro variable is read the same way here.
The module docstring in HDTools puts this in one place as if the timestamp marked the end of the step. The code itself is unambiguous, and the Excel cross-check (loading and total time exact, main/auxiliary time to ~1 %) depends on the implementation, not on the docstring. Even so: a mix-up shifts every spectrum by exactly one phase. This is the first point to be confirmed at the machine — when in doubt, let hdtrace monitor run alongside and check whether the code change occurs before or after the audible start of cut.
Segmentation — three rules that carry the result
A block that runs across a code change is discarded. The control is polled at ~20 Hz, a block is ~85 ms long; a change therefore regularly falls in the middle of a block. Assigning it to either of the two phases mixes two processes into one spectrum, and afterwards that is no longer detectable. The counter is in the interface under “data stream”.
The step duration comes from the code time axis, not from the blocks. Otherwise every step would be up to one block too short — after all, the discarded block is missing at the end. What is measured is therefore what the control reported; the resolution is the polling period (so 50 ms at 20 Hz).
Segments shorter than codes.min_segment_s (default 0,3 s) are discarded. The same threshold and the same reason as “evaluate raw data from” in the cycle time analysis: below that you measure the transition, not the phase. The cycle markers drop out by themselves as a result.
Teaching and comparison
Two results arise, and they are averaged differently:
- Reference per code — averaged over all occurrences of that code, no matter where in the cycle. A code is a process; how often it runs per part changes nothing about how it ought to sound.
- Taught step sequence — averaged per position, with code, designation and category by majority decision. That is the same construction as
gemittelte_schrittein the cycle time analysis, so that the step chart drawn here and the one there describe the same thing.
What is averaged are powers, never amplitudes. Band values are RMS values, and those do not add up — their squares do. Averaging amplitudes would set every reference systematically too low.
The band definitions are stored in the reference file as well. If the bands in the configuration are changed afterwards, the interface reports it instead of silently comparing different frequency ranges with one another.
Graphical display after teaching
A single complete cycle is enough. The chart in the “cycle” area draws the taught step sequence:
- a proportional strip (what the cycle time is spent on),
- one bar per step with its duration, coloured by category (main time blue, auxiliary time orange, loading green, dressing red — the same colours as in the step chart of the cycle time analysis),
- the current pass as an outline over the taught bar, so that a step running too long becomes visible as an overhang,
- clicking a step switches the spectrum and band table to that code.
As long as nothing has been taught, the same chart shows the running cycle — the display does not depend on any hard-wired list of phases.
Example: the simulator
The simulator phases carry real codes from the dictionary, so that the same resolution, the same categorisation and the same cycle boundary are exercised as on a machine:
| Phase | Code | Designation | Category |
|---|---|---|---|
| Cycle start | 999991 | start grinding | marker (cycle boundary) |
| Approach/air grinding | 999000 | approach | auxiliary time |
| Roughing | 922002 | roughing | main time |
| Finishing | 922014 | circumference finishing | main time |
| Spark-out | 922001 | cylindrical grinding | main time |
| Retract | 999003 | retract | auxiliary time |
| Part change | 910000 | workpiece change | loading |
| Dressing (every 5th part) | 913020 | dressing circumference right | main time + dressing |
Spark-out has no code of its own in the manufacturer's dictionary and runs under the ordinary cylindrical grinding code — that is the normal case, and the reason why codes can be renamed during teaching.
Open at the hardware
- Timestamp convention (see above) — if wrong, it shifts every spectrum by one phase.
- Marker addresses.
base,stride,index_variableand the slot allocation are taken from the machine builder's programming, but have not been read back on a running control.hdtrace probeshows the raw and the resolved value side by side. - Achievable poll rate. It determines how accurate a step duration becomes. Measure it with
hdtrace monitor, then set the group dividers infocas.divisor_*. - Band limits. The chatter and bearing bands are taken from the simulator (chatter 760 Hz, bearing resonance 1400 Hz). At the machine they should be determined from a measurement in the good state.