Class StepFeedSolver
Runner-agnostic per-step feed solver core of the NC optimization process: computes per-step feed adjustments from milling physics (force / yielding / spindle torque / spindle power / thermal yield / custom criteria and relief-face collision), constrains them over extended segments, propagates acceleration limits backward, and builds tool deflection compensation.
public class StepFeedSolver
- Inheritance
-
StepFeedSolver
- Inherited Members
- Extension Methods
Remarks
Ported from HiNc NcOptProc (frozen HardNc baseline,
HiNc/NcOpt/NcOptProc.cs): extension-window walkers (lines 144-206),
force/feed-per-tooth solver family (lines 207-561), feed boundaries
(lines 831-894), BuildStepAdjustment(ICuttingPara, Dictionary<int, StepOptContext>, List<MachiningStep>, IProgress<IMessage>, CancellationToken, KeyValuePair<int, StepOptContext>, StepAdjustmentLogger) (lines 895-1197),
ParallelBuildStepAdjustments(ICuttingPara, Dictionary<int, StepOptContext>, List<MachiningStep>, Func<string, string>, IProgress<IMessage>, CancellationToken) (lines 1198-1286),
ConstrainIndividualFeedrate(ICuttingPara, MachiningToolHouse, bool, List<INcOptPiecePack>, List<MachiningStep>, Dictionary<int, StepOptContext>, IProgress<IMessage>) (lines 1287-1441),
BuildCompensation(ICuttingPara, List<INcOptPiecePack>, List<MachiningStep>, SortedList<int, NcOptOption>, IProgress<IMessage>)
(lines 1449-1560) and the acceleration family (lines 1598-1786).
The two HardNc seams are parameterized: milling step luggage access is
injected via a Func<T, TResult> (was
SequentialBulkReader<MillingStepLuggage>.GetStep), and the
per-source-file log path derivation is injected via a
Func<T, TResult> (was the HardNcUtil
[NcFile]/[NcName] template constants).
Constructors
StepFeedSolver(Func<int, MillingStepLuggage>)
Ctor.
public StepFeedSolver(Func<int, MillingStepLuggage> getMillingStepLuggage)
Parameters
getMillingStepLuggageFunc<int, MillingStepLuggage>Maps a step index to its MillingStepLuggage. Must be thread safe: it is called from parallel workers.
Properties
CoreNum
Parallel computation thread num.
0 is special number to use all cores.
Wired from the HiNC:OptCoreNum configuration by
HiNcRclUtil alongside the legacy HardNc
NcOptProc.CoreNum.
public static int CoreNum { get; set; }
Property Value
EnableStepAdjustmentLog
Enable create log file for building individual StepAdjustment process.
Wired by the SessionShell.EnableIndividualStepAdjustmentLog
proxy setter alongside the legacy HardNc
NcOptProc.EnableIndividualStepAdjustmentLog.
public static bool EnableStepAdjustmentLog { get; set; }
Property Value
Methods
AccelerationConstrainAllFeedrate(List<INcOptPiecePack>, List<MachiningStep>, SortedList<int, NcOptOption>, Dictionary<int, INcOptPiecePack>, IProgress<IMessage>)
Constrain the feedrate of all steps by the maximum acceleration: walks every step forward and recursively propagates the acceleration limit backward when a step's feedrate cannot be reached.
public static void AccelerationConstrainAllFeedrate(List<INcOptPiecePack> piecePackList, List<MachiningStep> machiningSteps, SortedList<int, NcOptOption> stepIndexToSeedOptionSortedList, Dictionary<int, INcOptPiecePack> stepIndexToPackDictionary, IProgress<IMessage> mixedProgress)
Parameters
piecePackListList<INcOptPiecePack>The list of piece packs to process.
machiningStepsList<MachiningStep>The list of machining steps.
stepIndexToSeedOptionSortedListSortedList<int, NcOptOption>Sorted list mapping step index to seed optimization option.
stepIndexToPackDictionaryDictionary<int, INcOptPiecePack>Dictionary mapping step index to its owning pack. The packs here carry at least 1 step each.
mixedProgressIProgress<IMessage>The message host for logging.
BuildCompensation(ICuttingPara, List<INcOptPiecePack>, List<MachiningStep>, SortedList<int, NcOptOption>, IProgress<IMessage>)
Builds tool deflection compensation for every non-arc piece pack, writing each step's compensation vector into the PACK's own adjustment (StepAdjustmentList / StepAdjustment) — the object the writeback plan builder reads.
public void BuildCompensation(ICuttingPara millingPara, List<INcOptPiecePack> piecePackList, List<MachiningStep> machiningSteps, SortedList<int, NcOptOption> stepIndexToSeedOptionSortedList, IProgress<IMessage> mixedProgress)
Parameters
millingParaICuttingParaThe cutting parameters.
piecePackListList<INcOptPiecePack>The list of piece packs to process.
machiningStepsList<MachiningStep>The list of machining steps.
stepIndexToSeedOptionSortedListSortedList<int, NcOptOption>Sorted list mapping step index to seed optimization option.
mixedProgressIProgress<IMessage>The message host for logging.
Remarks
Fixed-handoff port of HiNc NcOptProc.BuildCompensation (frozen
HardNc baseline, HiNc/NcOpt/NcOptProc.cs lines 1503-1560).
History note — the baseline carries a data-flow defect that is
deliberately NOT reproduced: it writes the compensation into the
StepAdjustment of the context dictionary
(baseline lines 1529-1533/1547-1551) while its output generation reads
the pack's own adjustment (lines 2205-2206), whose compensation stays
null from construction — so HardNc never emitted a compensated
coordinate. This port redirects the assignment to the pack adjustments,
closing the handoff (the context/pack object separation itself is
intentional and stays, StepOptContext).
A second divergence follows from the redirect: the per-step fast path
compares MachineMotionStep.Feedrate_mmds against the PACK
adjustment's post-flatten/acceleration DstFeedrate_mmds — the
value the writeback chain continues from — whereas the baseline
compared the context-side value those passes never touch. The pack
value is the saner recompute trigger: the simulated deflection is
reused exactly when the destination feedrate still equals the
simulated one.
Ported gates: arc packs are skipped whole (IsArc, baseline lines 1515-1517 — arc lines never build compensation), PreservedPiecePack builds nothing, and a step only builds when its seed option's CompensationMask is non-zero. A mono pack's single shared adjustment is written per step (the last step wins), mirroring the baseline's build side; the writeback deliberately consumes compensation on splition fragments only (see StepAdjustment).
ConstrainIndividualFeedrate(ICuttingPara, MachiningToolHouse, bool, List<INcOptPiecePack>, List<MachiningStep>, Dictionary<int, StepOptContext>, IProgress<IMessage>)
Constrains individual feedrate for each step.
public static void ConstrainIndividualFeedrate(ICuttingPara millingPara, MachiningToolHouse millingToolHouse, bool isFlatConstraining, List<INcOptPiecePack> piecePackList, List<MachiningStep> machiningSteps, Dictionary<int, StepOptContext> stepIndexToStepOptContextDictionary, IProgress<IMessage> mixedProgress)
Parameters
millingParaICuttingParaThe cutting parameters.
millingToolHouseMachiningToolHouseThe machining tool house.
isFlatConstrainingboolFlat constraining process is the pre-process that constrains neighbor steps to the same feedrate; non-flat constraining process is the post-process.
piecePackListList<INcOptPiecePack>The list of piece packs to process.
machiningStepsList<MachiningStep>The list of machining steps.
stepIndexToStepOptContextDictionaryDictionary<int, StepOptContext>Dictionary mapping step index to optimization context.
mixedProgressIProgress<IMessage>The message host for logging.
GetIndexByPostDistance(List<MachiningStep>, int, double)
Get index by post distance.
The index position is larger than the distance or is at end or is stepIndex.
Or the index is endIndex(size of the machiningSteps) or is stepIndex.
public static int GetIndexByPostDistance(List<MachiningStep> machiningSteps, int stepIndex, double extendedPostDistance)
Parameters
machiningStepsList<MachiningStep>All machining steps.
stepIndexintThe target step index the window extends from.
extendedPostDistancedoubleThe forward extension distance in mm.
Returns
- int
The walked index.
GetIndexByPreDistance(List<MachiningStep>, int, double)
Get index by pre-distance.
The position of index is before the distance. i.e. the distance is larger from extendedPreDistance.
Or the index is 0 or is stepIndex.
public static int GetIndexByPreDistance(List<MachiningStep> machiningSteps, int stepIndex, double extendedPreDistance)
Parameters
machiningStepsList<MachiningStep>All machining steps.
stepIndexintThe target step index the window extends from.
extendedPreDistancedoubleThe backward extension distance in mm.
Returns
- int
The walked index.
GetTouchedFeedPerToothBoundary_mm(MachiningStep, NcOptOption)
Get the feed-per-tooth boundary in mm of a touched step by composing the option limits and the cutter optimization limits. If the composed limits conflict, the smallest wins (conservation principle).
public static Range<double> GetTouchedFeedPerToothBoundary_mm(MachiningStep machiningStep, NcOptOption ncOptOption)
Parameters
machiningStepMachiningStepThe machining step.
ncOptOptionNcOptOptionThe optimization option effective on the step.
Returns
Remarks
rapid is not concern
GetTouchedFeedrateBoundary_mmds(MachiningStep, NcOptOption)
Get the feedrate boundary in mm/s of a touched step. When the tool flute num is known the boundary derives from GetTouchedFeedPerToothBoundary_mm(MachiningStep, NcOptOption); otherwise from the option's plain feedrate limits.
public static Range<double> GetTouchedFeedrateBoundary_mmds(MachiningStep machiningStep, NcOptOption ncOptOption)
Parameters
machiningStepMachiningStepThe machining step.
ncOptOptionNcOptOptionThe optimization option effective on the step.
Returns
Remarks
rapid is not concern
ParallelBuildStepAdjustments(ICuttingPara, Dictionary<int, StepOptContext>, List<MachiningStep>, Func<string, string>, IProgress<IMessage>, CancellationToken)
Build the per-step StepAdjustment of every entry of
stepIndexToStepOptContextDictionary in parallel.
When EnableStepAdjustmentLog is on, one
.IndependentStepAdjustment.log file is created per source NC file.
public void ParallelBuildStepAdjustments(ICuttingPara millingPara, Dictionary<int, StepOptContext> stepIndexToStepOptContextDictionary, List<MachiningStep> machiningSteps, Func<string, string> getLogBaseFilePath, IProgress<IMessage> messageProgress, CancellationToken cancellationToken)
Parameters
millingParaICuttingParaThe cutting parameters.
stepIndexToStepOptContextDictionaryDictionary<int, StepOptContext>Dictionary mapping step index to optimization context.
machiningStepsList<MachiningStep>The raw strip-pose step projection, UNFILTERED, in strip order (position ==
MachiningStep.StepIndex; entries may be null).getLogBaseFilePathFunc<string, string>Maps a source NC file path to the absolute base output path of its adjustment log; the solver appends the
.IndependentStepAdjustment.logsuffix. This is the runner-agnostic replacement for the HardNc[NcFile]/[NcName]template constants —Hi.Common.PathUtils.PathUtil.GetPathByTemplatemay be used by the caller with its own keyword strings.messageProgressIProgress<IMessage>The message host for logging.
cancellationTokenCancellationTokenCancellation token to cancel the operation.
Remarks
Step-index key space: every step-keyed collection here — the context
dictionary keys, the logger seed sets (built from
StepIndex) and the
Enqueue(int, string) keys (the dictionary entry
keys) — lives in ONE space: the step's position in
machiningSteps, which equals the intrinsic
MachiningStep.StepIndex (the strip pos index) because the list
is the raw unfiltered strip-pose projection (mirrors the oracle,
NcOptProc.cs:2521). Null-step tolerance likewise mirrors the
oracle: steps are read directly with no extra null guards, exactly as
the oracle reads them (NcOptProc.cs:1211, 1236).