Skip to content

Commit 9b46854

Browse files
thinkyheadoponyx
authored andcommitted
πŸ§‘β€πŸ’» Change Marlin DIR bits: 1=Forward, 0=Reverse (MarlinFirmware#25791)
1 parent 34a1472 commit 9b46854

File tree

11 files changed

+266
-330
lines changed

11 files changed

+266
-330
lines changed

β€ŽMarlin/src/feature/backlash.cpp

+5-5
Original file line numberDiff line numberDiff line change
@@ -99,15 +99,15 @@ void Backlash::add_correction_steps(const int32_t &da, const int32_t &db, const
9999

100100
LOOP_NUM_AXES(axis) {
101101
if (distance_mm[axis]) {
102-
const bool reverse = dm[axis];
102+
const bool forward = dm[axis];
103103

104104
// When an axis changes direction, add axis backlash to the residual error
105105
if (changed_dir[axis])
106-
residual_error[axis] += (reverse ? -f_corr : f_corr) * distance_mm[axis] * planner.settings.axis_steps_per_mm[axis];
106+
residual_error[axis] += (forward ? f_corr : -f_corr) * distance_mm[axis] * planner.settings.axis_steps_per_mm[axis];
107107

108108
// Decide how much of the residual error to correct in this segment
109109
int32_t error_correction = residual_error[axis];
110-
if (reverse != (error_correction < 0))
110+
if (forward == (error_correction < 0))
111111
error_correction = 0; // Don't take up any backlash in this segment, as it would subtract steps
112112

113113
#ifdef BACKLASH_SMOOTHING_MM
@@ -147,14 +147,14 @@ void Backlash::add_correction_steps(const int32_t &da, const int32_t &db, const
147147
int32_t Backlash::get_applied_steps(const AxisEnum axis) {
148148
if (axis >= NUM_AXES) return 0;
149149

150-
const bool reverse = last_direction_bits[axis];
150+
const bool forward = last_direction_bits[axis];
151151

152152
const int32_t residual_error_axis = residual_error[axis];
153153

154154
// At startup it is assumed the last move was forwards. So the applied
155155
// steps will always be a non-positive number.
156156

157-
if (!reverse) return -residual_error_axis;
157+
if (forward) return -residual_error_axis;
158158

159159
const float f_corr = float(correction) / all_on;
160160
const int32_t full_error_axis = -f_corr * distance_mm[axis] * planner.settings.axis_steps_per_mm[axis];

β€ŽMarlin/src/feature/runout.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,7 @@ class FilamentSensorBase {
411411
// Only trigger on extrusion with XYZ movement to allow filament change and retract/recover.
412412
const uint8_t e = b->extruder;
413413
const int32_t steps = b->steps.e;
414-
const float mm = (b->direction_bits.e ? -steps : steps) * planner.mm_per_step[E_AXIS_N(e)];
414+
const float mm = (b->direction_bits.e ? steps : -steps) * planner.mm_per_step[E_AXIS_N(e)];
415415
if (e < NUM_RUNOUT_SENSORS) mm_countdown.runout[e] -= mm;
416416
#if ENABLED(FILAMENT_SWITCH_AND_MOTION)
417417
if (e < NUM_MOTION_SENSORS) mm_countdown.motion[e] -= mm;

β€ŽMarlin/src/gcode/feature/ft_motion/M493.cpp

+8-5
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,10 @@ void GcodeSuite::M493() {
102102
}
103103

104104
switch (val) {
105-
case ftMotionMode_ENABLED: fxdTiCtrl.reset(); break;
106105
#if HAS_X_AXIS
106+
//case ftMotionMode_ULENDO_FBS:
107+
//case ftMotionMode_DISCTF:
108+
// break;
107109
case ftMotionMode_ZV:
108110
case ftMotionMode_ZVD:
109111
case ftMotionMode_EI:
@@ -114,9 +116,10 @@ void GcodeSuite::M493() {
114116
fxdTiCtrl.updateShapingA();
115117
fxdTiCtrl.reset();
116118
break;
117-
//case ftMotionMode_ULENDO_FBS:
118-
//case ftMotionMode_DISCTF:
119119
#endif
120+
case ftMotionMode_ENABLED:
121+
fxdTiCtrl.reset();
122+
break;
120123
default: break;
121124
}
122125
}
@@ -195,7 +198,7 @@ void GcodeSuite::M493() {
195198
fxdTiCtrl.reset();
196199
if (fxdTiCtrl.cfg_dynFreqMode) { SERIAL_ECHOPGM("Compensator base dynamic frequency (X/A axis) set to:"); }
197200
else { SERIAL_ECHOPGM("Compensator static frequency (X/A axis) set to: "); }
198-
SERIAL_ECHO_F( fxdTiCtrl.cfg_baseFreq[0], 2 );
201+
SERIAL_ECHO_F(fxdTiCtrl.cfg_baseFreq[0], 2);
199202
SERIAL_ECHOLNPGM(".");
200203
}
201204
else { // Frequency out of range.
@@ -243,7 +246,7 @@ void GcodeSuite::M493() {
243246
fxdTiCtrl.reset();
244247
if (fxdTiCtrl.cfg_dynFreqMode) { SERIAL_ECHOPGM("Compensator base dynamic frequency (Y/B axis) set to:"); }
245248
else { SERIAL_ECHOPGM("Compensator static frequency (Y/B axis) set to: "); }
246-
SERIAL_ECHO_F( fxdTiCtrl.cfg_baseFreq[1], 2 );
249+
SERIAL_ECHO_F(fxdTiCtrl.cfg_baseFreq[1], 2);
247250
SERIAL_ECHOLNPGM(".");
248251
}
249252
else { // Frequency out of range.

β€ŽMarlin/src/gcode/motion/G6.cpp

+7-4
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,13 @@ void GcodeSuite::G6() {
3838
planner.last_page_step_rate = parser.value_ulong();
3939

4040
if (!DirectStepping::Config::DIRECTIONAL) {
41-
if (parser.seen('X')) planner.last_page_dir.x = !!parser.value_byte();
42-
if (parser.seen('Y')) planner.last_page_dir.y = !!parser.value_byte();
43-
if (parser.seen('Z')) planner.last_page_dir.z = !!parser.value_byte();
44-
if (parser.seen('E')) planner.last_page_dir.e = !!parser.value_byte();
41+
#define PAGE_DIR_SET(N,A) do{ if (parser.seen(N)) planner.last_page_dir.A = !!parser.value_byte(); } while(0)
42+
LOGICAL_AXIS_CODE(
43+
PAGE_DIR_SET('E',E),
44+
PAGE_DIR_SET('X',X), PAGE_DIR_SET('Y',Y), PAGE_DIR_SET('Z',Z),
45+
PAGE_DIR_SET(AXIS4_NAME,I), PAGE_DIR_SET(AXIS5_NAME,J), PAGE_DIR_SET(AXIS6_NAME,K),
46+
PAGE_DIR_SET(AXIS5_NAME,U), PAGE_DIR_SET(AXIS6_NAME,V), PAGE_DIR_SET(AXIS7_NAME,W)
47+
);
4548
}
4649

4750
// No index means we just set the state

β€ŽMarlin/src/inc/SanityCheck.h

+6-2
Original file line numberDiff line numberDiff line change
@@ -4037,8 +4037,12 @@ static_assert(_PLUS_TEST(3), "DEFAULT_MAX_ACCELERATION values must be positive."
40374037
/**
40384038
* Fixed-Time Motion limitations
40394039
*/
4040-
#if ENABLED(FT_MOTION) && (NUM_AXES > 3 || E_STEPPERS > 1 || NUM_Z_STEPPERS > 1 || ANY(DUAL_X_CARRIAGE, HAS_SYNCED_X_STEPPERS, HAS_SYNCED_Y_STEPPERS, HAS_MULTI_EXTRUDER, MIXING_EXTRUDER))
4041-
#error "FT_MOTION is currently limited to machines with 3 linear axes and a single extruder."
4040+
#if ENABLED(FT_MOTION)
4041+
#if NUM_AXES > 3
4042+
#error "FT_MOTION is currently limited to machines with 3 linear axes."
4043+
#elif ENABLED(MIXING_EXTRUDER)
4044+
#error "FT_MOTION is incompatible with MIXING_EXTRUDER."
4045+
#endif
40424046
#endif
40434047

40444048
// Multi-Stepping Limit

β€ŽMarlin/src/module/endstops.cpp

+9-9
Original file line numberDiff line numberDiff line change
@@ -872,7 +872,7 @@ void Endstops::update() {
872872

873873
#if HAS_X_AXIS
874874
if (stepper.axis_is_moving(X_AXIS)) {
875-
if (stepper.motor_direction(X_AXIS_HEAD)) { // -direction
875+
if (!stepper.motor_direction(X_AXIS_HEAD)) { // -direction
876876
#if USE_X_MIN || (X_SPI_SENSORLESS && X_HOME_TO_MIN)
877877
PROCESS_ENDSTOP_X(MIN);
878878
#if CORE_DIAG(XY, Y, MIN)
@@ -905,7 +905,7 @@ void Endstops::update() {
905905

906906
#if HAS_Y_AXIS
907907
if (stepper.axis_is_moving(Y_AXIS)) {
908-
if (stepper.motor_direction(Y_AXIS_HEAD)) { // -direction
908+
if (!stepper.motor_direction(Y_AXIS_HEAD)) { // -direction
909909
#if USE_Y_MIN || (Y_SPI_SENSORLESS && Y_HOME_TO_MIN)
910910
PROCESS_ENDSTOP_Y(MIN);
911911
#if CORE_DIAG(XY, X, MIN)
@@ -938,7 +938,7 @@ void Endstops::update() {
938938

939939
#if HAS_Z_AXIS
940940
if (stepper.axis_is_moving(Z_AXIS)) {
941-
if (stepper.motor_direction(Z_AXIS_HEAD)) { // Z -direction. Gantry down, bed up.
941+
if (!stepper.motor_direction(Z_AXIS_HEAD)) { // Z -direction. Gantry down, bed up.
942942

943943
#if USE_Z_MIN || (Z_SPI_SENSORLESS && Z_HOME_TO_MIN)
944944
if ( TERN1(Z_MIN_PROBE_USES_Z_MIN_ENDSTOP_PIN, z_probe_enabled)
@@ -983,7 +983,7 @@ void Endstops::update() {
983983

984984
#if HAS_I_AXIS
985985
if (stepper.axis_is_moving(I_AXIS)) {
986-
if (stepper.motor_direction(I_AXIS_HEAD)) { // -direction
986+
if (!stepper.motor_direction(I_AXIS_HEAD)) { // -direction
987987
#if USE_I_MIN || (I_SPI_SENSORLESS && I_HOME_TO_MIN)
988988
PROCESS_ENDSTOP(I, MIN);
989989
#endif
@@ -998,7 +998,7 @@ void Endstops::update() {
998998

999999
#if HAS_J_AXIS
10001000
if (stepper.axis_is_moving(J_AXIS)) {
1001-
if (stepper.motor_direction(J_AXIS_HEAD)) { // -direction
1001+
if (!stepper.motor_direction(J_AXIS_HEAD)) { // -direction
10021002
#if USE_J_MIN || (J_SPI_SENSORLESS && J_HOME_TO_MIN)
10031003
PROCESS_ENDSTOP(J, MIN);
10041004
#endif
@@ -1013,7 +1013,7 @@ void Endstops::update() {
10131013

10141014
#if HAS_K_AXIS
10151015
if (stepper.axis_is_moving(K_AXIS)) {
1016-
if (stepper.motor_direction(K_AXIS_HEAD)) { // -direction
1016+
if (!stepper.motor_direction(K_AXIS_HEAD)) { // -direction
10171017
#if USE_K_MIN || (K_SPI_SENSORLESS && K_HOME_TO_MIN)
10181018
PROCESS_ENDSTOP(K, MIN);
10191019
#endif
@@ -1028,7 +1028,7 @@ void Endstops::update() {
10281028

10291029
#if HAS_U_AXIS
10301030
if (stepper.axis_is_moving(U_AXIS)) {
1031-
if (stepper.motor_direction(U_AXIS_HEAD)) { // -direction
1031+
if (!stepper.motor_direction(U_AXIS_HEAD)) { // -direction
10321032
#if USE_U_MIN || (U_SPI_SENSORLESS && U_HOME_TO_MIN)
10331033
PROCESS_ENDSTOP(U, MIN);
10341034
#endif
@@ -1043,7 +1043,7 @@ void Endstops::update() {
10431043

10441044
#if HAS_V_AXIS
10451045
if (stepper.axis_is_moving(V_AXIS)) {
1046-
if (stepper.motor_direction(V_AXIS_HEAD)) { // -direction
1046+
if (!stepper.motor_direction(V_AXIS_HEAD)) { // -direction
10471047
#if USE_V_MIN || (V_SPI_SENSORLESS && V_HOME_TO_MIN)
10481048
PROCESS_ENDSTOP(V, MIN);
10491049
#endif
@@ -1058,7 +1058,7 @@ void Endstops::update() {
10581058

10591059
#if HAS_W_AXIS
10601060
if (stepper.axis_is_moving(W_AXIS)) {
1061-
if (stepper.motor_direction(W_AXIS_HEAD)) { // -direction
1061+
if (!stepper.motor_direction(W_AXIS_HEAD)) { // -direction
10621062
#if USE_W_MIN || (W_SPI_SENSORLESS && W_HOME_TO_MIN)
10631063
PROCESS_ENDSTOP(W, MIN);
10641064
#endif

β€ŽMarlin/src/module/ft_motion.cpp

+30-27
Original file line numberDiff line numberDiff line change
@@ -422,33 +422,36 @@ void FxdTiCtrl::reset() {
422422
stepperCmdBuff_produceIdx = stepperCmdBuff_consumeIdx = 0;
423423

424424
for (uint32_t i = 0U; i < (FTM_BATCH_SIZE); i++) { // Reset trajectory history
425-
TERN_(HAS_X_AXIS, xd[i] = 0.0f);
426-
TERN_(HAS_Y_AXIS, yd[i] = 0.0f);
427-
TERN_(HAS_Z_AXIS, zd[i] = 0.0f);
425+
TERN_(HAS_X_AXIS, xd[i] = 0.0f);
426+
TERN_(HAS_Y_AXIS, yd[i] = 0.0f);
427+
TERN_(HAS_Z_AXIS, zd[i] = 0.0f);
428428
TERN_(HAS_EXTRUDERS, ed[i] = 0.0f);
429429
}
430430

431431
blockProcRdy = blockProcRdy_z1 = blockProcDn = false;
432432
batchRdy = batchRdyForInterp = false;
433433
runoutEna = false;
434434

435-
TERN_(HAS_X_AXIS, x_endPosn_prevBlock = 0.0f);
436-
TERN_(HAS_Y_AXIS, y_endPosn_prevBlock = 0.0f);
437-
TERN_(HAS_Z_AXIS, z_endPosn_prevBlock = 0.0f);
435+
TERN_(HAS_X_AXIS, x_endPosn_prevBlock = 0.0f);
436+
TERN_(HAS_Y_AXIS, y_endPosn_prevBlock = 0.0f);
437+
TERN_(HAS_Z_AXIS, z_endPosn_prevBlock = 0.0f);
438438
TERN_(HAS_EXTRUDERS, e_endPosn_prevBlock = 0.0f);
439439

440440
makeVector_idx = makeVector_idx_z1 = 0;
441441
makeVector_batchIdx = FTM_BATCH_SIZE;
442442

443-
TERN_(HAS_X_AXIS, x_steps = 0);
444-
TERN_(HAS_Y_AXIS, y_steps = 0);
445-
TERN_(HAS_Z_AXIS, z_steps = 0);
443+
TERN_(HAS_X_AXIS, x_steps = 0);
444+
TERN_(HAS_Y_AXIS, y_steps = 0);
445+
TERN_(HAS_Z_AXIS, z_steps = 0);
446446
TERN_(HAS_EXTRUDERS, e_steps = 0);
447+
447448
interpIdx = interpIdx_z1 = 0;
448-
TERN_(HAS_X_AXIS, x_dirState = stepDirState_NOT_SET);
449-
TERN_(HAS_Y_AXIS, y_dirState = stepDirState_NOT_SET);
450-
TERN_(HAS_Z_AXIS, z_dirState = stepDirState_NOT_SET);
449+
450+
TERN_(HAS_X_AXIS, x_dirState = stepDirState_NOT_SET);
451+
TERN_(HAS_Y_AXIS, y_dirState = stepDirState_NOT_SET);
452+
TERN_(HAS_Z_AXIS, z_dirState = stepDirState_NOT_SET);
451453
TERN_(HAS_EXTRUDERS, e_dirState = stepDirState_NOT_SET);
454+
452455
nextStepTicks = FTM_MIN_TICKS;
453456

454457
#if HAS_X_AXIS
@@ -486,28 +489,28 @@ void FxdTiCtrl::loadBlockData(block_t * const current_block) {
486489
#if HAS_X_AXIS
487490
x_startPosn = x_endPosn_prevBlock;
488491
float x_moveDist = current_block->steps.a / planner.settings.axis_steps_per_mm[X_AXIS];
489-
if (direction.x) x_moveDist *= -1.0f;
492+
if (!direction.x) x_moveDist *= -1.0f;
490493
x_Ratio = x_moveDist * oneOverLength;
491494
#endif
492495

493496
#if HAS_Y_AXIS
494497
y_startPosn = y_endPosn_prevBlock;
495498
float y_moveDist = current_block->steps.b / planner.settings.axis_steps_per_mm[Y_AXIS];
496-
if (direction.y) y_moveDist *= -1.0f;
499+
if (!direction.y) y_moveDist *= -1.0f;
497500
y_Ratio = y_moveDist * oneOverLength;
498501
#endif
499502

500503
#if HAS_Z_AXIS
501504
z_startPosn = z_endPosn_prevBlock;
502505
float z_moveDist = current_block->steps.c / planner.settings.axis_steps_per_mm[Z_AXIS];
503-
if (direction.z) z_moveDist *= -1.0f;
506+
if (!direction.z) z_moveDist *= -1.0f;
504507
z_Ratio = z_moveDist * oneOverLength;
505508
#endif
506509

507510
#if HAS_EXTRUDERS
508511
e_startPosn = e_endPosn_prevBlock;
509512
float extrusion = current_block->steps.e / planner.settings.axis_steps_per_mm[E_AXIS_N(current_block->extruder)];
510-
if (direction.e) extrusion *= -1.0f;
513+
if (!direction.e) extrusion *= -1.0f;
511514
e_Ratio = extrusion * oneOverLength;
512515
#endif
513516

@@ -568,31 +571,31 @@ void FxdTiCtrl::loadBlockData(block_t * const current_block) {
568571
// One less than (Accel + Coasting + Decel) datapoints
569572
max_intervals = N1 + N2 + N3 - 1U;
570573

571-
TERN_(HAS_X_AXIS, x_endPosn_prevBlock += x_moveDist);
572-
TERN_(HAS_Y_AXIS, y_endPosn_prevBlock += y_moveDist);
573-
TERN_(HAS_Z_AXIS, z_endPosn_prevBlock += z_moveDist);
574+
TERN_(HAS_X_AXIS, x_endPosn_prevBlock += x_moveDist);
575+
TERN_(HAS_Y_AXIS, y_endPosn_prevBlock += y_moveDist);
576+
TERN_(HAS_Z_AXIS, z_endPosn_prevBlock += z_moveDist);
574577
TERN_(HAS_EXTRUDERS, e_endPosn_prevBlock += extrusion);
575578
}
576579

577580
// Generate data points of the trajectory.
578581
void FxdTiCtrl::makeVector() {
579-
float accel_k = 0.0f; // (mm/s^2) Acceleration K factor
580-
float tau = (makeVector_idx + 1) * (FTM_TS); // (s) Time since start of block
581-
float dist = 0.0f; // (mm) Distance traveled
582+
float accel_k = 0.0f; // (mm/s^2) Acceleration K factor
583+
float tau = (makeVector_idx + 1) * (FTM_TS); // (s) Time since start of block
584+
float dist = 0.0f; // (mm) Distance traveled
582585

583586
if (makeVector_idx < N1) {
584587
// Acceleration phase
585-
dist = (f_s * tau) + (0.5f * accel_P * sq(tau)); // (mm) Distance traveled for acceleration phase
586-
accel_k = accel_P; // (mm/s^2) Acceleration K factor from Accel phase
588+
dist = (f_s * tau) + (0.5f * accel_P * sq(tau)); // (mm) Distance traveled for acceleration phase
589+
accel_k = accel_P; // (mm/s^2) Acceleration K factor from Accel phase
587590
}
588591
else if (makeVector_idx >= N1 && makeVector_idx < (N1 + N2)) {
589592
// Coasting phase
590-
dist = s_1e + F_P * (tau - N1 * (FTM_TS)); // (mm) Distance traveled for coasting phase
593+
dist = s_1e + F_P * (tau - N1 * (FTM_TS)); // (mm) Distance traveled for coasting phase
591594
//accel_k = 0.0f;
592595
}
593596
else {
594597
// Deceleration phase
595-
const float tau_ = tau - (N1 + N2) * (FTM_TS); // (s) Time since start of decel phase
598+
const float tau_ = tau - (N1 + N2) * (FTM_TS); // (s) Time since start of decel phase
596599
dist = s_2e + F_P * tau_ + 0.5f * decel_P * sq(tau_); // (mm) Distance traveled for deceleration phase
597600
accel_k = decel_P; // (mm/s^2) Acceleration K factor from Decel phase
598601
}
@@ -614,7 +617,7 @@ void FxdTiCtrl::makeVector() {
614617
}
615618
else {
616619
ed[makeVector_batchIdx] = new_raw_z1;
617-
// Alternatively: coordArray_e[makeVector_batchIdx] = e_startDist + extrusion / (N1 + N2 + N3);
620+
// Alternatively: ed[makeVector_batchIdx] = e_startPosn + (e_Ratio * dist) / (N1 + N2 + N3);
618621
}
619622
#endif
620623

0 commit comments

Comments
Β (0)