#printer.cfg_version:V25271

[include printer_MCU.cfg]
[include printer_gcode_macro.cfg]

## 机器设置
[printer]
kinematics:corexy
max_velocity: 1000
max_accel: 40000
max_accel_to_decel: 10000
max_z_velocity: 10
max_z_accel: 150
square_corner_velocity: 8

[stepper_x]
step_pin:PC14
dir_pin:!PC13
enable_pin:!PC15
microsteps: 16
rotation_distance: 39.94
full_steps_per_rotation:200  
#endstop_pin:tmc5160_stepper_x:virtual_endstop
endstop_pin:!MKS_THR:PB12
position_min: -10  
position_endstop: 0
position_max: 330
homing_speed:30
homing_retract_dist:0

[stepper_y]
step_pin:PE5
dir_pin:!PE4
enable_pin:!PD14
microsteps:16
rotation_distance: 39.94
full_steps_per_rotation:200 
# endstop_pin:tmc5160_stepper_y:virtual_endstop
endstop_pin:!PB8
position_min: -10
position_endstop:0
position_max:330
homing_speed:30
homing_retract_dist:0

[stepper_z]
step_pin:PE1
dir_pin:PE0
enable_pin: !PE2
microsteps: 16
rotation_distance:2.674
full_steps_per_rotation: 200
endstop_pin:!PB9
position_endstop: 0.00
position_max: 303
position_min: -5.0
homing_speed: 5
homing_retract_dist: 5
second_homing_speed: 3
homing_positive_dir: false
step_pulse_duration:0.0000001

[stepper_z1]
step_pin:PB5
dir_pin:PB4
enable_pin:!PB6
microsteps:16
rotation_distance:2.674
endstop_pin:!PB9
full_steps_per_rotation: 200
step_pulse_duration:0.0000001

[extruder]
step_pin:MKS_THR:PB9
dir_pin:MKS_THR:PB8
enable_pin:!MKS_THR:PC15 
microsteps:16
rotation_distance: 53.7	
gear_ratio: 1517:170
full_steps_per_rotation: 200
nozzle_diameter: 0.400
filament_diameter: 1.750
min_temp: -100
max_temp: 350
heater_pin: MKS_THR:PB3
sensor_type: NTC 100K MGB18-104F39050L32
sensor_pin: MKS_THR:PA1
max_power: 1.0
min_extrude_temp: 170
smooth_time: 0.000001
nozzle_diameter:0.4
pressure_advance: 0.032
pressure_advance_smooth_time:0.03
max_extrude_cross_section:200
instantaneous_corner_velocity: 10
max_extrude_only_distance: 3000
max_extrude_only_velocity:5000
max_extrude_only_accel:2000
step_pulse_duration:0.000002

[verify_heater extruder]
max_error: 200
check_gain_time:100
hysteresis: 10
heating_gain: 1

[heater_bed]
heater_pin: PD12
sensor_type: NTC 100K MGB18-104F39050L32
sensor_pin: PC0
max_power: 1.0
min_temp: -50
max_temp: 140

[heater_fan Fan0]
pin:MKS_THR:PB4
shutdown_speed: 1

# [fan]
# pin:MKS_THR:PB5

[fan_generic cooling_fan]
pin:MKS_THR:PB5
max_power: 1.0
shutdown_speed: 0
cycle_time: 0.0100
hardware_pwm: false
kick_start_time: 0.100
off_below: 0.0

[fan_generic Chamber_fan]
pin:PA1
max_power: 1.0
shutdown_speed: 0
cycle_time: 0.0100
hardware_pwm: false
kick_start_time: 0.100
off_below: 0.0

[output_pin fan_assist]
pin:MKS_THR:PB6
pwm: True
cycle_time: 0.0100
hardware_pwm: false
value: 0.00
scale: 255
shutdown_value: 0.0

[output_pin board_fan]
pin:PA2
value:1

[temperature_sensor Chamber_sensor]
sensor_type:NTC 100K MGB18-104F39050L32
sensor_pin:PC1


# [temperature_fan Chamber_fan]
# pin: PA1
# sensor_type: NTC 100K MGB18-104F39050L32
# sensor_pin: PC1             
# target_temp: 32.0
# min_temp:-171
# max_temp:100
# control: pid     
# pid_Kp:  32
# pid_Ki: 3
# pid_Kd: 88
# max_speed: 1.0
# min_speed: 0


[idle_timeout]
timeout: 3600000

