kinematics: Generic Cartesian kinematics implementation (#6815)

* tests: Added a regression test for generic_cartesian kinematics

* kinematics: An intial implementation of generic_cartesian kinematics

* generic_cartesian: Refactored kinematics configuration API

* generic_cartesian: Use stepper instead of kinematic_stepper in configs

* generic_cartesian: Added SET_STEPPER_KINEMATICS command

* generic_cartesian: Fixed parsing of section names

* docs: Generic Caretsian kinematics documentation and config samples

* generic_cartesian: Implemented multi-mcu homing validation

* generic_cartesian: Fixed typos in docs, minor fixes

* generic_cartesian: Renamed `kinematics` option to `carriages`

* generic_cartesian: Moved kinematic_stepper.py file

* idex_modes: Internal refactoring of handling dual carriages

* stepper: Refactored the code to not store a reference to config object

* config: Updated example-generic-cartesian config

* generic_cartesian: Restricted SET_STEPPER_CARRIAGES and exported status

* idex_modes: Fixed handling stepper kinematics with input shaper enabled

* config: Updated configs and tests for SET_DUAL_CARRIAGE new params

* generic_cartesian: Avoid inheritance in the added classes

Signed-off-by: Dmitry Butyugin <dmbutyugin@google.com>
This commit is contained in:
Dmitry Butyugin
2025-05-07 00:06:36 +02:00
committed by GitHub
parent 1cc6398074
commit cc6736c3e3
27 changed files with 1855 additions and 199 deletions

172
test/klippy/corexyuv.cfg Normal file
View File

@@ -0,0 +1,172 @@
# Test config for generic cartesian kinematics with dual carriage
[carriage x]
position_endstop: 0
position_max: 300
homing_speed: 50
endstop_pin: ^PE5
[carriage y]
position_endstop: 0
position_max: 200
homing_speed: 50
endstop_pin: ^PJ1
[carriage z]
position_endstop: 0.5
position_max: 100
endstop_pin: ^PD3
[extra_carriage z1]
primary_carriage: z
endstop_pin: ^PD2
[dual_carriage u]
primary_carriage: x
safe_distance: 70
position_endstop: 300
position_max: 300
homing_speed: 50
endstop_pin: ^PE4
[dual_carriage v]
primary_carriage: y
safe_distance: 50
position_endstop: 200
position_max: 200
homing_speed: 50
endstop_pin: ^PD4
[stepper a]
carriages: x+y
step_pin: PF0
dir_pin: PF1
enable_pin: !PD7
microsteps: 16
rotation_distance: 40
[stepper b]
carriages: u-v
step_pin: PH1
dir_pin: PH0
enable_pin: !PA1
microsteps: 16
rotation_distance: 40
[stepper c]
carriages: x-y
step_pin: PF6
dir_pin: !PF7
enable_pin: !PF2
microsteps: 16
rotation_distance: 40
[stepper d]
carriages: u+v
step_pin: PE3
dir_pin: !PH6
enable_pin: !PG5
microsteps: 16
rotation_distance: 40
[stepper z]
carriages: z
step_pin: PL3
dir_pin: PL1
enable_pin: !PK0
microsteps: 16
rotation_distance: 8
[stepper z1]
carriages: z1
step_pin: PG1
dir_pin: PG0
enable_pin: !PH3
microsteps: 16
rotation_distance: 8
[extruder]
step_pin: PA4
dir_pin: PA6
enable_pin: !PA2
microsteps: 16
rotation_distance: 33.5
nozzle_diameter: 0.400
filament_diameter: 1.750
heater_pin: PB4
sensor_type: EPCOS 100K B57560G104F
sensor_pin: PK5
control: pid
pid_Kp: 22.2
pid_Ki: 1.08
pid_Kd: 114
min_temp: 0
max_temp: 250
[gcode_macro PARK_extruder]
gcode:
SET_DUAL_CARRIAGE CARRIAGE=x
SET_DUAL_CARRIAGE CARRIAGE=y
G90
G1 X0 Y0
[gcode_macro T0]
gcode:
PARK_{printer.toolhead.extruder}
SET_SERVO SERVO=my_servo angle=100
ACTIVATE_EXTRUDER EXTRUDER=extruder
SET_DUAL_CARRIAGE CARRIAGE=x
SET_DUAL_CARRIAGE CARRIAGE=y
[extruder1]
step_pin: PC1
dir_pin: PC3
enable_pin: !PC7
microsteps: 16
rotation_distance: 33.5
nozzle_diameter: 0.400
filament_diameter: 1.750
heater_pin: PB5
sensor_type: EPCOS 100K B57560G104F
sensor_pin: PK7
control: pid
pid_Kp: 22.2
pid_Ki: 1.08
pid_Kd: 114
min_temp: 0
max_temp: 250
[gcode_macro PARK_extruder1]
gcode:
SET_DUAL_CARRIAGE CARRIAGE=u
SET_DUAL_CARRIAGE CARRIAGE=v
G90
G1 X300 Y200
[gcode_macro T1]
gcode:
PARK_{printer.toolhead.extruder}
SET_SERVO SERVO=my_servo angle=50
ACTIVATE_EXTRUDER EXTRUDER=extruder1
SET_DUAL_CARRIAGE CARRIAGE=u
SET_DUAL_CARRIAGE CARRIAGE=v
[servo my_servo]
pin: PH4
[heater_bed]
heater_pin: PH5
sensor_type: EPCOS 100K B57560G104F
sensor_pin: PK6
control: watermark
min_temp: 0
max_temp: 130
[mcu]
serial: /dev/ttyACM0
[printer]
kinematics: generic_cartesian
max_velocity: 300
max_accel: 3000
max_z_velocity: 5
max_z_accel: 100

52
test/klippy/corexyuv.test Normal file
View File

@@ -0,0 +1,52 @@
# Test cases on printers with dual carriage and multiple extruders
CONFIG corexyuv.cfg
DICTIONARY atmega2560.dict
# First home the printer
G90
G28
# Perform a dummy move
G1 X10 Y20 F6000
# Activate alternate carriage
SET_DUAL_CARRIAGE CARRIAGE=u
SET_DUAL_CARRIAGE CARRIAGE=v
G1 X170 Y190 F6000
# Go back to main carriage on X axis
SET_DUAL_CARRIAGE CARRIAGE=x
G1 X20 F6000
# Save dual carriage state
SAVE_DUAL_CARRIAGE_STATE
G1 Y150 F6000
# Go back to main carriage on Y axis
SET_DUAL_CARRIAGE CARRIAGE=y
G1 X10 Y50 F6000
# Restore dual carriage state
RESTORE_DUAL_CARRIAGE_STATE
# Test changing extruders
G1 X5
T1
G91
G1 X-10 E.2
T0
G91
G1 X20 E.2
G90
QUERY_ENDSTOPS
# Servo tests
SET_SERVO servo=my_servo angle=160
SET_SERVO servo=my_servo angle=130
# Verify STEPPER_BUZZ
STEPPER_BUZZ STEPPER='stepper d'
STEPPER_BUZZ STEPPER=extruder
STEPPER_BUZZ STEPPER=extruder1

View File

@@ -0,0 +1,165 @@
# Test config for generic cartesian kinematics with dual carriage
[carriage x]
position_endstop: 0
position_max: 300
homing_speed: 50
endstop_pin: ^PE5
[carriage y]
position_endstop: 0
position_max: 200
homing_speed: 50
endstop_pin: ^PJ1
[extra_carriage y1]
primary_carriage: y
endstop_pin: ^PB6
[carriage z]
position_endstop: 0.5
position_max: 100
endstop_pin: ^PD3
[extra_carriage z1]
primary_carriage: z
endstop_pin: ^PD2
[dual_carriage u]
primary_carriage: x
position_endstop: 300
position_max: 300
homing_speed: 50
endstop_pin: ^PE4
[stepper stepper_x]
carriages: x+y
step_pin: PF0
dir_pin: PF1
enable_pin: !PD7
microsteps: 16
rotation_distance: 40
[stepper dual_carriage]
carriages: u-y1
step_pin: PH1
dir_pin: PH0
enable_pin: !PA1
microsteps: 16
rotation_distance: 40
[stepper stepper_y]
carriages: 1*y+0.5*z
step_pin: PF6
dir_pin: !PF7
enable_pin: !PF2
microsteps: 16
rotation_distance: 40
[stepper stepper_y1]
carriages: 1*y1-0.5*z1
step_pin: PE3
dir_pin: !PH6
enable_pin: !PG5
microsteps: 16
rotation_distance: 40
[stepper stepper_z]
carriages: z
step_pin: PL3
dir_pin: PL1
enable_pin: !PK0
microsteps: 16
rotation_distance: 8
[stepper stepper_z1]
carriages: z1
step_pin: PG1
dir_pin: PG0
enable_pin: !PH3
microsteps: 16
rotation_distance: 8
[extruder]
step_pin: PA4
dir_pin: PA6
enable_pin: !PA2
microsteps: 16
rotation_distance: 33.5
nozzle_diameter: 0.400
filament_diameter: 1.750
heater_pin: PB4
sensor_type: EPCOS 100K B57560G104F
sensor_pin: PK5
control: pid
pid_Kp: 22.2
pid_Ki: 1.08
pid_Kd: 114
min_temp: 0
max_temp: 250
[gcode_macro PARK_extruder]
gcode:
SET_DUAL_CARRIAGE CARRIAGE=x
G90
G1 X0
[gcode_macro T0]
gcode:
PARK_{printer.toolhead.extruder}
SET_SERVO SERVO=my_servo angle=100
ACTIVATE_EXTRUDER EXTRUDER=extruder
SET_DUAL_CARRIAGE CARRIAGE=x
[extruder1]
step_pin: PC1
dir_pin: PC3
enable_pin: !PC7
microsteps: 16
rotation_distance: 33.5
nozzle_diameter: 0.400
filament_diameter: 1.750
heater_pin: PB5
sensor_type: EPCOS 100K B57560G104F
sensor_pin: PK7
control: pid
pid_Kp: 22.2
pid_Ki: 1.08
pid_Kd: 114
min_temp: 0
max_temp: 250
[gcode_macro PARK_extruder1]
gcode:
SET_DUAL_CARRIAGE CARRIAGE=u
G90
G1 X300
[gcode_macro T1]
gcode:
PARK_{printer.toolhead.extruder}
SET_SERVO SERVO=my_servo angle=50
ACTIVATE_EXTRUDER EXTRUDER=extruder1
SET_DUAL_CARRIAGE CARRIAGE=u
[servo my_servo]
pin: PH4
[heater_bed]
heater_pin: PH5
sensor_type: EPCOS 100K B57560G104F
sensor_pin: PK6
control: watermark
min_temp: 0
max_temp: 130
[mcu]
serial: /dev/ttyACM0
[printer]
kinematics: generic_cartesian
max_velocity: 300
max_accel: 3000
max_z_velocity: 5
max_z_accel: 100
[input_shaper]

View File

@@ -0,0 +1,64 @@
# Test cases on printers with dual carriage and multiple extruders
CONFIG generic_cartesian.cfg
DICTIONARY atmega2560.dict
# Configure the input shaper
SET_DUAL_CARRIAGE CARRIAGE=u
SET_INPUT_SHAPER SHAPER_TYPE_X=ei SHAPER_FREQ_X=50 SHAPER_TYPE_Y=2hump_ei SHAPER_FREQ_Y=80
SET_DUAL_CARRIAGE CARRIAGE=x
SET_INPUT_SHAPER SHAPER_TYPE_X=ei SHAPER_FREQ_X=50 SHAPER_TYPE_Y=2hump_ei SHAPER_FREQ_Y=80
# Then home the printer
G90
G28
# Perform a dummy move
G1 X10 F6000
# Activate alternate carriage
SET_DUAL_CARRIAGE CARRIAGE=u
G1 X190 F6000
# Go back to main carriage
SET_DUAL_CARRIAGE CARRIAGE=x
G1 X100 F6000
# Save dual carriage state
SAVE_DUAL_CARRIAGE_STATE
G1 X50 F6000
# Go back to alternate carriage
SET_DUAL_CARRIAGE CARRIAGE=u
G1 X130 F6000
# Restore dual carriage state
RESTORE_DUAL_CARRIAGE_STATE MOVE=1
# Test changing extruders
G1 X5
T1
G91
G1 X-10 E.2
T0
G91
G1 X20 E.2
G90
# Test changing the stepper kinematics
SET_STEPPER_CARRIAGES STEPPER=dual_carriage CARRIAGES=u+y1
SET_STEPPER_CARRIAGES STEPPER=stepper_x CARRIAGES=x-y
G1 X30 E.2
G1 Z3
QUERY_ENDSTOPS
# Servo tests
SET_SERVO servo=my_servo angle=160
SET_SERVO servo=my_servo angle=130
# Verify STEPPER_BUZZ
STEPPER_BUZZ STEPPER='stepper dual_carriage'
STEPPER_BUZZ STEPPER=extruder
STEPPER_BUZZ STEPPER=extruder1