Table of Contents

Class ToolHeightOffsetSyntax

Namespace
Hi.NcParsers.LogicSyntaxs
Assembly
HiMech.dll

Resolves ISO tool height offset (G43/G44/G49) to the effective offset value (mm) and composes the offset as a translation into the accumulated ProgramToMcTransform matrix.

RTCP modes (G43.4, TRAORI, M128) are handled by separate brand-specific syntaxes (e.g., G43p4RtcpSyntax).

public class ToolHeightOffsetSyntax : ISituNcSyntax, INcSyntax, IMakeXmlSource
Inheritance
ToolHeightOffsetSyntax
Implements
Inherited Members
Extension Methods

Examples

All cases below have no ToolOrientation section and no TiltTransform entry in the chain — the composed translation therefore lies along UnitZ (the identity tilt's AxialNormal), so mat4d_t.Trans = (0, 0, height_mm).

G43 H1 with a TestDeps.ToolOffset mapping offset 1 to 99.98 mm — full consume from Parsing.G43, positive sign on G43:

#BeforeBuild:
{ "Parsing": { "G43": { "H": "1" } } }
#AfterBuild:
{
  "ToolHeightCompensation": {
    "Offset_mm": 99.98, "Term": "G43", "OffsetId": 1
  },
  "ProgramToMcTransform": [
    {
      "Source": "ToolHeightCompensation",
      "Kind": "Static",
      "Mat4d": [1,0,0,0, 0,1,0,0, 0,0,1,0, 0,0,99.98,1]
    }
  ]
}
G49 cancel flag — writes a sentinel G49 section with Offset_mm = 0, OffsetId = 0, and composes an identity mat4d_t so any previously composed tool-height translation is reset: #BeforeBuild:
{ "Parsing": { "Flags": ["G49"] } }
#AfterBuild:
{
  "ToolHeightCompensation": {
    "Offset_mm": 0, "Term": "G49", "OffsetId": 0
  },
  "ProgramToMcTransform": [
    {
      "Source": "ToolHeightCompensation",
      "Kind": "Static",
      "Mat4d": [1,0,0,0, 0,1,0,0, 0,0,1,0, 0,0,0,1]
    }
  ]
}
No G43/G44/G49 on the current block but #Previous: carries an active G43 H1 — modal lookback inherits the term + offset id, re-queries the tool table, and re-composes the translation. The unrelated M03 flag survives because the consume path only triggers when an ISO term is on the current block: #Previous:
{
  "ToolHeightCompensation": {
    "Offset_mm": 99.98, "Term": "G43", "OffsetId": 1
  }
}
#BeforeBuild:
{ "Parsing": { "Flags": ["M03"] } }
#AfterBuild:
{
  "Parsing": { "Flags": ["M03"] },
  "ToolHeightCompensation": {
    "Offset_mm": 99.98, "Term": "G43", "OffsetId": 1
  },
  "ProgramToMcTransform": [
    {
      "Source": "ToolHeightCompensation",
      "Kind": "Static",
      "Mat4d": [1,0,0,0, 0,1,0,0, 0,0,1,0, 0,0,99.98,1]
    }
  ]
}
G44 H1 with the same TestDeps.ToolOffset offset-1 → 99.98 mm — G44 negates the table value, so Offset_mm = -99.98 and the composed translation lies along -UnitZ. The X/Y components of toolOrientation * -99.98 land on IEEE-754 negative zero (0 * -99.98 = -0.0), which System.Text.Json emits literally as -0: #BeforeBuild:
{ "Parsing": { "G44": { "H": "1" } } }
#AfterBuild:
{
  "ToolHeightCompensation": {
    "Offset_mm": -99.98, "Term": "G44", "OffsetId": 1
  },
  "ProgramToMcTransform": [
    {
      "Source": "ToolHeightCompensation",
      "Kind": "Static",
      "Mat4d": [1,0,0,0, 0,1,0,0, 0,0,1,0, -0,-0,-99.98,1]
    }
  ]
}
G43 with no H word (G43 Z50.) on a block whose ToolChange section says tool 2 has just been loaded, after a #Previous: G49 whose sentinel still holds the modal H 1. H is modal on Fanuc: a bare G43 re-selects the last H written, the tool number never enters, and the control checks nothing — so the compensation is row 1's 99.98 mm, not tool 2's. (The H / T agreement check, on unless a ToolOffsetAgreementCheck on the runner turns it off, reports the disagreement as a warning; the JSON is unaffected.) A bare G43 arrives as a flag (no parameter object to hang an H on) and is consumed: #Previous:
{
  "ToolHeightCompensation": {
    "Offset_mm": 0, "Term": "G49", "OffsetId": 0, "ModalOffsetId": 1
  }
}
#BeforeBuild:
{
  "Parsing": { "Flags": ["G43"] },
  "ToolChange": { "ToolId": 2, "IsChange": true, "Term": "M06" }
}
#AfterBuild:
{
  "ToolChange": { "ToolId": 2, "IsChange": true, "Term": "M06" },
  "ToolHeightCompensation": {
    "Offset_mm": 99.98, "Term": "G43", "OffsetId": 1
  },
  "ProgramToMcTransform": [
    {
      "Source": "ToolHeightCompensation",
      "Kind": "Static",
      "Mat4d": [1,0,0,0, 0,1,0,0, 0,0,1,0, 0,0,99.98,1]
    }
  ]
}
The first block after a program end — #Previous: carries the ProgramEnd section next to the still-active G43 H1. This is the reset edge (ProgramEndSyntax): the controller's reset cancels tool length compensation, so the modal is not carried and the block gets the same G49 sentinel and identity mat4d_t an explicit G49 writes — with no ModalOffsetId, the reset clears the H number as well; the unrelated G00 flag survives: #Previous:
{
  "ProgramEnd": { "Term": "M30" },
  "ToolHeightCompensation": {
    "Offset_mm": 99.98, "Term": "G43", "OffsetId": 1
  }
}
#BeforeBuild:
{ "Parsing": { "Flags": ["G00"] } }
#AfterBuild:
{
  "Parsing": { "Flags": ["G00"] },
  "ToolHeightCompensation": {
    "Offset_mm": 0, "Term": "G49", "OffsetId": 0
  },
  "ProgramToMcTransform": [
    {
      "Source": "ToolHeightCompensation",
      "Kind": "Static",
      "Mat4d": [1,0,0,0, 0,1,0,0, 0,0,1,0, 0,0,0,1]
    }
  ]
}
An explicit G49 while G43 H1 is active — the compensation is cancelled (zero sentinel, identity mat4d_t) but the H number stays modal on Fanuc, so the sentinel records it as ModalOffsetId for a later bare G43 (the fifth example) to pick up: #Previous:
{
  "ToolHeightCompensation": {
    "Offset_mm": 99.98, "Term": "G43", "OffsetId": 1
  }
}
#BeforeBuild:
{ "Parsing": { "Flags": ["G49"] } }
#AfterBuild:
{
  "ToolHeightCompensation": {
    "Offset_mm": 0, "Term": "G49", "OffsetId": 0, "ModalOffsetId": 1
  },
  "ProgramToMcTransform": [
    {
      "Source": "ToolHeightCompensation",
      "Kind": "Static",
      "Mat4d": [1,0,0,0, 0,1,0,0, 0,0,1,0, 0,0,0,1]
    }
  ]
}

Remarks

Input data locations in JsonObject:

  • Parsing.G43 / Parsing.G44 → from ParameterizedFlagSyntax, {"H": "5"}
  • Parsing.H → from IntegerTagSetupSyntax, standalone modal H (int)
  • Parsing.Flags → from NumberedFlagSyntax, "G49" for cancellation, and a bare "G43" / "G44" whose H is omitted (the modal H applies — see the fifth example)
  • ToolOrientation → from a prior syntax (optional, default = Transformation.AxialNormal or UnitZ)
Modal state is persisted in the IToolHeightCompensationDef section (not syntax fields) and recovered from backward node traversal.

Constructors

ToolHeightOffsetSyntax()

Initializes a new instance with default settings.

public ToolHeightOffsetSyntax()

ToolHeightOffsetSyntax(XElement)

Initializes a new instance by deserializing from the given XML element.

public ToolHeightOffsetSyntax(XElement src)

Parameters

src XElement

Source XML element.

Fields

ToolOrientationKey

JSON key under which the upstream tool orientation vector is read.

public const string ToolOrientationKey = "ToolOrientation"

Field Value

string

TransformSource

Identifier used as the transform source key when composing the tool-height translation into ProgramToMcTransform.

public const string TransformSource = "ToolHeightCompensation"

Field Value

string

Properties

Name

Syntax kind name (typically the concrete type name).

public string Name { get; }

Property Value

string

XName

XML element name used to register this syntax with XFactory.

public static string XName { get; }

Property Value

string

Methods

Build(LazyLinkedListNode<SyntaxPiece>, List<INcDependency>, NcDiagnosticProgress)

Build syntax arrangement into the syntaxPieceNode in-place.

public void Build(LazyLinkedListNode<SyntaxPiece> syntaxPieceNode, List<INcDependency> ncDependencyList, NcDiagnosticProgress ncDiagnosticProgress)

Parameters

syntaxPieceNode LazyLinkedListNode<SyntaxPiece>
ncDependencyList List<INcDependency>
ncDiagnosticProgress NcDiagnosticProgress

MakeXmlSource(string, string, bool)

Creates an XML representation of the object. This method may also generate additional resources such as related files.

public XElement MakeXmlSource(string baseDirectory, string relFile, bool exhibitionOnly)

Parameters

baseDirectory string

The base directory for resolving relative paths

relFile string

The relative file path for the XML source

exhibitionOnly bool

if true, the extended file creation is suppressed.

Returns

XElement

An XML element representing the object's state

Remarks

For the demand of easy moving source folder (especially project folder) without configuration file path corruption, the relative file path is applied. The baseDirectory is typically the folder at the nearest configuration file folder. Since the folder can be moving with the configuration file.

Reg(XFactory)

Registers this type's deserializer with the given XFactory (or Default when factory is null). Idempotent.

public static void Reg(XFactory factory = null)

Parameters

factory XFactory