0
0
Fork 0
mirror of https://github.com/MarlinFirmware/Marlin.git synced 2025-06-30 10:50:44 +00:00

Add custom types for position ()

This commit is contained in:
Scott Lahteine 2019-09-29 04:25:39 -05:00 committed by GitHub
parent 43d6e9fa43
commit 50e4545255
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
227 changed files with 3147 additions and 3264 deletions
Marlin/src/module

View file

@ -169,10 +169,10 @@ uint8_t Stepper::steps_per_isr;
#endif
uint8_t Stepper::oversampling_factor;
int32_t Stepper::delta_error[XYZE] = { 0 };
xyze_long_t Stepper::delta_error{0};
uint32_t Stepper::advance_dividend[XYZE] = { 0 },
Stepper::advance_divisor = 0,
xyze_ulong_t Stepper::advance_dividend{0};
uint32_t Stepper::advance_divisor = 0,
Stepper::step_events_completed = 0, // The number of step events executed in the current block
Stepper::accelerate_until, // The count at which to stop accelerating
Stepper::decelerate_after, // The count at which to start decelerating
@ -218,10 +218,9 @@ int32_t Stepper::ticks_nominal = -1;
uint32_t Stepper::acc_step_rate; // needed for deceleration start point
#endif
volatile int32_t Stepper::endstops_trigsteps[XYZ];
volatile int32_t Stepper::count_position[NUM_AXIS] = { 0 };
int8_t Stepper::count_direction[NUM_AXIS] = { 0, 0, 0, 0 };
xyz_long_t Stepper::endstops_trigsteps;
xyze_long_t Stepper::count_position{0};
xyze_int8_t Stepper::count_direction{0};
#define DUAL_ENDSTOP_APPLY_STEP(A,V) \
if (separate_multi_axis) { \
@ -390,20 +389,20 @@ void Stepper::set_directions() {
// what e-steppers will step. Likely all. Set all.
if (motor_direction(E_AXIS)) {
MIXER_STEPPER_LOOP(j) REV_E_DIR(j);
count_direction[E_AXIS] = -1;
count_direction.e = -1;
}
else {
MIXER_STEPPER_LOOP(j) NORM_E_DIR(j);
count_direction[E_AXIS] = 1;
count_direction.e = 1;
}
#else
if (motor_direction(E_AXIS)) {
REV_E_DIR(stepper_extruder);
count_direction[E_AXIS] = -1;
count_direction.e = -1;
}
else {
NORM_E_DIR(stepper_extruder);
count_direction[E_AXIS] = 1;
count_direction.e = 1;
}
#endif
#endif // !LIN_ADVANCE
@ -1459,15 +1458,15 @@ void Stepper::stepper_pulse_phase_isr() {
// Pulse Extruders
// Tick the E axis, correct error term and update position
#if EITHER(LIN_ADVANCE, MIXING_EXTRUDER)
delta_error[E_AXIS] += advance_dividend[E_AXIS];
if (delta_error[E_AXIS] >= 0) {
count_position[E_AXIS] += count_direction[E_AXIS];
delta_error.e += advance_dividend.e;
if (delta_error.e >= 0) {
count_position.e += count_direction.e;
#if ENABLED(LIN_ADVANCE)
delta_error[E_AXIS] -= advance_divisor;
delta_error.e -= advance_divisor;
// Don't step E here - But remember the number of steps to perform
motor_direction(E_AXIS) ? --LA_steps : ++LA_steps;
#else // !LIN_ADVANCE && MIXING_EXTRUDER
// Don't adjust delta_error[E_AXIS] here!
// Don't adjust delta_error.e here!
// Being positive is the criteria for ending the pulse.
E_STEP_WRITE(mixer.get_next_stepper(), !INVERT_E_STEP_PIN);
#endif
@ -1504,8 +1503,8 @@ void Stepper::stepper_pulse_phase_isr() {
#if DISABLED(LIN_ADVANCE)
#if ENABLED(MIXING_EXTRUDER)
if (delta_error[E_AXIS] >= 0) {
delta_error[E_AXIS] -= advance_divisor;
if (delta_error.e >= 0) {
delta_error.e -= advance_divisor;
E_STEP_WRITE(mixer.get_stepper(), INVERT_E_STEP_PIN);
}
#else // !MIXING_EXTRUDER
@ -1660,10 +1659,7 @@ uint32_t Stepper::stepper_block_phase_isr() {
// Sync block? Sync the stepper counts and return
while (TEST(current_block->flag, BLOCK_BIT_SYNC_POSITION)) {
_set_position(
current_block->position[A_AXIS], current_block->position[B_AXIS],
current_block->position[C_AXIS], current_block->position[E_AXIS]
);
_set_position(current_block->position);
planner.discard_current_block();
// Try to get a new block
@ -1698,7 +1694,7 @@ uint32_t Stepper::stepper_block_phase_isr() {
#endif
#define X_MOVE_TEST ( S_(1) != S_(2) || (S_(1) > 0 && D_(1) X_CMP D_(2)) )
#else
#define X_MOVE_TEST !!current_block->steps[A_AXIS]
#define X_MOVE_TEST !!current_block->steps.a
#endif
#if CORE_IS_XY || CORE_IS_YZ
@ -1716,7 +1712,7 @@ uint32_t Stepper::stepper_block_phase_isr() {
#endif
#define Y_MOVE_TEST ( S_(1) != S_(2) || (S_(1) > 0 && D_(1) Y_CMP D_(2)) )
#else
#define Y_MOVE_TEST !!current_block->steps[B_AXIS]
#define Y_MOVE_TEST !!current_block->steps.b
#endif
#if CORE_IS_XZ || CORE_IS_YZ
@ -1734,17 +1730,17 @@ uint32_t Stepper::stepper_block_phase_isr() {
#endif
#define Z_MOVE_TEST ( S_(1) != S_(2) || (S_(1) > 0 && D_(1) Z_CMP D_(2)) )
#else
#define Z_MOVE_TEST !!current_block->steps[C_AXIS]
#define Z_MOVE_TEST !!current_block->steps.c
#endif
uint8_t axis_bits = 0;
if (X_MOVE_TEST) SBI(axis_bits, A_AXIS);
if (Y_MOVE_TEST) SBI(axis_bits, B_AXIS);
if (Z_MOVE_TEST) SBI(axis_bits, C_AXIS);
//if (!!current_block->steps[E_AXIS]) SBI(axis_bits, E_AXIS);
//if (!!current_block->steps[A_AXIS]) SBI(axis_bits, X_HEAD);
//if (!!current_block->steps[B_AXIS]) SBI(axis_bits, Y_HEAD);
//if (!!current_block->steps[C_AXIS]) SBI(axis_bits, Z_HEAD);
//if (!!current_block->steps.e) SBI(axis_bits, E_AXIS);
//if (!!current_block->steps.a) SBI(axis_bits, X_HEAD);
//if (!!current_block->steps.b) SBI(axis_bits, Y_HEAD);
//if (!!current_block->steps.c) SBI(axis_bits, Z_HEAD);
axis_did_move = axis_bits;
// No acceleration / deceleration time elapsed so far
@ -1767,15 +1763,10 @@ uint32_t Stepper::stepper_block_phase_isr() {
step_event_count = current_block->step_event_count << oversampling;
// Initialize Bresenham delta errors to 1/2
delta_error[X_AXIS] = delta_error[Y_AXIS] = delta_error[Z_AXIS] = delta_error[E_AXIS] = -int32_t(step_event_count);
delta_error = -int32_t(step_event_count);
// Calculate Bresenham dividends
advance_dividend[X_AXIS] = current_block->steps[X_AXIS] << 1;
advance_dividend[Y_AXIS] = current_block->steps[Y_AXIS] << 1;
advance_dividend[Z_AXIS] = current_block->steps[Z_AXIS] << 1;
advance_dividend[E_AXIS] = current_block->steps[E_AXIS] << 1;
// Calculate Bresenham divisor
// Calculate Bresenham dividends and divisors
advance_dividend = current_block->steps << 1;
advance_divisor = step_event_count << 1;
// No step events completed so far
@ -1840,7 +1831,7 @@ uint32_t Stepper::stepper_block_phase_isr() {
// If delayed Z enable, enable it now. This option will severely interfere with
// timing between pulses when chaining motion between blocks, and it could lead
// to lost steps in both X and Y axis, so avoid using it unless strictly necessary!!
if (current_block->steps[Z_AXIS]) enable_Z();
if (current_block->steps.z) enable_Z();
#endif
// Mark the time_nominal as not calculated yet
@ -2195,26 +2186,18 @@ void Stepper::_set_position(const int32_t &a, const int32_t &b, const int32_t &c
#if CORE_IS_XY
// corexy positioning
// these equations follow the form of the dA and dB equations on http://www.corexy.com/theory.html
count_position[A_AXIS] = a + b;
count_position[B_AXIS] = CORESIGN(a - b);
count_position[Z_AXIS] = c;
count_position.set(a + b, CORESIGN(a - b), c);
#elif CORE_IS_XZ
// corexz planning
count_position[A_AXIS] = a + c;
count_position[Y_AXIS] = b;
count_position[C_AXIS] = CORESIGN(a - c);
count_position.set(a + c, b, CORESIGN(a - c));
#elif CORE_IS_YZ
// coreyz planning
count_position[X_AXIS] = a;
count_position[B_AXIS] = b + c;
count_position[C_AXIS] = CORESIGN(b - c);
count_position.set(a, b + c, CORESIGN(b - c));
#else
// default non-h-bot planning
count_position[X_AXIS] = a;
count_position[Y_AXIS] = b;
count_position[Z_AXIS] = c;
count_position.set(a, b, c);
#endif
count_position[E_AXIS] = e;
count_position.e = e;
}
/**
@ -2290,36 +2273,22 @@ void Stepper::report_positions() {
if (was_enabled) DISABLE_STEPPER_DRIVER_INTERRUPT();
#endif
const int32_t xpos = count_position[X_AXIS],
ypos = count_position[Y_AXIS],
zpos = count_position[Z_AXIS];
const xyz_long_t pos = count_position;
#ifdef __AVR__
if (was_enabled) ENABLE_STEPPER_DRIVER_INTERRUPT();
#endif
#if CORE_IS_XY || CORE_IS_XZ || ENABLED(DELTA) || IS_SCARA
SERIAL_ECHOPGM(MSG_COUNT_A);
SERIAL_ECHOPAIR(MSG_COUNT_A, pos.x, " B:", pos.y);
#else
SERIAL_ECHOPGM(MSG_COUNT_X);
SERIAL_ECHOPAIR(MSG_COUNT_X, pos.x, " Y:", pos.y);
#endif
SERIAL_ECHO(xpos);
#if CORE_IS_XY || CORE_IS_YZ || ENABLED(DELTA) || IS_SCARA
SERIAL_ECHOPGM(" B:");
#else
SERIAL_ECHOPGM(" Y:");
#endif
SERIAL_ECHO(ypos);
#if CORE_IS_XZ || CORE_IS_YZ || ENABLED(DELTA)
SERIAL_ECHOPGM(" C:");
SERIAL_ECHOLNPAIR(" C:", pos.z);
#else
SERIAL_ECHOPGM(" Z:");
SERIAL_ECHOLNPAIR(" Z:", pos.z);
#endif
SERIAL_ECHO(zpos);
SERIAL_EOL();
}
#if ENABLED(BABYSTEPPING)