[homing_override]
gcode:
    {action_respond_info("homing_override_start\n")}
    M84
    G4 P200
    {% if (printer.gcode_move.position.z+5) < 295 %}
    G91
    G1 Z5 F600
    {% else %}
    G91
    G1 Z-5 F600  
    {% endif %}

    G4 P500
    G90
    G28 Y0
    G4 P200
    G1 Y50 F2000
    G4 P200
    G28 X0
    G4 P200
    PRZ_WIPEMOUTH
    G90
    G1 X150 Y150 F8000
    G4 P500
    probe_up
    G4 P200
    G28 Z0
    G4 P200
    probe_off 
    G4 P500
    G1 Z10 F600

    # {% if printer['gcode_macro PRZ_PRINTING_START'].printing_start | int == 1 %}  
    #     {% set extruder_temp = printer.extruder.temperature | int %}
    #     {% set bed_temp = printer.heater_bed.temperature | int %}
    #     SET_HEATER_TEMPERATURE HEATER=heater_bed TARGET={bed_temp}
    #     G4 P200
    #     PRZ_WAITINGAREA
    #     G4 P200
    #     #M104 S235
    #     {action_respond_info("M109 S235\n")}
    #     M109 S235
    #     G4 P200
    #     PRZ_SPITTING
    #     G4 P200
    #     M106 S255
    #     G4 P200
    #     PRZ_WIPEMOUTH
    #     G4 P200
    #     G90 
    #     G1 X150 Y290 F8000
    #     G4 P500
    #     probe_up
    #     G4 P200
    #     G28 Z0
    #     G4 P200
    #     probe_off
    #     G4 P200
    #     SET_PIN PIN=fan_assist VALUE=255
    #     G4 P200
    #     G90
    #     G1 Z0 F300
    #     G4 P200
    #     {action_respond_info("M109 S140\n")}
    #     M109 S140
    #     G4 P5
    #     G1 Z10 F1200
    #     G4 P200
    #     G90
    #     G1 X150 Y150 F8000
    #     G4 P500
    #     probe_up
    #     G4 P200
    #     G28 Z0
    #     G4 P200
    #     probe_off
    #     G4 P200
    #     G90
    #     G1 Z10 F1200
    #     G4 P200
    #     SET_GCODE_VARIABLE MACRO=PRZ_PRINTING_START VARIABLE=printing_start VALUE=0
    #     G4 P200
    #     SET_PIN PIN=fan_assist VALUE=0
    #     G4 P200
    # {% endif %}
    {action_respond_info("homing_override_end\n")}
 
axes: z


# [gcode_macro PG28]
# gcode:
#     G28

[probe]
pin: !PB9
x_offset: 0
y_offset: 0
z_offset: 0
speed: 5
samples: 2
samples_result: median
sample_retract_dist: 2#3
samples_tolerance: 0.02
samples_tolerance_retries: 5
activate_gcode:probe_up
deactivate_gcode:probe_off

# [bed_mesh]
# speed: 150             
# horizontal_move_z: 3    
# mesh_min: 20, 20           
# mesh_max: 280, 280          
# probe_count: 5,5              
# mesh_pps: 4,4                          
# bicubic_tension: 0.2   

[bed_mesh]
speed: 300             
horizontal_move_z: 2    
mesh_min: 10, 10           
mesh_max: 290, 290          
probe_count: 6,6              
mesh_pps: 8,8
algorithm: bicubic                          
bicubic_tension: 0.2    



[tmc5160 stepper_x]
cs_pin:PE6
spi_software_sclk_pin:PE12
spi_software_mosi_pin:PE14
spi_software_miso_pin:PE13
spi_speed:200000
run_current: 1.6
sense_resistor:0.12
stealthchop_threshold:0
diag1_pin:^!PA14
driver_SGT:1

[tmc5160 stepper_y]
cs_pin:PE3
spi_software_sclk_pin:PE12
spi_software_mosi_pin:PE14
spi_software_miso_pin:PE13
spi_speed:200000
run_current: 1.6
sense_resistor:0.12
stealthchop_threshold:0
diag1_pin:^!PA15
driver_SGT:1

[tmc2209 stepper_z]
uart_pin: PB7
interpolate: true
run_current: 0.9
sense_resistor: 0.110
stealthchop_threshold: 0

[tmc2209 stepper_z1]
uart_pin: PB3
interpolate: true
run_current: 0.9
sense_resistor: 0.110
stealthchop_threshold: 0



[tmc2209 extruder]
uart_pin: MKS_THR:PC13
interpolate: true
run_current: 0.707
sense_resistor: 0.110
stealthchop_threshold: 0


[duplicate_pin_override]
pins: PB9


[gcode_arcs]
resolution: 0.5


[virtual_sdcard]
path: /home/mks/printer_data/gcodes

## 暂停恢复功能调用
[pause_resume]

[display_status]

