# WARNING. THIS FILE IS GENERATED BY THE RATOS CONFIGURATOR.
# CHANGES YOU MAKE HERE WILL BE OVERWRITTEN. KEEP YOUR CHANGES IN PRINTER.CFG.
# Config generated for Rat Rig V-Core 3 300
# Documentation: https://os.ratrig.com

#############################################################################################################
### CONTROLBOARD & TOOLBOARD
#############################################################################################################
[include RatOS/boards/rpi/config.cfg]

[board_pins btt-octopus-11]
aliases:
	#----------------------------------------------- X motor pins -----------------------------------------------
	# Assigned to slot: "MOTOR 0"
	#------------------------------------------------------------------------------------------------------------
	x_step_pin=PF13,
	x_dir_pin=PF12,
	x_enable_pin=PF14,
	x_uart_pin=PC4,
	x_diag_pin=PG6,
	x_endstop_pin=PG6,
	#----------------------------------------------- Y motor pins -----------------------------------------------
	# Assigned to slot: "MOTOR 1"
	#------------------------------------------------------------------------------------------------------------
	y_step_pin=PG0,
	y_dir_pin=PG1,
	y_enable_pin=PF15,
	y_uart_pin=PD11,
	y_diag_pin=PG9,
	y_endstop_pin=PG9,
	#----------------------------------------------- Z motor pins -----------------------------------------------
	# Assigned to slot: "MOTOR 5"
	#------------------------------------------------------------------------------------------------------------
	z0_step_pin=PC13,
	z0_dir_pin=PF0,
	z0_enable_pin=PF1,
	z0_uart_pin=PE4,
	z0_diag_pin=PG13,
	#---------------------------------------------- Z1 motor pins -----------------------------------------------
	# Assigned to slot: "MOTOR 6"
	#------------------------------------------------------------------------------------------------------------
	z1_step_pin=PE2,
	z1_dir_pin=PE3,
	z1_enable_pin=PD4,
	z1_uart_pin=PE1,
	z1_diag_pin=PG14,
	#---------------------------------------------- Z2 motor pins -----------------------------------------------
	# Assigned to slot: "MOTOR 7"
	#------------------------------------------------------------------------------------------------------------
	z2_step_pin=PE6,
	z2_dir_pin=PA14,
	z2_enable_pin=PE0,
	z2_uart_pin=PD3,
	z2_diag_pin=PG15,
	#------------------------------------------- EXTRUDER motor pins --------------------------------------------
	e_step_pin=PF11,
	e_dir_pin=PG3,
	e_enable_pin=PG5,
	e_uart_pin=PC6,
	#----------------------------------------------- GENERAL PINS -----------------------------------------------
	e_heater_pin=PA2,
	e_sensor_pin=PF4,
	e_power_draw_pin=null,
	stepper_spi_mosi_pin=PA7,
	stepper_spi_miso_pin=PA6,
	stepper_spi_sclk_pin=PA5,
	adxl345_cs_pin=PA15,
	bltouch_sensor_pin=PB7,
	bltouch_control_pin=PB6,
	probe_pin=PB7,
	fan_part_cooling_pin=PA8,
	fan_toolhead_cooling_pin=PE5,
	fan_controller_board_pin=PD12,
	heater_bed_heating_pin=PA1,
	heater_bed_sensor_pin=PF3,
	4p_fan_part_cooling_pin=null,
	4p_fan_part_cooling_tach_pin=null,
	4p_fan_part_cooling_enable_pin=null,
	4p_toolhead_cooling_pin=null,
	4p_toolhead_cooling_tach_pin=null,
	4p_controller_board_pin=null,
	4p_controller_board_tach_pin=null,
	run_led_pin=null,
	rgb_led_data_pin=null,
	filament_sensor_runout_pin=PG15,
	filament_sensor_motion_pin=PG14,
	ratrig_vaoc_probe_pin=PG10,
	ratrig_vaoc_led_pin=PB0,
	ratrig_vaoc_fan_pin=PD13,
	chamber_lighting_pin=PB11,
	chamber_filter_4p_fan_pin=PD14,
	chamber_filter_4p_fan_enable_pin=PD15

[mcu]
serial: /dev/RatOS/btt-octopus-11

[temperature_sensor Octopus_V1.1_F446]
sensor_type: temperature_mcu

[adxl345 controlboard]
cs_pin: PA15
spi_bus: spi3

[board_pins toolboard_t0]
mcu: toolboard_t0
aliases:
	#------------------------------------------- EXTRUDER motor pins --------------------------------------------
	e_step_pin=PD0,
	e_dir_pin=PD1,
	e_enable_pin=PD2,
	e_uart_pin=PA15,
	#----------------------------------------------- GENERAL PINS -----------------------------------------------
	e_heater_pin=PB13,
	e_sensor_pin=PA3,
	e_power_draw_pin=null,
	stepper_spi_mosi_pin=null,
	stepper_spi_miso_pin=null,
	stepper_spi_sclk_pin=null,
	adxl345_cs_pin=PB12,
	bltouch_sensor_pin=PB8,
	bltouch_control_pin=PB9,
	probe_pin=PB9,
	fan_part_cooling_pin=PA0,
	fan_toolhead_cooling_pin=PA1,
	fan_controller_board_pin=null,
	heater_bed_heating_pin=null,
	heater_bed_sensor_pin=null,
	4p_fan_part_cooling_pin=null,
	4p_fan_part_cooling_tach_pin=null,
	4p_fan_part_cooling_enable_pin=null,
	4p_toolhead_cooling_pin=null,
	4p_toolhead_cooling_tach_pin=null,
	4p_controller_board_pin=null,
	4p_controller_board_tach_pin=null,
	run_led_pin=null,
	rgb_led_data_pin=null,
	filament_sensor_runout_pin=PB4,
	filament_sensor_motion_pin=PB3,
	ratrig_vaoc_probe_pin=null,
	ratrig_vaoc_led_pin=null,
	ratrig_vaoc_fan_pin=null,
	chamber_lighting_pin=null,
	chamber_filter_4p_fan_pin=null,
	chamber_filter_4p_fan_enable_pin=null

[mcu toolboard_t0]
serial: /dev/RatOS/btt-ebb42-12-t0

[temperature_sensor EBB42_v1.2]
sensor_type: temperature_mcu
sensor_mcu: toolboard_t0

[adxl345 toolboard_t0]
axes_map: x, z, y # Assumes back-facing vertical toolboard mounting
cs_pin: toolboard_t0:PB12
spi_software_mosi_pin: toolboard_t0:PB11
spi_software_miso_pin: toolboard_t0:PB2
spi_software_sclk_pin: toolboard_t0:PB10

#############################################################################################################
### BASE SETUP
#############################################################################################################
[include RatOS/homing.cfg]
[include RatOS/macros.cfg]
[include RatOS/shell-macros.cfg]
[include RatOS/printers/v-core-3/v-core-3.cfg]
[include RatOS/printers/v-core-3/macros.cfg]
[include RatOS/printers/v-core-3/300.cfg]

# Extruder
# T0 Orbiter 2 definition (from RatOS/extruders/orbiter-2.cfg)
[extruder]
rotation_distance: 4.63
full_steps_per_rotation: 200
filament_diameter: 1.750
max_extrude_only_velocity: 60

[firmware_retraction]
retract_speed: 60
unretract_extra_length: 0
unretract_speed: 60

# Hotend
# T0 Phaetus Rapido UHF definition (from RatOS/hotends/rapido-uhf.cfg)
[extruder]
max_extrude_only_distance: 200
nozzle_diameter: 0.6
heater_pin: toolboard_t0:PB13
sensor_type: PT1000
pullup_resistor: 2200
sensor_pin: toolboard_t0:PA3
min_extrude_temp: 170
min_temp: 0
max_temp: 285
pressure_advance: 0.03

[firmware_retraction]
retract_length: 0.5

# ADXL345 resonance testing configuration
[resonance_tester]
accel_chip_x: adxl345 toolboard_t0
accel_chip_y: adxl345 toolboard_t0
probe_points:
	150,150,20

#############################################################################################################
### STEPPER MOTORS, DRIVERS & SPEED LIMITS
#############################################################################################################
#---------------------------------------------------- X -----------------------------------------------------
# The A motor in the CoreXY system, located at the rear left of the printer
# Connected to MOTOR 0 on BIGTREETECH Octopus V1.1 F446
# Driver: BTT TMC2209 v1.3
# Motor: LDO-42STH48-2504AC
# Voltage: 24
#------------------------------------------------------------------------------------------------------------
[tmc2209 stepper_x]
stealthchop_threshold: 1
interpolate: False
uart_pin: PC4
run_current: 1.6
driver_TBL: 2
driver_TOFF: 3
driver_HEND: 0
driver_HSTRT: 6
sense_resistor: 0.11

[stepper_x]
step_pin: PF13
dir_pin: PF12
enable_pin: !PF14
microsteps: 64
full_steps_per_rotation: 200
rotation_distance: 40
homing_speed: 50

