I think it may be necessary to change the behavior of some of the status variables available to macros and on the API Server. For example, it may be necessary to change the format of {printer.gcode_move.position}.
This message is to gather feedback on how we should go about making a change like this. @pedrolamas, @meteyou, @arksine, @dmbutyugin, I’d be interested in hearing your thoughts.
We recently added support for “extra gcode axes” to the Klipper code ( Support for additional G1 axes (6-axis support) by KevinOConnor · Pull Request #6888 · Klipper3d/klipper · GitHub ). Previously, regular G1 style moves contained four coordinates - XYZE. However, now a G1 move can have many additional axes (eg, XYZERPNU) - the number of axes and their letter designations are user defined and can change at run-time. Currently, it is possible to map “manual_stepper” motors to these additional axes, but @dmbutyugin is looking to extend that support to additional extruders and additional kinematic carriages ( Support of mapping dual_carriage(s) and extruders to custom GCode axes ).
We currently export coordinates in status reports today in a somewhat quirky way. We typically export coordinates using a Python “named tuple” - examples include gcode_move.position, gcode_move.homing_origin, gcode_move.gcode_position, toolhead.position, toolhead.axis_min, toolhead.axis_max, motion_report.live_position. A “named tuple” allows the internal code and macros to access the coordinates by name (eg, {printer.gcode_move.position.x}), but on the API Server the coordinates are transmitted as a list (eg, { "gcode_move": { "position": [1.0, 2.0, 3.0, 4.0] }, ... }).
Although the code fully supports additional axes today, it does not currently export their positions. Going forward we would like to export this information, however it isn’t clear what is the best way to do that. Extending the “named tuple” isn’t going to work well for extra axes because there isn’t any meaningful order to these axes (reporting them as a list doesn’t make sense). Also, the full axis name can be quite long and contain spaces (eg, “manual_stepper my_extra_stepper”).
I have a proposal for how we could make this change:
-
The following status variables will continue to use an internal “named tuple”, but only provide XYZ in the future:
gcode_move.homing_origin,toolhead.axis_min,toolhead.axis_max,toolhead.position,motion_report.live_position. For the first three of these, the E field was always zero anyway, so this shouldn’t be a significant change. To obtain the toolhead position of extruder (and other extra axes), we could add a new{'toolhead': {'extra_axes': ['extruder', 'manual_stepper my_stepper']}}list and export the current position in these classes (eg,{printer.exruder.position}). For motion_report we could introduce a new field for extra axes:{'motion_report': {'live_position_extra_axes': {'extruder': 123.4, 'manual_stepper my_stepper': 56.7 } } }. To facilitate a conversion, these fields can continue to report XYZE for several months prior to their removal. -
The remaining status variables would be replaced with alternative variables that use mappings (instead of named tuples). So,
gcode_move.positionwould be replaced withgcode_move.axis_position- for example:{'gcode_move': { 'axis_position': {'x': 1.0, 'y': 2.0, 'z': 3.0, 'e': 4.0, 'r': 99.9}}}. Similarly,gcode_move.gcode_positioncould be replaced withgcode_move.gcode_axis_position. Using new status variable names could allow us to provide both versions for a few months during a phaseout period.
One challenge with making a change like this is that there isn’t a good way to provide automatic deprecation notices to users from within Klipper itself. At some point I think it would be worthwhile to remove the old support, and when we do so there’s a good chance it will catch at least some users unaware.
Anyway, does the above seem like a viable plan? Are there other approaches that should be considered?
-Kevin