Table of Contents

Class CircularMotionSyntax

Namespace
Hi.NcParsers.LogicSyntaxs
Assembly
HiMech.dll

Writes McArc motion for circular commands (ISO G02/G03). Detects motion mode from Flags, reads I/J/K center offsets or R radius from Parsing, computes arc center in program coordinates, and writes a one-shot MotionEvent (form + arc params) plus a modal MotionState (Term).

G02/G03 mode is modal (Group 01) — persists across blocks via Term. Arc parameters (I/J/K/R) are per-block and must be present in every arc block.

Must be placed before LinearMotionSyntax in the syntax chain. Both share the Group 01 motion slot; whichever writes a MotionEvent first claims it.

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

Examples

All cases below have the current block's ProgramXyz already set (as a prior ProgramXyzSyntax would have produced) and run with no #Previous:, so GetLastProgramXyz returns Vec3d.Zero. The G17 XY plane is implicit (no PlaneSelect section means GetPlaneNormalDir(JsonObject) returns 2 — the XY-plane default — so arc math runs with Z as the perpendicular axis).

G02 with I/J — quarter arc from (0,0,0) to (10,0,0) around (5,0,0); I=5 J=0 are incremental offsets from start to center. The G02 flag is consumed (Parsing removed once empty); MotionState + MotionEvent are written:

#BeforeBuild:
{
  "Parsing": { "Flags": ["G02"], "I": 5, "J": 0 },
  "ProgramXyz": { "X": 10, "Y": 0, "Z": 0 }
}
#AfterBuild:
{
  "ProgramXyz": { "X": 10, "Y": 0, "Z": 0 },
  "MotionState": { "Term": "G02" },
  "MotionEvent": {
    "Form": "McArc",
    "ArcCenter": { "X": 5, "Y": 0, "Z": 0 },
    "IsCcw": false,
    "AdditionalCircleNum": 0
  }
}
Modal carry of G02: no motion flag on the current block but a #Previous: MotionState.Term = "G02" tells us we are still in circular mode. I/J on the current block describe the arc the same way: #Previous:
{ "MotionState": { "Term": "G02" } }
#BeforeBuild:
{
  "Parsing": { "I": 5, "J": 0 },
  "ProgramXyz": { "X": 10, "Y": 0, "Z": 0 }
}
#AfterBuild:
{
  "ProgramXyz": { "X": 10, "Y": 0, "Z": 0 },
  "MotionState": { "Term": "G02" },
  "MotionEvent": {
    "Form": "McArc",
    "ArcCenter": { "X": 5, "Y": 0, "Z": 0 },
    "IsCcw": false,
    "AdditionalCircleNum": 0
  }
}
No I/J/K/R on the block — the per-block arc data is missing, so the syntax bails out early; the G02 flag stays in Parsing.Flags for some other syntax to act on (or to surface as residue if no one does): #BeforeBuild:
{
  "Parsing": { "Flags": ["G02"] },
  "ProgramXyz": { "X": 10, "Y": 0, "Z": 0 }
}
#AfterBuild:
{
  "Parsing": { "Flags": ["G02"] },
  "ProgramXyz": { "X": 10, "Y": 0, "Z": 0 }
}
R-format degenerate (chord = 2R, semicircle): start (0,0,0) → end (10,0,0), R=5. perpDistSq resolves to 0 so the computed center collapses to the chord midpoint (5,0,0); no sqrt drift on this branch: #BeforeBuild:
{
  "Parsing": { "Flags": ["G02"], "R": 5 },
  "ProgramXyz": { "X": 10, "Y": 0, "Z": 0 }
}
#AfterBuild:
{
  "ProgramXyz": { "X": 10, "Y": 0, "Z": 0 },
  "MotionState": { "Term": "G02" },
  "MotionEvent": {
    "Form": "McArc",
    "ArcCenter": { "X": 5, "Y": 0, "Z": 0 },
    "IsCcw": false,
    "AdditionalCircleNum": 0
  }
}
R-format non-trivial: G02 90° arc from (0,0,0) to (10,10,0) with R=10. The center comes from the cross-product + sqrt + normalize path inside ResolveCenterFromSignedRadius(Vec3d, Vec3d, int, bool, double), but for this particular axis-aligned chord the rounding errors cancel and the center lands at exactly (10, 0, 0) — i.e. no ULP drift here, in contrast to e.g. McAbcCyclicPathSyntax's rad/deg round-trip: #BeforeBuild:
{
  "Parsing": { "Flags": ["G02"], "R": 10 },
  "ProgramXyz": { "X": 10, "Y": 10, "Z": 0 }
}
#AfterBuild:
{
  "ProgramXyz": { "X": 10, "Y": 10, "Z": 0 },
  "MotionState": { "Term": "G02" },
  "MotionEvent": {
    "Form": "McArc",
    "ArcCenter": { "X": 10, "Y": 0, "Z": 0 },
    "IsCcw": false,
    "AdditionalCircleNum": 0
  }
}
G03 CCW with I/J — same geometry as case 0 (start (0,0,0), end (10,0,0), I=5 J=0 → center (5,0,0)) but the G03 flag flips IsCcw to true. Direction is the only differentiating output; arc-center math is unchanged: #BeforeBuild:
{
  "Parsing": { "Flags": ["G03"], "I": 5, "J": 0 },
  "ProgramXyz": { "X": 10, "Y": 0, "Z": 0 }
}
#AfterBuild:
{
  "ProgramXyz": { "X": 10, "Y": 0, "Z": 0 },
  "MotionState": { "Term": "G03" },
  "MotionEvent": {
    "Form": "McArc",
    "ArcCenter": { "X": 5, "Y": 0, "Z": 0 },
    "IsCcw": true,
    "AdditionalCircleNum": 0
  }
}
Full circle G02 — start == end (both (0,0,0)), I=5 J=0 places center off-start at (5,0,0). Plane-restricted closure (IsClosedOnPlane(Vec3d, Vec3d, int, double)) flips AdditionalCircleNum to 1 so a downstream motion semantic knows to draw the closed loop: #BeforeBuild:
{
  "Parsing": { "Flags": ["G02"], "I": 5, "J": 0 },
  "ProgramXyz": { "X": 0, "Y": 0, "Z": 0 }
}
#AfterBuild:
{
  "ProgramXyz": { "X": 0, "Y": 0, "Z": 0 },
  "MotionState": { "Term": "G02" },
  "MotionEvent": {
    "Form": "McArc",
    "ArcCenter": { "X": 5, "Y": 0, "Z": 0 },
    "IsCcw": false,
    "AdditionalCircleNum": 1
  }
}
Fanuc L parameter (helix turn count, 1-based) — L3 on a start==end closed loop means three total turns, so AdditionalCircleNum = L − 1 = 2. Matches legacy NcProc.cs:442; the L parameter is consumed alongside I/J/K/R: #BeforeBuild:
{
  "Parsing": { "Flags": ["G02"], "I": 5, "J": 0, "L": 3 },
  "ProgramXyz": { "X": 0, "Y": 0, "Z": 0 }
}
#AfterBuild:
{
  "ProgramXyz": { "X": 0, "Y": 0, "Z": 0 },
  "MotionState": { "Term": "G02" },
  "MotionEvent": {
    "Form": "McArc",
    "ArcCenter": { "X": 5, "Y": 0, "Z": 0 },
    "IsCcw": false,
    "AdditionalCircleNum": 2
  }
}
K-as-pitch helix on G17 (XY plane) — when the plane-normal axis letter (K for G17, J for G18, I for G19) is present on an IJK-format arc, it is the per-turn axial pitch, not a center offset. Here K = −3 mm/turn over ΔZ = −9 mm gives AdditionalCircleNum = floor(−9 / −3) = 3. The center stays on the begin-plane (Z = 0) — ResolveCenterFromIjk zeros the plane-normal component before adding to begin. Matches legacy NcProc.cs:458: #BeforeBuild:
{
  "Parsing": { "Flags": ["G02"], "I": 5, "J": 0, "K": -3 },
  "ProgramXyz": { "X": 0, "Y": 0, "Z": -9 }
}
#AfterBuild:
{
  "ProgramXyz": { "X": 0, "Y": 0, "Z": -9 },
  "MotionState": { "Term": "G02" },
  "MotionEvent": {
    "Form": "McArc",
    "ArcCenter": { "X": 5, "Y": 0, "Z": 0 },
    "IsCcw": false,
    "AdditionalCircleNum": 3
  }
}

Constructors

CircularMotionSyntax()

Initializes a new instance with default settings.

public CircularMotionSyntax()

CircularMotionSyntax(XElement)

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

public CircularMotionSyntax(XElement src)

Parameters

src XElement

Source XML element.

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