#---------------------------------------------------- Y -----------------------------------------------------
# The B motor in the CoreXY system, located at the rear right of the printer
# Connected to MOTOR 1 on BIGTREETECH Octopus V1.1 F446
# Driver: BTT TMC2209 v1.3
# Motor: LDO-42STH48-2504AC
# Voltage: 24
#------------------------------------------------------------------------------------------------------------
[tmc2209 stepper_y]
stealthchop_threshold: 1
interpolate: False
uart_pin: PD11
run_current: 1.6
driver_TBL: 2
driver_TOFF: 3
driver_HEND: 0
driver_HSTRT: 6
sense_resistor: 0.11

[stepper_y]
step_pin: PG0
dir_pin: PG1
enable_pin: !PF15
microsteps: 64
full_steps_per_rotation: 200
rotation_distance: 40
homing_speed: 50

#---------------------------------------------------- Z -----------------------------------------------------
# The left Z motor for the kinematic bed
# Connected to MOTOR 5 on BIGTREETECH Octopus V1.1 F446
# Driver: BTT TMC2209 v1.3
# Motor: LDO-42STH48-2504AC
# Voltage: 24
#------------------------------------------------------------------------------------------------------------
[tmc2209 stepper_z]
stealthchop_threshold: 1
interpolate: False
uart_pin: PE4
run_current: 1.6
driver_TBL: 2
driver_TOFF: 3
driver_HEND: 0
driver_HSTRT: 6
sense_resistor: 0.11

[stepper_z]
step_pin: PC13
dir_pin: PF0
enable_pin: !PF1
microsteps: 64
full_steps_per_rotation: 200
rotation_distance: 4
position_min: -5
homing_speed: 10
endstop_pin: probe:z_virtual_endstop

#---------------------------------------------------- Z1 ----------------------------------------------------
# The rear Z motor for the kinematic bed
# Connected to MOTOR 6 on BIGTREETECH Octopus V1.1 F446
# Driver: BTT TMC2209 v1.3
# Motor: LDO-42STH48-2504AC
# Voltage: 24
#------------------------------------------------------------------------------------------------------------
[tmc2209 stepper_z1]
stealthchop_threshold: 1
interpolate: False
uart_pin: PE1
run_current: 1.6
driver_TBL: 2
driver_TOFF: 3
driver_HEND: 0
driver_HSTRT: 6
sense_resistor: 0.11

[stepper_z1]
step_pin: PE2
dir_pin: PE3
enable_pin: !PD4
microsteps: 64
full_steps_per_rotation: 200
rotation_distance: 4

#---------------------------------------------------- Z2 ----------------------------------------------------
# The right Z motor for the kinematic bed
# Connected to MOTOR 7 on BIGTREETECH Octopus V1.1 F446
# Driver: BTT TMC2209 v1.3
# Motor: LDO-42STH48-2504AC
# Voltage: 24
#------------------------------------------------------------------------------------------------------------
[tmc2209 stepper_z2]
stealthchop_threshold: 1
interpolate: False
uart_pin: PD3
run_current: 1.6
driver_TBL: 2
driver_TOFF: 3
driver_HEND: 0
driver_HSTRT: 6
sense_resistor: 0.11

[stepper_z2]
step_pin: PE6
dir_pin: PA14
enable_pin: !PE0
microsteps: 64
full_steps_per_rotation: 200
rotation_distance: 4

#------------------------------------------------- EXTRUDER -------------------------------------------------
# The extruder motor used for pushing filament through the toolhead
# Connected to EBB42 v1.2
# Driver: BTT TMC2209 v1.3
# Motor: LDO-36STH20-1004AHG
# Voltage: 24
#------------------------------------------------------------------------------------------------------------
[tmc2209 extruder]
stealthchop_threshold: 1
interpolate: False
uart_pin: toolboard_t0:PA15
run_current: 0.707
driver_TBL: 0
driver_TOFF: 4
driver_HEND: 6
driver_HSTRT: 7
sense_resistor: 0.11

[extruder]
step_pin: toolboard_t0:PD0
dir_pin: toolboard_t0:PD1
enable_pin: !toolboard_t0:PD2
microsteps: 64
full_steps_per_rotation: 200
rotation_distance: 4.63


[printer]
max_velocity: 800
max_accel: 10000
minimum_cruise_ratio: 0.5
max_z_velocity: 50
max_z_accel: 600
square_corner_velocity: 5

[gcode_macro RatOS]
variable_macro_travel_speed: 600
variable_macro_travel_accel: 8000

[bed_mesh]
speed: 600

[z_tilt]
speed: 600


#############################################################################################################
### HOMING
#############################################################################################################
[include RatOS/z-probe/beacon.cfg]


# Physical X endstop configuration
[stepper_x]
endstop_pin: toolboard_t0:PB6
[gcode_macro RatOS]
variable_homing_x: "endstop"

