Skip to content

task: planner refactor, remove unused NML commands - #4969

Open
rene-dev wants to merge 11 commits into
LinuxCNC:masterfrom
rene-dev:task-planner-refactor
Open

rene-dev wants to merge 11 commits into
LinuxCNC:masterfrom
rene-dev:task-planner-refactor

Conversation

@rene-dev

@rene-dev rene-dev commented Dec 5, 2026

Copy link
Copy Markdown
Member

The task planner refactor from #4832, with the NML commands nothing sends, split out as asked in review there. No change in behaviour except the removed commands: breaking-change for out-of-tree NML clients.

Commits

  1. tests: record what the task planner does with every command
    tests/task-planner brings task into each situation the planner tells apart (E-stop, off, Manual, MDI idle and running, Auto idle, reading, waiting, paused) and sends it every command emcTaskPlan() handles, one at a time. It records whether the planner issued, queued, refused or handled each one, and what situation it left task in; expected is today's behaviour. The commands come from test_task_probe, a small NML client built for run-in-place only; without it the test is skipped (a skip file). This is scaffolding: each refactoring commit below leaves the table unchanged, and the last commit removes the test again.
  2. task: hand emcTaskPlan() the new command: the main loop decides whether there is a new command and passes it, or NULL. This is what lets a command reach the planner another way (task's HAL pins, next PR).
  3. task: one list of immediate commands for the planner tables: isImmediate() says once what the eight tables each repeated. 256 lines shorter; letting spindle orient through in Manual, as an example of a slip, fails the table.
  4. nml: remove seven commands nothing in the tree sends: EMC_JOG_ABS, EMC_JOINT_HALT, EMC_JOINT_SET_FERROR, EMC_JOINT_SET_MIN_FERROR, EMC_JOINT_SET_HOMING_PARAMS, EMC_TRAJ_SET_VELOCITY, EMC_TRAJ_SET_ACCELERATION.
  5. task: remove the MDI input queue nothing appends to, and what is left of checkInterpList()
  6. task: the message pointers of emcTaskIssueCommand() are locals
  7. task: one table for what a queued command waits for, before and after: commandWaits() and steppingHolds() replace the pre/postcondition switches and STEPPING_CHECK.
  8. task: the planner is one switch instead of seven nested ones: the situation is worked out once; a command is handled by the planner (planSpecial()), passed through (isImmediate()) or refused (refuse()).
  9. motion: remove EMCMOT_JOG_ABS, which nothing sends any more: in teleop it wasn't absolute either.
  10. tests: remove the task planner table and its probe: the refactoring is done, and the table would otherwise have to follow every later planner change. It ran for about a minute, and its fixed delays made it sensitive to load.

The kinematics-switch hold (#4949) and the queued-MDI READING state (#4890) from master are carried into the new switch.

Breaking changes

The seven NML command types above, and EMCMOT_JOG_ABS, are gone. Nothing in the tree sent them.

Found along the way

#4831: after a tool command in Manual or MDI, task's wait flag stays set and MDI commands are queued instead of issued until a program runs. The planner table clears the flag before each situation; the behaviour itself is left as it is.

Part of #4832, which stays open as the tracking branch.

tests/task-planner brings task into each situation its planner tells
apart (E-stop, off, Manual, MDI idle and running, Auto idle, reading,
waiting and paused) and sends it every command emcTaskPlan() handles,
one at a time, plus one it has no case for. From task's own debug output
it records, for each, whether the planner issued the command, queued it
for later, refused it or handled it itself, and what situation the
command left task in. The table is compared with tests/task-planner/
expected, which is the behaviour of today's planner.

A change to the planner that is not meant to change behaviour leaves the
table as it is; one that is shows up as a diff of it.

The commands come from test_task_probe, a small NML client that sends
any of them with arguments that change as little as possible. It is
built for run-in-place only and not installed; the test skips without
it.
emcTaskPlan() found its command itself: it compared emcCommand's serial
number with the echoed one to tell a new command from none, and
allow_while_idle_type() read the command's type from the NML buffer once
more. Have the main loop make that decision and pass the new command,
or NULL, and use only that inside the planner.

This is what lets a command reach the planner by another way than the
NML buffer. No change in behaviour: tests/task-planner is unchanged.
The planner's tables repeated the commands each passes straight to
emcTaskIssueCommand(): 22 accepted in any state, three more only while
the machine is off, twelve once it is on, the spindle commands unless a
program is reading or waiting, the program and I/O commands unless one
runs, and so on. isImmediate() now says this once, by the state, mode
and interpreter state task is in, and each table keeps only what is
special to it and its own refusal. allow_while_idle_type() is part of
it now, and the three tool commands share queueToolCommand().

No change in behaviour: tests/task-planner is unchanged, and fails if
spindle orient is let through in Manual, as an example of a slip.
EMC_JOG_ABS, EMC_JOINT_HALT, EMC_JOINT_SET_FERROR, EMC_JOINT_SET_MIN_FERROR,
EMC_JOINT_SET_HOMING_PARAMS, EMC_TRAJ_SET_VELOCITY and
EMC_TRAJ_SET_ACCELERATION, with their classes, task's handling of them and
their rows in the planner table. emcJogAbs() had no other caller.
… of checkInterpList()

checkInterpList() lost its limit checks long ago and always returned 0; it
now only shows the operator errors of the lines it drops. task read
[TASK]MDI_QUEUED_COMMANDS and never used it.
42 file-level pointers each held the cast for one case. Those used once
are folded into the call; the others are declared in their case.
emcTaskCheckPreconditions() and emcTaskCheckPostconditions() become
commandWaits(), and the STEPPING_CHECK macro becomes steppingHolds(). The
table says what the two switches said, command for command.
emcTaskPlan() works out the situation once, then a command is handled by
the planner itself (planSpecial()), passed straight through
(isImmediate()) or refused (refuse()). The planner table is unchanged.
With EMC_JOG_ABS and emcJogAbs() gone the handler had no caller. In teleop
it was not absolute either: axis_jog_abs() added the target to the current
position.
tests/task-planner and test_task_probe recorded what the planner did with
every command, to show that the refactoring of emcTaskPlan() changed
nothing. That work is done.
@rene-dev
rene-dev force-pushed the task-planner-refactor branch from 3e31a6d to 2b89446 Compare December 6, 2026 12:52
Comment thread src/emc/task/emctaskmain.cc Resolved
Comment thread src/emc/task/emctaskmain.cc Resolved
Comment thread src/emc/task/emctaskmain.cc Resolved
Comment thread src/emc/task/emctaskmain.cc Resolved
Comment thread src/emc/task/emctaskmain.cc Resolved
From the review of LinuxCNC#4969:

- Situation has one field per line, each with a comment, and the
  comment above it says why it is a snapshot: the readahead at the end
  of emcTaskPlan() has to go by the situation the command found.
- situation() uses designated initializers; its local is machineOn, so
  it no longer shadows the field on.
- isImmediate() uses s.on, s.manual, ... instead of copying them into
  locals.
- The new planner functions, the case blocks this PR changes in
  emcTaskIssueCommand() and emcTaskExecute(), and the main loop's
  command handling are indented with spaces. git diff -w shows only
  the changes above.
- A comment in the main loop says how a new command is told apart and
  that the planner sees each command once.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants