Prusa-MMU-Private
PrusaMultiMaterialUpgradev3firmwareforMK3SMK4
config.h
Go to the documentation of this file.
1 #pragma once
3 #include <stdint.h>
4 #include "axis.h"
5 
7 
8 //#define DEBUG_FINDA
10 //#define DEBUG_LOGIC
11 
13 //#define DEBUG_MODULES
14 
16 //#define DEBUG_HAL
17 
19 namespace config {
20 
24 static constexpr const uint8_t toolCount = 5U;
25 static_assert(toolCount < 15, "Up to 14 valid slots (+1 parking) is supported in EEPROM storage");
26 
27 // Printer's filament sensor setup
28 static constexpr const uint16_t fsensorDebounceMs = 2;
29 
30 // LEDS
35 static constexpr uint16_t ledBlinkPeriodMs = 1024U;
36 static_assert(ledBlinkPeriodMs == 256 || ledBlinkPeriodMs == 512 || ledBlinkPeriodMs == 1024 || ledBlinkPeriodMs == 2048, "LED blink period should be a power of 2");
37 
38 // FINDA setup
39 static constexpr const uint16_t findaDebounceMs = 100;
40 
41 // Buttons setup
42 static constexpr const uint8_t buttonCount = 3;
43 static constexpr const uint16_t buttonsDebounceMs = 20;
44 static constexpr const uint16_t buttonADCLimits[buttonCount][2] = { { 0, 50 }, { 80, 100 }, { 160, 180 } };
45 static constexpr const uint16_t buttonADCMaxValue = 1023;
46 static constexpr const uint8_t buttonsADCIndex = 5;
47 
48 // VCC measurement setup
49 static constexpr const uint8_t VCCADCIndex = 30;
50 static constexpr const uint16_t VCCADCThreshold = 274;
54 static constexpr const uint8_t VCCADCReadCnt = 10;
55 
56 // Motion and planning
57 
59 static constexpr uint8_t dropSegments = 0;
60 
62 static constexpr uint16_t maxStepFrequency = 40000;
63 
65 static constexpr uint16_t minStepRate = 120;
66 
68 static constexpr uint8_t blockBufferSize = 4;
69 
71 static constexpr uint8_t stepTimerFrequencyDivider = 8;
72 
76 static constexpr uint16_t stepTimerQuantum = 256; // 256 = 128us
77 
79 static constexpr uint8_t feedToBondtechMaxRetries = 2;
80 
82 static constexpr U_mm pulleyToCuttingEdge = 33.0_mm;
85 static constexpr U_mm filamentMinLoadedToMMU = 20.0_mm;
86 static constexpr U_mm ejectFromCuttingEdge = 40.0_mm;
87 static constexpr U_mm cuttingEdgeRetract = 5.0_mm;
88 static constexpr U_mm cuttingEdgeToFinda = 18.5_mm;
89 static constexpr U_mm findaTriggerDistance = 4.5_mm;
90 static constexpr U_mm cuttingEdgeToFindaMidpoint = 22.85_mm;
91 static constexpr U_mm findaToCoupler = 12.0_mm;
92 static constexpr U_mm couplerToBowden = 3.5_mm;
93 
94 // Min, max and default bowden length setup
95 static constexpr U_mm defaultBowdenLength = 360.0_mm;
96 static constexpr U_mm minimumBowdenLength = 341.0_mm;
97 static constexpr U_mm maximumBowdenLength = 1000.0_mm;
98 static_assert(minimumBowdenLength.v <= defaultBowdenLength.v);
99 static_assert(maximumBowdenLength.v > defaultBowdenLength.v);
100 
102 static constexpr U_mm maximumFeedToFinda = feedToFinda + 20.0_mm;
103 static constexpr U_mm pulleyHelperMove = 10.0_mm;
104 static constexpr U_mm cutLength = 8.0_mm;
105 static constexpr U_mm fsensorToNozzle = 30.0_mm;
106 static constexpr U_mm fsensorToNozzleAvoidGrind = 5.0_mm;
108 static constexpr U_mm fsensorUnloadCheckDistance = 40.0_mm;
109 
111 static constexpr AxisConfig pulley = {
112  .dirOn = false,
113  .mRes = MRes_8,
114  .iRun = 13,
115  .iHold = 0,
116  .stealth = false,
117  .stepsPerUnit = (200 * 8 / 19.147274),
118  .sg_thrs = 8,
119 };
120 
122 static constexpr PulleyLimits pulleyLimits = {
123  .lenght = 1000.0_mm, // TODO
124  .jerk = 4.0_mm_s,
125  .accel = 800.0_mm_s2,
126 };
127 
128 static constexpr U_mm_s pulleyUnloadFeedrate = 95._mm_s;
131 static constexpr U_mm_s pulleyLoadFeedrate = 95._mm_s;
132 static constexpr U_mm_s pulleySlowFeedrate = 20._mm_s;
134 
136 static constexpr AxisConfig selector = {
137  .dirOn = true,
138  .mRes = MRes_8,
139  .iRun = 31,
140  .iHold = 0,
141  .stealth = false,
142  .stepsPerUnit = (200 * 8 / 8.),
143  .sg_thrs = 3,
144 };
145 
146 static constexpr uint8_t selectorCutIRun = 40;
147 
149 static constexpr SelectorLimits selectorLimits = {
150  .lenght = 75.0_mm, // TODO how does this relate to SelectorOffsetFromMin?
151  .jerk = 1.0_mm_s,
152  .accel = 200.0_mm_s2,
153 };
154 
155 static constexpr U_mm SelectorSlotDistance = 14.0_mm;
156 static constexpr U_mm SelectorOffsetFromMax = 1.0_mm;
157 static constexpr U_mm SelectorOffsetFromMin = 75.5_mm;
158 
162 static constexpr U_mm selectorSlotPositions[toolCount + 1] = {
163 
165  SelectorOffsetFromMax + 0 * SelectorSlotDistance,
166  SelectorOffsetFromMax + 1 * SelectorSlotDistance,
167  SelectorOffsetFromMax + 2 * SelectorSlotDistance,
168  SelectorOffsetFromMax + 3 * SelectorSlotDistance,
169  SelectorOffsetFromMax + 4 * SelectorSlotDistance,
170  SelectorOffsetFromMax + 5 * SelectorSlotDistance
171 
173  // SelectorOffsetFromMin - 1.0_mm - 0 * SelectorSlotDistance, ///75.5_mm - 1.0_mm - 0 * 14.0_mm = 74.5_mm
174  // SelectorOffsetFromMin - 1.0_mm - 1 * SelectorSlotDistance, ///75.5_mm - 1.0_mm - 1 * 14.0_mm = 60.5_mm
175  // SelectorOffsetFromMin - 1.0_mm - 2 * SelectorSlotDistance, ///75.5_mm - 1.0_mm - 2 * 14.0_mm = 46.5_mm
176  // SelectorOffsetFromMin - 1.0_mm - 3 * SelectorSlotDistance, ///75.5_mm - 1.0_mm - 3 * 14.0_mm = 32.5_mm
177  // SelectorOffsetFromMin - 1.0_mm - 4 * SelectorSlotDistance, ///75.5_mm - 1.0_mm - 4 * 14.0_mm = 18.5_mm
178  // SelectorOffsetFromMin - 1.0_mm - 5 * SelectorSlotDistance ///75.5_mm - 1.0_mm - 5 * 14.0_mm = 4.5_mm
179 };
180 
181 static constexpr U_mm_s selectorFeedrate = 45._mm_s;
182 static constexpr U_mm_s selectorHomingFeedrate = 30._mm_s;
184 
186 static constexpr AxisConfig idler = {
187  .dirOn = true,
188  .mRes = MRes_16,
189  .iRun = 31,
190  .iHold = 5,
191  .stealth = false,
192  .stepsPerUnit = (200 * 16 / 360.),
193  .sg_thrs = 7,
194 };
195 
197 static constexpr IdlerLimits idlerLimits = {
198  .lenght = 225.0_deg,
199  .jerk = 0.1_deg_s,
200  .accel = 500.0_deg_s2,
201 };
202 
203 static constexpr U_deg IdlerSlotDistance = 40.0_deg;
204 static constexpr U_deg IdlerOffsetFromHome = 18.0_deg;
205 
208 static constexpr U_deg idlerSlotPositions[toolCount + 1] = {
209  IdlerOffsetFromHome + 5 * IdlerSlotDistance,
210  IdlerOffsetFromHome + 4 * IdlerSlotDistance,
211  IdlerOffsetFromHome + 3 * IdlerSlotDistance,
212  IdlerOffsetFromHome + 2 * IdlerSlotDistance,
213  IdlerOffsetFromHome + 1 * IdlerSlotDistance,
215 };
216 
219  IdlerOffsetFromHome + 4.75F * IdlerSlotDistance,
220  IdlerOffsetFromHome + 3.75F * IdlerSlotDistance,
221  IdlerOffsetFromHome + 2.75F * IdlerSlotDistance,
222  IdlerOffsetFromHome + 1.75F * IdlerSlotDistance,
223  IdlerOffsetFromHome + 0.75F * IdlerSlotDistance,
225 };
226 
227 static constexpr U_deg idlerParkPositionDelta = -IdlerSlotDistance + 5.0_deg / 2; // TODO verify
228 
229 static constexpr U_deg_s idlerFeedrate = 300._deg_s;
230 static constexpr U_deg_s idlerHomingFeedrate = 265._deg_s;
232 
233 // TMC2130 setup
234 
235 // static constexpr int8_t tmc2130_sg_thrs = 3;
236 // static_assert(tmc2130_sg_thrs >= -64 && tmc2130_sg_thrs <= 63, "tmc2130_sg_thrs out of range");
237 
238 static constexpr uint32_t tmc2130_coolStepThreshold = 450;
239 static_assert(tmc2130_coolStepThreshold <= 0xfffff, "tmc2130_coolStepThreshold out of range");
240 
241 static constexpr uint32_t tmc2130_PWM_AMPL = 240;
242 static_assert(tmc2130_PWM_AMPL <= 255, "tmc2130_PWM_AMPL out of range");
243 
244 static constexpr uint32_t tmc2130_PWM_GRAD = 4;
245 static_assert(tmc2130_PWM_GRAD <= 255, "tmc2130_PWM_GRAD out of range");
246 
247 static constexpr uint32_t tmc2130_PWM_FREQ = 0;
248 static_assert(tmc2130_PWM_FREQ <= 3, "tmc2130_PWM_GRAD out of range");
249 
250 static constexpr uint32_t tmc2130_PWM_AUTOSCALE = 1;
251 static_assert(tmc2130_PWM_AUTOSCALE <= 1, "tmc2130_PWM_AUTOSCALE out of range");
252 
258 static constexpr uint32_t tmc2130_freewheel = 1;
259 static_assert(tmc2130_PWM_AUTOSCALE <= 3, "tmc2130_freewheel out of range");
260 
261 } // namespace config
Define Debug mode to add additional serial output.
Definition: axis.h:6
static constexpr U_deg idlerSlotPositions[toolCount+1]
Idler offset from home to slots.
Definition: config.h:208
static constexpr const uint16_t VCCADCThreshold
Definition: config.h:50
static constexpr U_mm selectorSlotPositions[toolCount+1]
Selector offset from home min to slot 0.
Definition: config.h:162
static constexpr AxisConfig selector
End: Pulley axis configuration.
Definition: config.h:136
static constexpr uint32_t tmc2130_coolStepThreshold
End: Idler configuration.
Definition: config.h:238
static constexpr IdlerLimits idlerLimits
Idler motion limits.
Definition: config.h:197
static constexpr const uint16_t buttonADCMaxValue
used in unit tests
Definition: config.h:45
static constexpr U_deg IdlerOffsetFromHome
Idler distance between two slots.
Definition: config.h:204
static constexpr U_mm SelectorOffsetFromMax
Selector distance between two slots.
Definition: config.h:156
static constexpr U_mm maximumBowdenLength
~341.0_mm - Minimum bowden length.
Definition: config.h:97
static constexpr U_mm cuttingEdgeToFinda
Cutting retraction distance (filament should be flush with outlet)
Definition: config.h:88
static constexpr U_mm findaToCoupler
Cutting edge to Midpoint of FINDA should be 22.85_mm.
Definition: config.h:91
static constexpr U_mm_s pulleyLoadFeedrate
Definition: config.h:131
static constexpr uint8_t blockBufferSize
Size for the motion planner block buffer size.
Definition: config.h:68
static constexpr U_mm minimumBowdenLength
~360.0_mm - Default Bowden length.
Definition: config.h:96
static constexpr U_mm fsensorUnloadCheckDistance
Check the state of FSensor after this amount of filament got (hopefully) pulled out while unloading.
Definition: config.h:108
static constexpr SelectorLimits selectorLimits
Selector motion limits.
Definition: config.h:149
static constexpr U_mm couplerToBowden
FINDA Coupler side to coupler screw.
Definition: config.h:92
static constexpr const uint16_t buttonsDebounceMs
tuned with a pack of highly trained monkeys :)
Definition: config.h:43
static constexpr uint16_t maxStepFrequency
Max step frequency 40KHz.
Definition: config.h:62
static constexpr U_deg idlerIntermediateSlotPositions[toolCount+1]
Intermediate positions for Idler's slots: 0-4 are the real ones, the 5th index is the idle position.
Definition: config.h:218
static constexpr const uint8_t VCCADCReadCnt
Number of ADC reads to perform, only the last one being used.
Definition: config.h:54
static constexpr U_mm maximumFeedToFinda
allow for some safety margin to load to FINDA
Definition: config.h:102
static constexpr AxisConfig idler
End: Selector configuration.
Definition: config.h:186
static constexpr U_mm feedToFinda
~1000.0_mm - Maximum bowden length.
Definition: config.h:101
static constexpr U_mm filamentMinLoadedToMMU
Definition: config.h:85
static constexpr U_mm cuttingEdgeRetract
Eject should ignore FilamentMinLoadedToMMU and retract.
Definition: config.h:87
static constexpr uint16_t minStepRate
Minimum stepping rate 120Hz.
Definition: config.h:65
static constexpr uint8_t dropSegments
Do not plan moves equal or shorter than the requested steps.
Definition: config.h:59
static constexpr U_mm defaultBowdenLength
FINDA Coupler screw to bowden mmu side (in coupling).
Definition: config.h:95
static constexpr uint16_t ledBlinkPeriodMs
Definition: config.h:35
static constexpr U_mm pulleyToCuttingEdge
Distances.
Definition: config.h:82
static constexpr PulleyLimits pulleyLimits
Pulley motion limits.
Definition: config.h:122
static constexpr U_mm SelectorOffsetFromMin
Selector offset from home max to slot 0.
Definition: config.h:157
static constexpr U_mm cuttingEdgeToFindaMidpoint
FINDA trigger distance +1.0_mm tolerance.
Definition: config.h:90
static constexpr U_mm ejectFromCuttingEdge
Limit of retraction.
Definition: config.h:86
static constexpr uint8_t stepTimerFrequencyDivider
Step timer frequency divider (F = F_CPU / divider)
Definition: config.h:71
static constexpr AxisConfig pulley
Begin: Pulley axis configuration.
Definition: config.h:111
static constexpr U_mm findaTriggerDistance
Cutting edge to FINDA MMU side -1mm tolerance should be ~18.5. FINDA shouldn't trigger here.
Definition: config.h:89
static constexpr uint8_t feedToBondtechMaxRetries
Max retries of FeedToBondtech used in LoadFilament.
Definition: config.h:79
static constexpr uint8_t selectorCutIRun
660mA
Definition: config.h:146
static constexpr const uint8_t VCCADCIndex
ADC index of scaled VCC input.
Definition: config.h:49
static constexpr const uint8_t buttonsADCIndex
ADC index of buttons input.
Definition: config.h:46
static constexpr uint32_t tmc2130_freewheel
Definition: config.h:258
static constexpr U_mm fsensorToNozzle
~20mm from MK4's filament sensor through extruder gears into nozzle
Definition: config.h:105
static constexpr uint16_t stepTimerQuantum
Definition: config.h:76
static constexpr const uint8_t toolCount
Definition: config.h:24
static constexpr U_mm pulleyHelperMove
Helper move for Load/Unload error states - when the MMU should slowly move the filament a bit.
Definition: config.h:103
static constexpr const uint8_t buttonCount
number of buttons currently supported
Definition: config.h:42
Axis configuration data.
Definition: axis.h:24
bool dirOn
direction ON state (for inversion)
Definition: axis.h:25
Phisical limits for an axis.
Definition: axis.h:47
Unit< long double, B, Lenght > lenght
Longest move that can be performed by the axis.
Definition: axis.h:49
Generic unit type for compile-time conformability testing.
Definition: unit.h:42