🧑‍💻 FxdTiCtrl => FTMotion

This commit is contained in:
Scott Lahteine
2023-10-12 09:44:46 -05:00
parent a7a3abb9bf
commit e7e77d9612
12 changed files with 186 additions and 205 deletions

View File

@@ -1492,11 +1492,14 @@ void Stepper::isr() {
uint8_t max_loops = 10;
#if ENABLED(FT_MOTION)
static bool fxdTiCtrl_stepCmdRdy = false; // Indicates a step command was loaded from the
// buffers and is ready to be output.
static bool fxdTiCtrl_applyDir = false; // Indicates the DIR output should be set.
static ft_command_t fxdTiCtrl_stepCmd = 0U; // Storage for the step command to be output.
static uint32_t fxdTiCtrl_nextAuxISR = 0U; // Storage for the next ISR of the auxilliary tasks.
static bool ftMotion_stepCmdRdy = false; // Indicates a step command was loaded from the
// buffers and is ready to be output.
static bool ftMotion_applyDir = false; // Indicates the DIR output should be set.
static ft_command_t ftMotion_stepCmd = 0U; // Storage for the step command to be output.
static uint32_t ftMotion_nextAuxISR = 0U; // Storage for the next ISR of the auxilliary tasks.
const bool using_ftMotion = ftMotion.cfg.mode;
#else
constexpr bool using_ftMotion = false;
#endif
// We need this variable here to be able to use it in the following loop
@@ -1509,64 +1512,58 @@ void Stepper::isr() {
#if ENABLED(FT_MOTION)
// NOTE STEPPER_TIMER_RATE is equal to 2000000, not what VSCode shows
const bool using_fxtictrl = fxdTiCtrl.cfg.mode;
if (using_fxtictrl) {
if (using_ftMotion) {
if (!nextMainISR) {
if (abort_current_block) {
fxdTiCtrl_stepCmdRdy = false; // If a command was ready, cancel it.
fxdTiCtrl.sts_stepperBusy = false; // Set busy false to allow a reset.
ftMotion_stepCmdRdy = false; // If a command was ready, cancel it.
ftMotion.sts_stepperBusy = false; // Set busy false to allow a reset.
nextMainISR = 0.01f * (STEPPER_TIMER_RATE); // Come back in 10 msec.
}
else { // !(abort_current_block)
if (fxdTiCtrl_stepCmdRdy) {
fxdTiCtrl_stepper(fxdTiCtrl_applyDir, fxdTiCtrl_stepCmd);
fxdTiCtrl_stepCmdRdy = false;
if (ftMotion_stepCmdRdy) {
ftMotion_stepper(ftMotion_applyDir, ftMotion_stepCmd);
ftMotion_stepCmdRdy = false;
}
// Check if there is data in the buffers.
if (fxdTiCtrl.stepperCmdBuff_produceIdx != fxdTiCtrl.stepperCmdBuff_consumeIdx) {
if (ftMotion.stepperCmdBuff_produceIdx != ftMotion.stepperCmdBuff_consumeIdx) {
fxdTiCtrl.sts_stepperBusy = true;
ftMotion.sts_stepperBusy = true;
// "Pop" one command from the command buffer.
fxdTiCtrl_stepCmd = fxdTiCtrl.stepperCmdBuff[fxdTiCtrl.stepperCmdBuff_consumeIdx];
const uint8_t dir_index = fxdTiCtrl.stepperCmdBuff_consumeIdx >> 3,
dir_bit = fxdTiCtrl.stepperCmdBuff_consumeIdx & 0x7;
fxdTiCtrl_applyDir = TEST(fxdTiCtrl.stepperCmdBuff_ApplyDir[dir_index], dir_bit);
nextMainISR = fxdTiCtrl.stepperCmdBuff_StepRelativeTi[fxdTiCtrl.stepperCmdBuff_consumeIdx];
fxdTiCtrl_stepCmdRdy = true;
ftMotion_stepCmd = ftMotion.stepperCmdBuff[ftMotion.stepperCmdBuff_consumeIdx];
const uint8_t dir_index = ftMotion.stepperCmdBuff_consumeIdx >> 3,
dir_bit = ftMotion.stepperCmdBuff_consumeIdx & 0x7;
ftMotion_applyDir = TEST(ftMotion.stepperCmdBuff_ApplyDir[dir_index], dir_bit);
nextMainISR = ftMotion.stepperCmdBuff_StepRelativeTi[ftMotion.stepperCmdBuff_consumeIdx];
ftMotion_stepCmdRdy = true;
if (++fxdTiCtrl.stepperCmdBuff_consumeIdx == (FTM_STEPPERCMD_BUFF_SIZE))
fxdTiCtrl.stepperCmdBuff_consumeIdx = 0;
if (++ftMotion.stepperCmdBuff_consumeIdx == (FTM_STEPPERCMD_BUFF_SIZE))
ftMotion.stepperCmdBuff_consumeIdx = 0;
}
else { // Buffer empty.
fxdTiCtrl.sts_stepperBusy = false;
ftMotion.sts_stepperBusy = false;
nextMainISR = 0.01f * (STEPPER_TIMER_RATE); // Come back in 10 msec.
}
} // !(abort_current_block)
} // if (!nextMainISR)
// Define 2.5 msec task for auxilliary functions.
if (!fxdTiCtrl_nextAuxISR) {
// Define 2.5 msec task for auxiliary functions.
if (!ftMotion_nextAuxISR) {
endstops.update();
TERN_(BABYSTEPPING, if (babystep.has_steps()) babystepping_isr());
fxdTiCtrl_refreshAxisDidMove();
fxdTiCtrl_nextAuxISR = 0.0025f * (STEPPER_TIMER_RATE);
ftMotion_refreshAxisDidMove();
ftMotion_nextAuxISR = 0.0025f * (STEPPER_TIMER_RATE);
}
interval = _MIN(nextMainISR, fxdTiCtrl_nextAuxISR);
interval = _MIN(nextMainISR, ftMotion_nextAuxISR);
nextMainISR -= interval;
fxdTiCtrl_nextAuxISR -= interval;
ftMotion_nextAuxISR -= interval;
}
#else
constexpr bool using_fxtictrl = false;
#endif
if (!using_fxtictrl) {
if (!using_ftMotion) {
TERN_(HAS_ZV_SHAPING, shaping_isr()); // Do Shaper stepping, if needed
@@ -3436,12 +3433,8 @@ void Stepper::report_a_position(const xyz_long_t &pos) {
TERN(SAYS_A, PSTR(STR_COUNT_A), PSTR(STR_COUNT_X)), pos.x,
TERN(SAYS_B, PSTR("B:"), SP_Y_LBL), pos.y,
TERN(SAYS_C, PSTR("C:"), SP_Z_LBL), pos.z,
SP_I_LBL, pos.i,
SP_J_LBL, pos.j,
SP_K_LBL, pos.k,
SP_U_LBL, pos.u,
SP_V_LBL, pos.v,
SP_W_LBL, pos.w
SP_I_LBL, pos.i, SP_J_LBL, pos.j, SP_K_LBL, pos.k,
SP_U_LBL, pos.u, SP_V_LBL, pos.v, SP_W_LBL, pos.w
)
);
#endif
@@ -3466,7 +3459,7 @@ void Stepper::report_positions() {
#if ENABLED(FT_MOTION)
// Set stepper I/O for fixed time controller.
void Stepper::fxdTiCtrl_stepper(const bool applyDir, const ft_command_t command) {
void Stepper::ftMotion_stepper(const bool applyDir, const ft_command_t command) {
USING_TIMED_PULSE();
@@ -3558,13 +3551,13 @@ void Stepper::report_positions() {
if (axis_step.w) W_APPLY_STEP(!STEP_STATE_W, false)
);
} // Stepper::fxdTiCtrl_stepper
} // Stepper::ftMotion_stepper
void Stepper::fxdTiCtrl_BlockQueueUpdate() {
void Stepper::ftMotion_BlockQueueUpdate() {
if (current_block) {
// If the current block is not done processing, return right away
if (!fxdTiCtrl.getBlockProcDn()) return;
if (!ftMotion.getBlockProcDn()) return;
axis_did_move.reset();
current_block = nullptr;
@@ -3591,21 +3584,21 @@ void Stepper::report_positions() {
// update it here, even though it will may be out of sync with step commands
last_direction_bits = current_block->direction_bits;
fxdTiCtrl.startBlockProc(current_block);
ftMotion.startBlockProc(current_block);
}
else {
fxdTiCtrl.runoutBlock();
ftMotion.runoutBlock();
return; // No queued blocks
}
} // if (!current_block)
} // Stepper::fxdTiCtrl_BlockQueueUpdate()
} // Stepper::ftMotion_BlockQueueUpdate()
// Debounces the axis move indication to account for potential
// delay between the block information and the stepper commands
void Stepper::fxdTiCtrl_refreshAxisDidMove() {
void Stepper::ftMotion_refreshAxisDidMove() {
// Set the debounce time in seconds.
#define AXIS_DID_MOVE_DEB 5 // TODO: The debounce time should be calculated if possible,