[adxl345]
cs_pin: MKS_THR:PA4
spi_software_sclk_pin: MKS_THR:PA5
spi_software_mosi_pin: MKS_THR:PA7
spi_software_miso_pin: MKS_THR:PA6
axes_map: -x, z, -y

[resonance_tester]
accel_chip: adxl345
probe_points:
    150, 150, 20 


[phrozen_dev]
dev_port: /dev/ttyACM1
auto_connect: false
fila_cut_x_pos: 320
fila_cut_x_pos_up: 1
fila_cut_y_pos: 260
fila_exist_value: 0.476252
fila_empty_value: 0.249695
fila_sensor_pin: MKS_THR:PA2
wait_max_velocity: 180          
wait_line_width: 0.5            
wait_timeout: 60                
switch_fila_zup_by_gcode: 0

#*# <---------------------- SAVE_CONFIG ---------------------->
#*# DO NOT EDIT THIS BLOCK OR BELOW. The contents are auto-generated.
#*#
#*# [bed_mesh phrozen]
#*# version = 1
#*# points =
#*# 	0.129940, 0.129522, 0.076878, 0.059747, 0.075206, 0.152502
#*# 	0.104035, 0.092754, 0.023815, 0.038439, 0.048048, 0.103200
#*# 	0.120748, 0.034678, 0.010418, 0.030473, 0.026322, 0.042617
#*# 	0.183420, 0.100275, 0.020863, 0.027966, -0.010445, -0.016295
#*# 	0.245256, 0.145399, 0.077295, -0.033425, -0.058494, -0.122001
#*# 	0.278681, 0.117823, 0.006267, -0.086905, -0.116570, -0.202639
#*# x_count = 6
#*# y_count = 6
#*# mesh_x_pps = 2
#*# mesh_y_pps = 2
#*# algo = bicubic
#*# tension = 0.2
#*# min_x = 10.0
#*# max_x = 290.0
#*# min_y = 10.0
#*# max_y = 290.0
#*#
#*# [extruder]
#*# control = pid
#*# pid_kp = 32.606
#*# pid_ki = 3.019
#*# pid_kd = 88.038
#*#
#*# [bed_mesh default]
#*# version = 1
#*# points =
#*# 	0.228961, 0.222694, 0.144145, 0.145817, 0.161693, 0.158351, 0.144563, 0.184673, 0.218934, 0.283277, 0.375613
#*# 	0.199714, 0.147906, 0.142056, 0.144145, 0.124508, 0.132864, 0.109049, 0.134118, 0.184255, 0.217680, 0.271578
#*# 	0.147070, 0.144563, 0.119912, 0.118241, 0.046377, 0.049720, 0.078131, 0.119912, 0.158769, 0.189269, 0.282023
#*# 	0.066850, 0.055569, 0.045959, -0.015877, -0.007521, 0.040110, 0.073953, 0.083563, 0.112809, 0.160858, 0.188433
#*# 	0.104453, 0.075624, 0.042617, -0.019637, -0.061864, -0.010055, 0.040083, 0.050973, 0.052644, 0.110303, 0.139549
#*# 	0.107378, 0.084816, -0.001253, 0.035932, -0.049329, -0.012144, 0.000808, 0.020055, 0.000836, 0.063925, 0.067268
#*# 	0.109049, 0.064761, -0.002089, -0.010027, -0.038466, -0.048076, -0.021754, -0.006267, -0.004178, 0.014623, 0.050555
#*# 	0.134536, 0.113645, 0.043035, 0.005432, -0.020891, 0.011699, -0.003342, 0.009192, 0.019219, -0.017130, 0.005014
#*# 	0.206817, 0.126179, 0.083145, 0.090248, 0.044706, -0.012952, -0.030500, -0.042199, -0.033007, -0.009610, -0.061001
#*# 	0.182166, 0.197208, 0.141221, 0.087741, 0.038439, 0.020055, -0.022144, -0.058076, -0.050555, -0.048466, -0.081473
#*# 	0.226872, 0.166707, 0.104871, 0.037185, -0.010863, -0.045542, -0.059747, -0.077713, -0.086069, -0.085652, -0.113227
#*# x_count = 11
#*# y_count = 11
#*# mesh_x_pps = 2
#*# mesh_y_pps = 2
#*# algo = bicubic
#*# tension = 0.2
#*# min_x = 10.0
#*# max_x = 290.0
#*# min_y = 10.0
#*# max_y = 290.0
#*#
#*# [heater_bed]
#*# control = pid
#*# pid_kp = 47.270
#*# pid_ki = 2.481
#*# pid_kd = 225.126
#*#
#*# [input_shaper]
#*# shaper_type_x = mzv
#*# shaper_freq_x = 72.2
#*# shaper_type_y = mzv
#*# shaper_freq_y = 48.8
