|
@@ -49,7 +49,7 @@ void I2CPositionEncoder::init(const uint8_t address, const AxisEnum axis) {
|
49
|
49
|
|
50
|
50
|
initialized = true;
|
51
|
51
|
|
52
|
|
- SERIAL_ECHOLNPGM("Setting up encoder on ", AS_CHAR(axis_codes[encoderAxis]), " axis, addr = ", address);
|
|
52
|
+ SERIAL_ECHOLNPGM("Setting up encoder on ", AS_CHAR(AXIS_CHAR(encoderAxis)), " axis, addr = ", address);
|
53
|
53
|
|
54
|
54
|
position = get_position();
|
55
|
55
|
}
|
|
@@ -67,7 +67,7 @@ void I2CPositionEncoder::update() {
|
67
|
67
|
/*
|
68
|
68
|
if (trusted) { //commented out as part of the note below
|
69
|
69
|
trusted = false;
|
70
|
|
- SERIAL_ECHOLNPGM("Fault detected on ", AS_CHAR(axis_codes[encoderAxis]), " axis encoder. Disengaging error correction until module is trusted again.");
|
|
70
|
+ SERIAL_ECHOLNPGM("Fault detected on ", AS_CHAR(AXIS_CHAR(encoderAxis)), " axis encoder. Disengaging error correction until module is trusted again.");
|
71
|
71
|
}
|
72
|
72
|
*/
|
73
|
73
|
return;
|
|
@@ -92,7 +92,7 @@ void I2CPositionEncoder::update() {
|
92
|
92
|
if (millis() - lastErrorTime > I2CPE_TIME_TRUSTED) {
|
93
|
93
|
trusted = true;
|
94
|
94
|
|
95
|
|
- SERIAL_ECHOLNPGM("Untrusted encoder module on ", AS_CHAR(axis_codes[encoderAxis]), " axis has been fault-free for set duration, reinstating error correction.");
|
|
95
|
+ SERIAL_ECHOLNPGM("Untrusted encoder module on ", AS_CHAR(AXIS_CHAR(encoderAxis)), " axis has been fault-free for set duration, reinstating error correction.");
|
96
|
96
|
|
97
|
97
|
//the encoder likely lost its place when the error occurred, so we'll reset and use the printer's
|
98
|
98
|
//idea of where it the axis is to re-initialize
|
|
@@ -172,7 +172,7 @@ void I2CPositionEncoder::update() {
|
172
|
172
|
float sumP = 0;
|
173
|
173
|
LOOP_L_N(i, I2CPE_ERR_PRST_ARRAY_SIZE) sumP += errPrst[i];
|
174
|
174
|
const int32_t errorP = int32_t(sumP * RECIPROCAL(I2CPE_ERR_PRST_ARRAY_SIZE));
|
175
|
|
- SERIAL_CHAR(axis_codes[encoderAxis]);
|
|
175
|
+ SERIAL_CHAR(AXIS_CHAR(encoderAxis));
|
176
|
176
|
SERIAL_ECHOLNPGM(" : CORRECT ERR ", errorP * planner.mm_per_step[encoderAxis], "mm");
|
177
|
177
|
babystep.add_steps(encoderAxis, -LROUND(errorP));
|
178
|
178
|
errPrstIdx = 0;
|
|
@@ -192,7 +192,7 @@ void I2CPositionEncoder::update() {
|
192
|
192
|
if (ABS(error) > I2CPE_ERR_CNT_THRESH * planner.settings.axis_steps_per_mm[encoderAxis]) {
|
193
|
193
|
const millis_t ms = millis();
|
194
|
194
|
if (ELAPSED(ms, nextErrorCountTime)) {
|
195
|
|
- SERIAL_CHAR(axis_codes[encoderAxis]);
|
|
195
|
+ SERIAL_CHAR(AXIS_CHAR(encoderAxis));
|
196
|
196
|
SERIAL_ECHOLNPGM(" : LARGE ERR ", error, "; diffSum=", diffSum);
|
197
|
197
|
errorCount++;
|
198
|
198
|
nextErrorCountTime = ms + I2CPE_ERR_CNT_DEBOUNCE_MS;
|
|
@@ -212,7 +212,7 @@ void I2CPositionEncoder::set_homed() {
|
212
|
212
|
homed = trusted = true;
|
213
|
213
|
|
214
|
214
|
#ifdef I2CPE_DEBUG
|
215
|
|
- SERIAL_CHAR(axis_codes[encoderAxis]);
|
|
215
|
+ SERIAL_CHAR(AXIS_CHAR(encoderAxis));
|
216
|
216
|
SERIAL_ECHOLNPGM(" axis encoder homed, offset of ", zeroOffset, " ticks.");
|
217
|
217
|
#endif
|
218
|
218
|
}
|
|
@@ -223,7 +223,7 @@ void I2CPositionEncoder::set_unhomed() {
|
223
|
223
|
homed = trusted = false;
|
224
|
224
|
|
225
|
225
|
#ifdef I2CPE_DEBUG
|
226
|
|
- SERIAL_CHAR(axis_codes[encoderAxis]);
|
|
226
|
+ SERIAL_CHAR(AXIS_CHAR(encoderAxis));
|
227
|
227
|
SERIAL_ECHOLNPGM(" axis encoder unhomed.");
|
228
|
228
|
#endif
|
229
|
229
|
}
|
|
@@ -231,7 +231,7 @@ void I2CPositionEncoder::set_unhomed() {
|
231
|
231
|
bool I2CPositionEncoder::passes_test(const bool report) {
|
232
|
232
|
if (report) {
|
233
|
233
|
if (H != I2CPE_MAG_SIG_GOOD) SERIAL_ECHOPGM("Warning. ");
|
234
|
|
- SERIAL_CHAR(axis_codes[encoderAxis]);
|
|
234
|
+ SERIAL_CHAR(AXIS_CHAR(encoderAxis));
|
235
|
235
|
serial_ternary(H == I2CPE_MAG_SIG_BAD, F(" axis "), F("magnetic strip "), F("encoder "));
|
236
|
236
|
switch (H) {
|
237
|
237
|
case I2CPE_MAG_SIG_GOOD:
|
|
@@ -252,7 +252,7 @@ float I2CPositionEncoder::get_axis_error_mm(const bool report) {
|
252
|
252
|
error = ABS(diff) > 10000 ? 0 : diff; // Huge error is a bad reading
|
253
|
253
|
|
254
|
254
|
if (report) {
|
255
|
|
- SERIAL_CHAR(axis_codes[encoderAxis]);
|
|
255
|
+ SERIAL_CHAR(AXIS_CHAR(encoderAxis));
|
256
|
256
|
SERIAL_ECHOLNPGM(" axis target=", target, "mm; actual=", actual, "mm; err=", error, "mm");
|
257
|
257
|
}
|
258
|
258
|
|
|
@@ -262,7 +262,7 @@ float I2CPositionEncoder::get_axis_error_mm(const bool report) {
|
262
|
262
|
int32_t I2CPositionEncoder::get_axis_error_steps(const bool report) {
|
263
|
263
|
if (!active) {
|
264
|
264
|
if (report) {
|
265
|
|
- SERIAL_CHAR(axis_codes[encoderAxis]);
|
|
265
|
+ SERIAL_CHAR(AXIS_CHAR(encoderAxis));
|
266
|
266
|
SERIAL_ECHOLNPGM(" axis encoder not active!");
|
267
|
267
|
}
|
268
|
268
|
return 0;
|
|
@@ -287,7 +287,7 @@ int32_t I2CPositionEncoder::get_axis_error_steps(const bool report) {
|
287
|
287
|
errorPrev = error;
|
288
|
288
|
|
289
|
289
|
if (report) {
|
290
|
|
- SERIAL_CHAR(axis_codes[encoderAxis]);
|
|
290
|
+ SERIAL_CHAR(AXIS_CHAR(encoderAxis));
|
291
|
291
|
SERIAL_ECHOLNPGM(" axis target=", target, "; actual=", encoderCountInStepperTicksScaled, "; err=", error);
|
292
|
292
|
}
|
293
|
293
|
|
|
@@ -657,7 +657,7 @@ void I2CPositionEncodersMgr::report_position(const int8_t idx, const bool units,
|
657
|
657
|
else {
|
658
|
658
|
if (noOffset) {
|
659
|
659
|
const int32_t raw_count = encoders[idx].get_raw_count();
|
660
|
|
- SERIAL_CHAR(axis_codes[encoders[idx].get_axis()], ' ');
|
|
660
|
+ SERIAL_CHAR(AXIS_CHAR(encoders[idx).get_axis()], ' ');
|
661
|
661
|
|
662
|
662
|
for (uint8_t j = 31; j > 0; j--)
|
663
|
663
|
SERIAL_ECHO((bool)(0x00000001 & (raw_count >> j)));
|
|
@@ -712,7 +712,7 @@ void I2CPositionEncodersMgr::change_module_address(const uint8_t oldaddr, const
|
712
|
712
|
// and enable it (it will likely have failed initialization on power-up, before the address change).
|
713
|
713
|
const int8_t idx = idx_from_addr(newaddr);
|
714
|
714
|
if (idx >= 0 && !encoders[idx].get_active()) {
|
715
|
|
- SERIAL_CHAR(axis_codes[encoders[idx].get_axis()]);
|
|
715
|
+ SERIAL_CHAR(AXIS_CHAR(encoders[idx).get_axis()]);
|
716
|
716
|
SERIAL_ECHOLNPGM(" axis encoder was not detected on printer startup. Trying again.");
|
717
|
717
|
encoders[idx].set_active(encoders[idx].passes_test(true));
|
718
|
718
|
}
|
|
@@ -814,7 +814,7 @@ void I2CPositionEncodersMgr::M860() {
|
814
|
814
|
|
815
|
815
|
if (I2CPE_idx == 0xFF) {
|
816
|
816
|
LOOP_LOGICAL_AXES(i) {
|
817
|
|
- if (!I2CPE_anyaxis || parser.seen_test(axis_codes[i])) {
|
|
817
|
+ if (!I2CPE_anyaxis || parser.seen_test(AXIS_CHAR(i))) {
|
818
|
818
|
const uint8_t idx = idx_from_axis(AxisEnum(i));
|
819
|
819
|
if ((int8_t)idx >= 0) report_position(idx, hasU, hasO);
|
820
|
820
|
}
|
|
@@ -841,7 +841,7 @@ void I2CPositionEncodersMgr::M861() {
|
841
|
841
|
|
842
|
842
|
if (I2CPE_idx == 0xFF) {
|
843
|
843
|
LOOP_LOGICAL_AXES(i) {
|
844
|
|
- if (!I2CPE_anyaxis || parser.seen(axis_codes[i])) {
|
|
844
|
+ if (!I2CPE_anyaxis || parser.seen(AXIS_CHAR(i))) {
|
845
|
845
|
const uint8_t idx = idx_from_axis(AxisEnum(i));
|
846
|
846
|
if ((int8_t)idx >= 0) report_status(idx);
|
847
|
847
|
}
|
|
@@ -869,7 +869,7 @@ void I2CPositionEncodersMgr::M862() {
|
869
|
869
|
|
870
|
870
|
if (I2CPE_idx == 0xFF) {
|
871
|
871
|
LOOP_LOGICAL_AXES(i) {
|
872
|
|
- if (!I2CPE_anyaxis || parser.seen(axis_codes[i])) {
|
|
872
|
+ if (!I2CPE_anyaxis || parser.seen(AXIS_CHAR(i))) {
|
873
|
873
|
const uint8_t idx = idx_from_axis(AxisEnum(i));
|
874
|
874
|
if ((int8_t)idx >= 0) test_axis(idx);
|
875
|
875
|
}
|
|
@@ -900,7 +900,7 @@ void I2CPositionEncodersMgr::M863() {
|
900
|
900
|
|
901
|
901
|
if (I2CPE_idx == 0xFF) {
|
902
|
902
|
LOOP_LOGICAL_AXES(i) {
|
903
|
|
- if (!I2CPE_anyaxis || parser.seen(axis_codes[i])) {
|
|
903
|
+ if (!I2CPE_anyaxis || parser.seen(AXIS_CHAR(i))) {
|
904
|
904
|
const uint8_t idx = idx_from_axis(AxisEnum(i));
|
905
|
905
|
if ((int8_t)idx >= 0) calibrate_steps_mm(idx, iterations);
|
906
|
906
|
}
|
|
@@ -976,7 +976,7 @@ void I2CPositionEncodersMgr::M865() {
|
976
|
976
|
|
977
|
977
|
if (!I2CPE_addr) {
|
978
|
978
|
LOOP_LOGICAL_AXES(i) {
|
979
|
|
- if (!I2CPE_anyaxis || parser.seen(axis_codes[i])) {
|
|
979
|
+ if (!I2CPE_anyaxis || parser.seen(AXIS_CHAR(i))) {
|
980
|
980
|
const uint8_t idx = idx_from_axis(AxisEnum(i));
|
981
|
981
|
if ((int8_t)idx >= 0) report_module_firmware(encoders[idx].get_address());
|
982
|
982
|
}
|
|
@@ -1007,7 +1007,7 @@ void I2CPositionEncodersMgr::M866() {
|
1007
|
1007
|
|
1008
|
1008
|
if (I2CPE_idx == 0xFF) {
|
1009
|
1009
|
LOOP_LOGICAL_AXES(i) {
|
1010
|
|
- if (!I2CPE_anyaxis || parser.seen(axis_codes[i])) {
|
|
1010
|
+ if (!I2CPE_anyaxis || parser.seen(AXIS_CHAR(i))) {
|
1011
|
1011
|
const uint8_t idx = idx_from_axis(AxisEnum(i));
|
1012
|
1012
|
if ((int8_t)idx >= 0) {
|
1013
|
1013
|
if (hasR)
|
|
@@ -1045,7 +1045,7 @@ void I2CPositionEncodersMgr::M867() {
|
1045
|
1045
|
|
1046
|
1046
|
if (I2CPE_idx == 0xFF) {
|
1047
|
1047
|
LOOP_LOGICAL_AXES(i) {
|
1048
|
|
- if (!I2CPE_anyaxis || parser.seen(axis_codes[i])) {
|
|
1048
|
+ if (!I2CPE_anyaxis || parser.seen(AXIS_CHAR(i))) {
|
1049
|
1049
|
const uint8_t idx = idx_from_axis(AxisEnum(i));
|
1050
|
1050
|
if ((int8_t)idx >= 0) {
|
1051
|
1051
|
const bool ena = onoff == -1 ? !encoders[I2CPE_idx].get_ec_enabled() : !!onoff;
|
|
@@ -1081,7 +1081,7 @@ void I2CPositionEncodersMgr::M868() {
|
1081
|
1081
|
|
1082
|
1082
|
if (I2CPE_idx == 0xFF) {
|
1083
|
1083
|
LOOP_LOGICAL_AXES(i) {
|
1084
|
|
- if (!I2CPE_anyaxis || parser.seen(axis_codes[i])) {
|
|
1084
|
+ if (!I2CPE_anyaxis || parser.seen(AXIS_CHAR(i))) {
|
1085
|
1085
|
const uint8_t idx = idx_from_axis(AxisEnum(i));
|
1086
|
1086
|
if ((int8_t)idx >= 0) {
|
1087
|
1087
|
if (newThreshold != -9999)
|
|
@@ -1115,7 +1115,7 @@ void I2CPositionEncodersMgr::M869() {
|
1115
|
1115
|
|
1116
|
1116
|
if (I2CPE_idx == 0xFF) {
|
1117
|
1117
|
LOOP_LOGICAL_AXES(i) {
|
1118
|
|
- if (!I2CPE_anyaxis || parser.seen(axis_codes[i])) {
|
|
1118
|
+ if (!I2CPE_anyaxis || parser.seen(AXIS_CHAR(i))) {
|
1119
|
1119
|
const uint8_t idx = idx_from_axis(AxisEnum(i));
|
1120
|
1120
|
if ((int8_t)idx >= 0) report_error(idx);
|
1121
|
1121
|
}
|