Skip to content

interp: get the kinematics and HAL values from the canon - #4899

Open
grandixximo wants to merge 3 commits into
LinuxCNC:masterfrom
grandixximo:interp-kins-canon
Open

grandixximo wants to merge 3 commits into
LinuxCNC:masterfrom
grandixximo:interp-kins-canon

Conversation

@grandixximo

@grandixximo grandixximo commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Bertho pointed out on #4891 that the interpreter ties librs274 to HAL: it loaded the machine's kinematics module itself, on a HAL component of its own, and #<_hal[name]> read HAL directly. Rene suggested on #4852 keeping _hal[] and moving only the HAL access behind a canon call.

The canon now answers both:

  • GET_EXTERNAL_KINEMATICS() loads a module for each caller and hands it out with a table of the calls on it, KinematicsUserOps. The interpreter keeps both in its setup and frees the module at exit, so each interpreter instance has its own and none shares a kinematics type or tool offset with another. Task loads it on the HAL component canon already holds for its joint caps, which the new EXIT_CANON() releases; the preview module loads it from INI_FILE_NAME; sai has no machine and says so.
  • GET_EXTERNAL_HAL_VALUE() reads the pin, signal or param for #<_hal[name]>; task and the preview module answer it with hal_get_p() and hal_get_s().

librs274 no longer links liblinuxcnchal or libkinslimits.

The second commit brings the stub canon in tests/interp/compile up to date. Built against the internal headers it links -lrs274 alone and prints what expected holds. The test stays skipped: rs274ngc.hh, interp_base.hh, interp_fwd.hh and nurbs_math.hh are not exported to include/ yet. @BsAtHome, how would you like that done?

Tested with the ptp, kins (kins-switch reads _hal[]), twp, interp, gcode-renderer and tool tests, rs274 on a G68.3 program, and gcode.parse() with HAL up. I added no test, since what the programs see is unchanged.

Two choices to look at. Rene floated one READ_SPECIAL_VARIABLE(name) for INI and HAL values; I kept a HAL-only call, since the interpreter reads the INI file itself. The logOword notes "no signal connected" and "signal has no writer" went away with the lookup.

The interpreter loaded the machine's kinematics module itself, on a HAL component of its own, and #<_hal[name]> read HAL directly, so librs274 linked liblinuxcnchal and libkinslimits and the interpreter owned a HAL component's lifetime.

The canon now answers both. GET_EXTERNAL_KINEMATICS() loads a module for each caller on the canon's HAL component and hands it out with a table of the calls on it, KinematicsUserOps; the interpreter keeps both in its setup and frees the module through the table at exit, before the new EXIT_CANON() lets the component go. GET_EXTERNAL_HAL_VALUE() reads a pin, signal or param through a new hal_get_number(). Task and the preview module answer both; sai has no machine and no HAL. librs274 no longer links liblinuxcnchal or libkinslimits.
The stub lacked 17 canon calls added since the test was disabled, plus the two GET_EXTERNAL_ calls added here. Built against the internal headers it links -lrs274 alone, runs under LD_BIND_NOW and prints what expected holds. It stays skipped until the interpreter headers are exported to include/.

@BsAtHome BsAtHome left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you missed emc/canterp/canterp.cc

Comment thread src/hal/hal_lib_query.c Outdated
Comment on lines +449 to +456
//
// hal_get_number() - Read a pin, signal or param by name, in that order, as a
// number, the way the interpreter's #<_hal[name]> does
//
// Returns 0 with *value set, -ENOENT when nothing has that name, -EFAULT when
// HAL is not mapped and -EINVAL for a port.
//
int hal_get_number(const char *name, double *value)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This does not belong in here. This is a specific case for the interpreter that always wants a floating point answer.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed, it is out of HAL. Task and the preview module now read the pin, signal or param themselves with hal_get_p() and hal_get_s().

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think there should be a function that does exactly this. My hal.hh had this, the python interface needs it as well.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bertho's point was that hal_lib_query.c is the wrong home for a lookup that always answers a double, which is only what the interpreter wants. hal::get_value() in hal.hh (#4251) is the general one, returning the value in its HAL type, so once that lands both canons call it and convert, and the two copies here go away. Until then I kept the lookup in the canons so this PR does not wait on #4251. Does that work for you?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hal_lib contains primitives and abstractions. There are very few specific exceptions in the halcmd/HAL interaction (loadrt), but otherwise we should keep cascading searches and conversions to the upper levels.

hal_get_number() put an interpreter-specific lookup in the HAL query API. Task and the preview module now read the pin, signal or param themselves with hal_get_p() and hal_get_s(). canterp replays EXIT_CANON as it does INIT_CANON.
@grandixximo

Copy link
Copy Markdown
Contributor Author

canterp now replays EXIT_CANON next to INIT_CANON. If you meant something else in there, tell me what I missed.

On the headers for tests/interp/compile: I would move rs274ngc.hh, interp_base.hh and interp_fwd.hh to include/rs274ngc/ and nurbs_math.hh to include/nml_intf/, the way the interface types went to include/nml_intf/, and include them by that prefix. Would that work for you, here or in a PR of its own?

@rene-dev

Copy link
Copy Markdown
Member

the INIT_CANON and EXIT_CANON should go into constructor/destructor after the canon interface refactor...

@rene-dev

Copy link
Copy Markdown
Member

can you explain what the kinematics change is about? there is more happening here than the heading suggests.

@grandixximo

Copy link
Copy Markdown
Contributor Author

Agreed. Until then EXIT_CANON() is the pair to INIT_CANON(), and task calls it after the interpreter's exit.

@grandixximo grandixximo changed the title interp: reach HAL only through the canon interp: get the kinematics and HAL values from the canon Nov 24, 2026
@BsAtHome

Copy link
Copy Markdown
Contributor

On the headers for tests/interp/compile: I would move rs274ngc.hh, interp_base.hh and interp_fwd.hh to include/rs274ngc/ and nurbs_math.hh to include/nml_intf/, the way the interface types went to include/nml_intf/, and include them by that prefix. Would that work for you, here or in a PR of its own?

A separate PR should be better to keep together what belongs together. I will have a look at these headers and make a PR.

@grandixximo

Copy link
Copy Markdown
Contributor Author

can you explain what the kinematics change is about? there is more happening here than the heading suggests.

Kinematics change are about having the interpreter unbound from HAL, the gcode that need kinematics awareness get it from canon, does that answer the question?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants