This repository has been archived on 2026-10-11. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
HiNC-2025-win-desktop-Deploy/App/wwwroot/HiAPI-docsite/release-note/upgrading-to-3.2/nc-optimization-and-writeback.html
T
2026-09-13 19:45:24 +08:00

221 lines
16 KiB
HTML

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>NC optimization and writeback | HiAPI-C# 2025 </title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="title" content="NC optimization and writeback | HiAPI-C# 2025 ">
<link rel="icon" href="../../img/HiAPI.favicon.ico">
<link rel="stylesheet" href="../../public/docfx.min.css">
<link rel="stylesheet" href="../../public/main.css">
<meta name="docfx:navrel" content="../../toc.html">
<meta name="docfx:tocrel" content="toc.html">
<meta name="docfx:rel" content="../../">
<meta name="loc:inThisArticle" content="In this article">
<meta name="loc:searchResultsCount" content="{count} results for &quot;{query}&quot;">
<meta name="loc:searchNoResults" content="No results for &quot;{query}&quot;">
<meta name="loc:tocFilter" content="Filter by title">
<meta name="loc:nextArticle" content="Next">
<meta name="loc:prevArticle" content="Previous">
<meta name="loc:themeLight" content="Light">
<meta name="loc:themeDark" content="Dark">
<meta name="loc:themeAuto" content="Auto">
<meta name="loc:changeTheme" content="Change theme">
<meta name="loc:copy" content="Copy">
<meta name="loc:downloadPdf" content="Download PDF">
<script type="module" src="./../../public/docfx.min.js"></script>
<script>
const theme = localStorage.getItem('theme') || 'auto'
document.documentElement.setAttribute('data-bs-theme', theme === 'auto' ? (window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light') : theme)
</script>
</head>
<body class="tex2jax_ignore" data-layout="" data-yaml-mime="">
<header class="bg-body border-bottom">
<nav id="autocollapse" class="navbar navbar-expand-md" role="navigation">
<div class="container-xxl flex-nowrap">
<a class="navbar-brand" href="../../index.html">
<img id="logo" class="svg" src="../../img/HiAPI.logo.png" alt="">
</a>
<button class="btn btn-lg d-md-none border-0" type="button" data-bs-toggle="collapse" data-bs-target="#navpanel" aria-controls="navpanel" aria-expanded="false" aria-label="Toggle navigation">
<i class="bi bi-three-dots"></i>
</button>
<div class="collapse navbar-collapse" id="navpanel">
<div id="navbar">
<form class="search" role="search" id="search">
<i class="bi bi-search"></i>
<input class="form-control" id="search-query" type="search" disabled placeholder="Search" autocomplete="off" aria-label="Search">
</form>
</div>
</div>
</div>
</nav>
</header>
<main class="container-xxl">
<div class="toc-offcanvas">
<div class="offcanvas-md offcanvas-start" tabindex="-1" id="tocOffcanvas" aria-labelledby="tocOffcanvasLabel">
<div class="offcanvas-header">
<h5 class="offcanvas-title" id="tocOffcanvasLabel">Table of Contents</h5>
<button type="button" class="btn-close" data-bs-dismiss="offcanvas" data-bs-target="#tocOffcanvas" aria-label="Close"></button>
</div>
<div class="offcanvas-body">
<nav class="toc" id="toc"></nav>
</div>
</div>
</div>
<div class="content">
<div class="actionbar">
<button class="btn btn-lg border-0 d-md-none" type="button" data-bs-toggle="offcanvas" data-bs-target="#tocOffcanvas" aria-controls="tocOffcanvas" aria-expanded="false" aria-label="Show table of contents">
<i class="bi bi-list"></i>
</button>
<nav id="breadcrumb"></nav>
</div>
<article data-uid="Release-Upgrading-NcOptimization">
<h1 id="nc-optimization-and-writeback">NC optimization and writeback</h1>
<div class="IMPORTANT">
<h5>Important</h5>
<p><strong>NC optimization is not finished on the 3.2 line.</strong> What follows describes the leg as it stands,
and it is published for review, not for production. Work that depends on optimized output should
stay on the 3.1 line, serviced as <code>3.1.175.&lt;patch&gt;</code>.</p>
</div>
<ul>
<li><strong>The optimizer runs on the SoftNc pipeline by default.</strong>
<a class="xref" href="../../api/Hi.MachiningProcs.SessionShell.html#Hi_MachiningProcs_SessionShell_OptimizeToFiles_">OptimizeToFiles</a> keeps its signature, its script snippet and
its HTTP route, but when <a class="xref" href="../../api/Hi.MachiningProcs.LocalProjectService.html#Hi_MachiningProcs_LocalProjectService_EnableSoftNcRunner">EnableSoftNcRunner</a> is on and
the session holds played <a class="xref" href="../../api/Hi.MachiningProcs.NcRunnerSessionState.html#Hi_MachiningProcs_NcRunnerSessionState_SyntaxPieceLayers">SyntaxPieceLayers</a>, it
delegates to the new <a class="xref" href="../../api/Hi.MachiningProcs.MachiningSession.html#Hi_MachiningProcs_MachiningSession_OptimizeNcFiles_">OptimizeNcFiles</a>; otherwise the frozen
HardNc path runs unchanged. The new leg classifies the final
<a class="xref" href="../../api/Hi.NcParsers.Syntaxs.SyntaxPiece.html">SyntaxPiece</a> layer, solves the per-step feed adjustments from milling
physics, and regenerates text as anchored token edits over the verbatim source block — <strong>lines the
optimizer does not touch round-trip byte-identically</strong> instead of being re-synthesized. Per-file
results are retained in <a class="xref" href="../../api/Hi.MachiningProcs.MachiningSession.html#Hi_MachiningProcs_MachiningSession_NcOptimizations">NcOptimizations</a>.
<a class="xref" href="../../api/Hi.MachiningProcs.SessionShell.html#Hi_MachiningProcs_SessionShell_EnableIndividualStepAdjustmentLog">EnableIndividualStepAdjustmentLog</a> drives both legs.</li>
<li><strong>Depth splition re-interpolates through a planned fragment path</strong>, with separate modal chains for
the pre-build feed and the emission endpoint, per-step machine-to-program-frame inversion, and
per-fragment arc IJK recomputation — including R-to-IJK conversion — wherever the arc block itself
carries the centre. An arc whose centre lives on a preceding modal block is exempt: its fragments
keep the source block's arc words and share that upstream centre line unchanged, so only their
endpoint and <code>F</code> words move. Two cases where the frozen HardNc optimizer is silently wrong are
downgraded to a non-split rewrite rather than reproduced, each warned once per run. The first is
an incremental block, and it is now taken by both of its spellings: <code>G91</code> modal state, <strong>or</strong> a
block whose modal state is absolute while individual axis words carry a per-word incremental
override — Siemens <code>X=IC(10)</code> and the coded <code>CIC()</code>, klartext <code>IX+20</code> and <code>IC+90</code>. The frozen
fragment rewrite carries no <code>G90</code>/<code>G91</code> handling at all and always re-emits a coordinate as an
absolute program value, so it splits both shapes and is wrong on each in its own way: the <code>G91</code>
line comes back stating an absolute number the control still reads as a distance, and the
per-word line keeps its incremental source word, so every fragment re-applies the same distance
from its own start. Both now stop at <code>NcOpt--SplitionIncrementalUnsupported</code>. The per-word
spelling is also the only one that can reach klartext: that dialect has no modal <code>G90</code>/<code>G91</code>
word, so a stamped axis word is the only incremental form it produces. The second case is a
klartext <code>C … DR±</code> arc whose modal <code>CC</code> chain left one of the two in-plane axes unstated, so the
block's own start point supplied that component — since every fragment would re-derive the centre
from its own start; that one reports <code>NcOpt--SplitionStartPointCenterUnsupported</code>. A klartext
<code>C</code> block whose centre lands entirely on its own start point never reaches that guard: its radius
is zero, so play degrades it to a chord under a validation warning of its own.
<strong>Neither the controller brand nor klartext as such refuses a split</strong>: a klartext <code>L</code> block
re-interpolates like an ISO one.</li>
<li><strong>The compensation stage is no longer dead on the SoftNc leg.</strong> The HardNc baseline wrote the
compensation into the step contexts while its output read the piece packs, so it never emitted a
compensated coordinate at all. Each fragment endpoint is now offset — XYZ only, rotary words
untouched — by the tool-tip deflection rotated into the leaf program frame the endpoint lives in, so
a G68.2 tilted setup is compensated in the right direction. It is consumed on re-interpolated
splition fragments only, and <a class="xref" href="../../api/Hi.NcOpt.NcOptOption.html#Hi_NcOpt_NcOptOption_CompensationMask">CompensationMask</a> defaults to 0, so with no
mask set the stage is a strict no-op.</li>
<li><strong>Output follows the source's decimal digits.</strong> Both legs used to write coordinates through a fixed
<code>F4</code> and every F word through <code>F2</code>, so a program stated to three decimals could come back with a
fourth — an alarm on controllers strict about their least input increment. Digit counts are now
scanned per word family over the played source texts with comment spans masked, floored at 3/3/0 and
capped at 9, and threaded through the whole write path. The word-suppression tolerances and the F
comparison grid derive from the resolved digits instead of the old fixed literals.</li>
<li><strong>Leading zeros follow the source, and the project can pin the spelling.</strong>
<a class="xref" href="../../api/Hi.NcOpt.NcOptOption.html#Hi_NcOpt_NcOptOption_OmitLeadingZero">OmitLeadingZero</a> is an output style: on, the writer drops a leading
zero before the decimal (<code>.5</code> rather than <code>0.5</code>); off, it writes the zero. The option is carried on
the project so two machines produce the same bytes, and a report names which style the source
itself used.</li>
<li><strong>Optimized NC is written back in the source file's encoding.</strong> NC play reads and optimized writes go
through <a class="xref" href="../../api/Hi.Common.FileLines.FileUtil.html#Hi_Common_FileLines_FileUtil_DetectRoundTripEncoding_">DetectRoundTripEncoding</a> — BOM, then strict UTF-8, then
Latin-1 — so an ANSI-family file (GBK, Big5, Shift-JIS) re-encodes to its original bytes instead of
having every undecodable byte replaced. Comments in those encodings survive the round trip.</li>
<li><strong>A feed change no longer mints a one-step carrier fragment.</strong> Under an arc split that fragment is a
degenerate arc whose start and end nearly coincide, which an incremental-IJK reader — or a control
that treats begin == end as a full turn — expands into a full circle. An <code>F</code> re-statement is now
handed to the feed run's next emitted fragment, the one that actually runs at that feed.</li>
<li><strong>A splition fragment at the head of the stream writes only the axis words the source stated</strong>, so it
can no longer invent a <code>Z0.</code> whose value under the source's silence is just the home-fallback modal.</li>
<li><strong>Unparsable NC lines survive.</strong> A line the parser could not read used to be dropped from the runner's
line list, so the optimized file silently lost it. <code>HardNcRunner</code> now rebuilds a parse-failed line as
an opaque no-op — the empty-text parse inherits modal state like a blank line, and the raw text is
restored for writers — and the optimizer mirrors the fallback, so <code>IF</code> blocks, <code>#</code>-variable macros,
<code>G68 R#</code> and <code>GOTO</code> come through verbatim. A <code>BuildNcLines--ParseFailed</code> diagnostic still reports the
line, and the line stays un-simulated. The output writer is also closed in a <code>finally</code>, so an
exception can no longer leave a half-written file locked. First delivered on the 3.1.175.x service
line.</li>
<li><strong>A Siemens <code>CYCLE800</code> swivel counts as a macro line</strong> in the piece classifier, so it is preserved
rather than treated as an optimizable motion block.</li>
<li><strong>The host key <code>HiNC:OptCoreNum</code> governs both legs again.</strong> It used to set only the legacy
<code>NcOptProc.CoreNum</code>; once the SoftNc optimizer became the default path the key silently stopped
governing anything. It now assigns both (0 = derive from the processor count).</li>
<li><strong>NC text writeback</strong> regenerates NC from a program that has already been played, in two stages over
the session's finished syntax pieces: a converter turns the source piece stream into a destination
stream plus a bidirectional source↔destination map keyed by sentence index, and a reverse segmenter
serializes that stream back to lines. The data→text seam is a brand-agnostic sentence composer, first
implemented for Fanuc. A patch-mode writer performs positional token edits — <code>NaN</code> deletes a word
absorbing one separator space, insertion follows conventional order, trailing zeros trim keeping the
dot — and refuses to rewrite variable, bracket and keyword values rather than corrupting them,
reporting <code>Writeback-Patch--VariableValue</code>, <code>--KeywordValue</code>, <code>--CommentOnlyText</code> and
<code>--EditUnmatched</code>. <strong>Five of its choices follow the dialect rather than the convention</strong>: the
variable prefix it recognizes and refuses (<code>Q</code> on klartext, <code>R</code> on Siemens, <code>#</code> elsewhere), the
keyword feed values it refuses (klartext's <code>FMAX</code> and <code>FAUTO</code>), the comment spans it protects
(klartext's <code>;</code> and <code>//</code> as well as the parenthesized span), and two that show in the written
text. On a klartext file an inserted <code>F</code> lands after the rightmost of <code>DR+</code>/<code>DR-</code> and
<code>RL</code>/<code>RR</code>/<code>R0</code> as well as after its conventional predecessor coordinate words, so the patched
block keeps the element order a TNC enforces — coordinates, rotation direction, radius
compensation, <code>F</code>, <code>M</code>. And a trailing comment is wrapped in the file's own grammar, the Fanuc
family's <code>(text)</code> against klartext's <code>;text</code>, so the optimizer's embedded source note leaves a
klartext program valid instead of handing a control a parenthesis it would read as code.</li>
<li><strong>A second diagnostic home.</strong> <a class="xref" href="../../api/Hi.MachiningSteps.IMachiningService.html#Hi_MachiningSteps_IMachiningService_NcManipulationDiagnosticProgress">NcManipulationDiagnosticProgress</a>
is a sibling of the play-time <code>NcDiagnosticProgress</code>, dedicated to NC-rework operations — writeback
conversion and optimization — so a play reset never discards manipulation results and vice versa.</li>
</ul>
</article>
<div class="contribution d-print-none">
</div>
<div class="next-article d-print-none border-top" id="nextArticle"></div>
</div>
<div class="affix">
<nav id="affix"></nav>
</div>
</main>
<div class="container-xxl search-results" id="search-results"></div>
<footer class="border-top text-secondary">
<div class="container-xxl">
<div class="flex-fill">
<span> Copyright © 2025 <a href='https://superhightech.com.tw'>Tech Coordinate</a>. All rights reserved. <a href='https://superhightech.com.tw'>超級高科技股份有限公司</a> © 2025 版權所有 </span>
</div>
</div>
</footer>
</body>
</html>