# Physical Y endstop configuration
[stepper_y]
endstop_pin: PG9
[gcode_macro RatOS]
variable_homing_y: "endstop"


#############################################################################################################
### FANS
#############################################################################################################
# Part cooling fan
[fan]
# 4-pin fan connected to 2-pin header on Octopus V1.1 F446 - digital pwm
pin: !PA8
cycle_time:  0.00004

# Hotend cooling fan
[heater_fan toolhead_cooling_fan]
heater: extruder
shutdown_speed: 1
# 2-pin fan connected to 2-pin header on T0 (EBB42 v1.2) - input voltage pwm
pin: toolboard_t0:PA1

# Controller cooling fan
[controller_fan controller_fan]
# 2-pin fan connected to 2-pin header on Octopus V1.1 F446 - input voltage pwm
pin: PD12

#############################################################################################################
### ACCESSORIES
#############################################################################################################

# Filament sensors
# orbiter-smart-sensor connected to controlboard
[filament_switch_sensor toolhead_filament_sensor_t0]
pause_on_runout: False
event_delay: 1.0
switch_pin: ^PG15
runout_gcode:
	_ON_TOOLHEAD_FILAMENT_SENSOR_RUNOUT TOOLHEAD=0
insert_gcode:
	_ON_TOOLHEAD_FILAMENT_SENSOR_INSERT TOOLHEAD=0

[gcode_button filament_sensor_button]
pin: ^PG14
press_gcode:
    {% if (printer.print_stats.state == "printing") %}
        _ON_TOOLHEAD_FILAMENT_SENSOR_CLOG TOOLHEAD=0
    {% else %}
        _ON_FILAMENT_SENSOR_BUTTON_PRESSED TOOLHEAD=0
    {% endif %}
release_gcode:
	# No action on release





#############################################################################################################
### MACRO CONFIGURATION
#############################################################################################################
[gcode_macro T0]
variable_join: 0
variable_remap: 0
variable_alert: ""
variable_filament_name: ""
variable_filament_type: ""
variable_filament_temp: 0
variable_runout_sensor: ""
variable_active: True
variable_color: "7bff33"                                          # Used in frontends
variable_hotend_type: "UHF"
variable_has_cht_nozzle: False
variable_cooling_position_to_nozzle_distance: 40                  # heatbreak length from cold zone to nozzle
variable_tooolhead_sensor_to_extruder_gear_distance: 15           # distance in mm from the sensor to the extruder gear
variable_extruder_gear_to_cooling_position_distance: 30           # distance in mm from the extruder gear to the end of the hotend cold zone
variable_filament_loading_nozzle_offset: -5
variable_filament_grabbing_length: 5
variable_filament_grabbing_speed: 1
variable_enable_insert_detection: True                            # enables filament sensor insert detection 
variable_enable_runout_detection: True                            # enables filament sensor runout detection 
variable_enable_clog_detection: True                              # enables filament sensor clog detection 
variable_unload_after_runout: True                                # unload filament after a runout has been detected
variable_purge_after_load: 0
variable_purge_before_unload: 0
variable_extruder_load_speed: 60
variable_filament_load_speed: 10
variable_standby: False
variable_temperature_offset: 0                                    # hotend temperature offset
variable_has_oozeguard: False                                     # toolhead has a oozeguard
variable_has_front_arm_nozzle_wiper: False                        # toolhead has front arm nozzle wipers
variable_toolhead_sensor_button_only_when_sensor_enabled: False   # if True, the toolhead sensor action button is only enabled when the sensor is enabled
variable_toolhead_detect_clog_only_when_sensor_enabled: True      # if True, toolhead sensor clog detection is only enabled when the sensor is enabled
variable_resume_after_insert: False                               # resumes the print after inserting new filament
gcode:
	{% set x = params.X|default(-1.0)|float %}
	{% set y = params.Y|default(-1.0)|float %}
	{% set z = params.Z|default(0.0)|float %}
	{% set s = params.S|default(1)|int %}
	{% if printer["gcode_macro _SELECT_TOOL"] is defined %}
		_SELECT_TOOL T=0 X={x} Y={y} Z={z} TOOLSHIFT={s}
	{% endif %}

# Macro variable overrides
[gcode_macro RatOS]
variable_bed_margin_x: [0, 0]
variable_bed_margin_y: [0, 0]
variable_x_driver_types: ["tmc2209"]
variable_x_axes: ["x"]
variable_y_driver_types: ["tmc2209"]
variable_y_axes: ["y"]
variable_z_driver_types: ["tmc2209", "tmc2209", "tmc2209"]
variable_z_axes: ["z", "z1", "z2"]

# Save variables
[save_variables]
filename: /home/pi/printer_data/config/ratos-variables.cfg