-
Notifications
You must be signed in to change notification settings - Fork 0
/
motors_sync.cfg
138 lines (126 loc) · 5.87 KB
/
motors_sync.cfg
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
# [gcode_macro _MOTORS_SYNC_VARIABLES]
# variable_accel_chip: 'mpu9250'
# gcode:
# [delayed_gcode _MOTORS_SYNC_CHECKS]
# initial_duration: 1
# gcode:
# {% if printer['gcode_macro _MOTORS_SYNC_VARIABLES'].accel_chip == '' %}
# {% if printer.configfile.config.resonance_tester.accel_chip %}
# {% set accel_chip = printer.configfile.config.resonance_tester.accel_chip %}
# {% else %}
# {% set accel_chip = adxl345 %}
# {% endif %}
# SET_GCODE_VARIABLE MACRO=_MOTORS_SYNC_VARIABLES VARIABLE=accel_chip VALUE={accel_chip|string}
# {% endif %}
# [gcode_shell_command motors_sync]
# command: bash scripts/motors_sync.sh
# timeout: 1
# verbose: False
# [gcode_macro MOTORS_SYNC]
# gcode:
# RUN_SHELL_COMMAND CMD=motors_sync
[gcode_macro _HOME_XY_AND_MOVE_TO_CENTER]
gcode:
{% if "xy" not in printer.toolhead.homed_axes %}
G28 X Y ; Home X and Y axes
{% endif %}
G0 X{printer.toolhead.axis_maximum.x / 2} Y{printer.toolhead.axis_maximum.y / 2} F7320 ; Move to the center
[gcode_macro MOVE_TO_CENTER]
gcode:
G0 X{printer.toolhead.axis_maximum.x / 2} Y{printer.toolhead.axis_maximum.y / 2} F7320 ; Move to the center
[gcode_macro _BUZZ_X1]
gcode:
SET_STEPPER_ENABLE STEPPER=stepper_x ENABLE=0
FORCE_MOVE STEPPER=stepper_x1 DISTANCE=1 VELOCITY=300 ACCEL=5000
FORCE_MOVE STEPPER=stepper_x1 DISTANCE=-2 VELOCITY=300 ACCEL=5000
{% for i in range(0, 80) %}
{% set distance_forward = 1 - 0.0125 * (i + 1) + 1 - 0.0125 * i %}
{% set distance_backward = -(1 - 0.0125 * (i + 1) + 1 - 0.0125 * i) + 0.0125 %}
FORCE_MOVE STEPPER=stepper_x1 DISTANCE={distance_forward} VELOCITY=300 ACCEL=5000
FORCE_MOVE STEPPER=stepper_x1 DISTANCE={distance_backward} VELOCITY=300 ACCEL=5000
{% endfor %}
G4 P3000
SET_STEPPER_ENABLE STEPPER=stepper_x ENABLE=1
[gcode_macro _BUZZ_Y1]
gcode:
SET_STEPPER_ENABLE STEPPER=stepper_y ENABLE=0
FORCE_MOVE STEPPER=stepper_y1 DISTANCE=1 VELOCITY=300 ACCEL=5000
FORCE_MOVE STEPPER=stepper_y1 DISTANCE=-2 VELOCITY=300 ACCEL=5000
{% for i in range(0, 80) %}
{% set distance_forward = 1 - 0.0125 * (i + 1) + 1 - 0.0125 * i %}
{% set distance_backward = -(1 - 0.0125 * (i + 1) + 1 - 0.0125 * i) + 0.0125 %}
FORCE_MOVE STEPPER=stepper_y1 DISTANCE={distance_forward} VELOCITY=300 ACCEL=5000
FORCE_MOVE STEPPER=stepper_y1 DISTANCE={distance_backward} VELOCITY=300 ACCEL=5000
{% endfor %}
G4 P3000
SET_STEPPER_ENABLE STEPPER=stepper_y ENABLE=1
[gcode_macro _ACTIVATE_AND_MEASURE_X]
gcode:
_BUZZ_X1
SET_STEPPER_ENABLE STEPPER=stepper_x ENABLE=0
ACCELEROMETER_MEASURE CHIP={printer['gcode_macro _MOTORS_SYNC_VARIABLES'].accel_chip}
SET_STEPPER_ENABLE STEPPER=stepper_x ENABLE=1
ACCELEROMETER_MEASURE CHIP={printer['gcode_macro _MOTORS_SYNC_VARIABLES'].accel_chip}
[gcode_macro _ACTIVATE_AND_MEASURE_Y]
gcode:
_BUZZ_Y1
SET_STEPPER_ENABLE STEPPER=stepper_y ENABLE=0
ACCELEROMETER_MEASURE CHIP={printer['gcode_macro _MOTORS_SYNC_VARIABLES'].accel_chip}
SET_STEPPER_ENABLE STEPPER=stepper_y ENABLE=1
ACCELEROMETER_MEASURE CHIP={printer['gcode_macro _MOTORS_SYNC_VARIABLES'].accel_chip}
[gcode_macro _STATIC_MEASURE]
gcode:
ACCELEROMETER_MEASURE CHIP={printer['gcode_macro _MOTORS_SYNC_VARIABLES'].accel_chip} NAME=stand_still
G4 P250
ACCELEROMETER_MEASURE CHIP={printer['gcode_macro _MOTORS_SYNC_VARIABLES'].accel_chip} NAME=stand_still
[gcode_macro _RESUME_PRINT]
gcode:
{% if printer['pause_resume'].is_paused|int == 1 %}
RESUME SYNC_MOTORS=1
{% endif %}
[gcode_macro MOTORS_SYNC]
gcode:
{% set axis = params.AXIS|default('xy')|string|lower %}
{% set accel_chip = params.ACCEL_CHIP|default('default')|string|lower %}
{% set steps_threshold = params.STEPS_THRESHOLD|default('default')|string|lower %}
{% set fast_threshold = params.FAST_THRESHOLD|default('default')|string|lower %}
{% set retry_tolerance = params.RETRY_TOLERANCE|default('default')|string|lower %}
{% set retries = params.THRESHOLD_RETRIES|default('default')|string|lower %}
{% if accel_chip == 'default' %}
{% if 'accel_chip' in printer.configfile.config.motors_sync %}
{% set accel_chip = printer.configfile.config.motors_sync.accel_chip %}
{% elif 'accel_chip' in printer.configfile.config.resonance_tester %}
{% set accel_chip = printer.configfile.config.resonance_tester.accel_chip %}
{% else %}
{action_raise_error('WARNING!!! Accelerometer not defined')}
{% endif %}
{% endif %}
{% if steps_threshold == 'default' %}
{% if 'steps_threshold' in printer.configfile.config.motors_sync %}
{% set steps_threshold = printer.configfile.config.motors_sync.steps_threshold %}
{% else %}
{% set steps_threshold = 999999 %}
{% endif %}
{% endif %}
{% if fast_threshold == 'default' %}
{% if 'fast_threshold' in printer.configfile.config.motors_sync %}
{% set fast_threshold = printer.configfile.config.motors_sync.fast_threshold %}
{% else %}
{% set fast_threshold = 999999 %}
{% endif %}
{% endif %}
{% if retry_tolerance == 'default' %}
{% if 'retry_tolerance' in printer.configfile.config.motors_sync %}
{% set retry_tolerance = printer.configfile.config.motors_sync.retry_tolerance %}
{% else %}
{% set retry_tolerance = 999999 %}
{% endif %}
{% endif %}
{% if retries == 'default' %}
{% if 'retries' in printer.configfile.config.motors_sync %}
{% set retries = printer.configfile.config.motors_sync.retries %}
{% else %}
{% set retries = 0 %}
{% endif %}
{% endif %}
SYNC_MOTORS AXIS={axis} ACCEL_CHIP={accel_chip} STEPS_THRESHOLD={steps_threshold} FAST_THRESHOLD={fast_threshold} RETRY_TOLERANCE={retry_tolerance} RETRIES={retries}