@ -49,7 +49,7 @@ void I2CPositionEncoder::init(const uint8_t address, const AxisEnum axis) {
initialized = true ;
initialized = true ;
SERIAL_ECHOLNPGM ( " Setting up encoder on " , AS_CHAR ( axis_codes [ encoderAxis ] ) , " axis, addr = " , address ) ;
SERIAL_ECHOLNPGM ( " Setting up encoder on " , AS_CHAR ( AXIS_CHAR ( encoderAxis ) ) , " axis, addr = " , address ) ;
position = get_position ( ) ;
position = get_position ( ) ;
}
}
@ -67,7 +67,7 @@ void I2CPositionEncoder::update() {
/*
/*
if ( trusted ) { //commented out as part of the note below
if ( trusted ) { //commented out as part of the note below
trusted = false ;
trusted = false ;
SERIAL_ECHOLNPGM ( " Fault detected on " , AS_CHAR ( axis_codes [ encoderAxis ] ) , " axis encoder. Disengaging error correction until module is trusted again. " ) ;
SERIAL_ECHOLNPGM ( " Fault detected on " , AS_CHAR ( AXIS_CHAR ( encoderAxis ) ) , " axis encoder. Disengaging error correction until module is trusted again. " ) ;
}
}
*/
*/
return ;
return ;
@ -92,7 +92,7 @@ void I2CPositionEncoder::update() {
if ( millis ( ) - lastErrorTime > I2CPE_TIME_TRUSTED ) {
if ( millis ( ) - lastErrorTime > I2CPE_TIME_TRUSTED ) {
trusted = true ;
trusted = true ;
SERIAL_ECHOLNPGM ( " Untrusted encoder module on " , AS_CHAR ( axis_codes [ encoderAxis ] ) , " axis has been fault-free for set duration, reinstating error correction. " ) ;
SERIAL_ECHOLNPGM ( " Untrusted encoder module on " , AS_CHAR ( AXIS_CHAR ( encoderAxis ) ) , " axis has been fault-free for set duration, reinstating error correction. " ) ;
//the encoder likely lost its place when the error occurred, so we'll reset and use the printer's
//the encoder likely lost its place when the error occurred, so we'll reset and use the printer's
//idea of where it the axis is to re-initialize
//idea of where it the axis is to re-initialize
@ -172,7 +172,7 @@ void I2CPositionEncoder::update() {
float sumP = 0 ;
float sumP = 0 ;
LOOP_L_N ( i , I2CPE_ERR_PRST_ARRAY_SIZE ) sumP + = errPrst [ i ] ;
LOOP_L_N ( i , I2CPE_ERR_PRST_ARRAY_SIZE ) sumP + = errPrst [ i ] ;
const int32_t errorP = int32_t ( sumP * RECIPROCAL ( I2CPE_ERR_PRST_ARRAY_SIZE ) ) ;
const int32_t errorP = int32_t ( sumP * RECIPROCAL ( I2CPE_ERR_PRST_ARRAY_SIZE ) ) ;
SERIAL_CHAR ( axis_codes [ encoderAxis ] ) ;
SERIAL_CHAR ( AXIS_CHAR ( encoderAxis ) ) ;
SERIAL_ECHOLNPGM ( " : CORRECT ERR " , errorP * planner . mm_per_step [ encoderAxis ] , " mm " ) ;
SERIAL_ECHOLNPGM ( " : CORRECT ERR " , errorP * planner . mm_per_step [ encoderAxis ] , " mm " ) ;
babystep . add_steps ( encoderAxis , - LROUND ( errorP ) ) ;
babystep . add_steps ( encoderAxis , - LROUND ( errorP ) ) ;
errPrstIdx = 0 ;
errPrstIdx = 0 ;
@ -192,7 +192,7 @@ void I2CPositionEncoder::update() {
if ( ABS ( error ) > I2CPE_ERR_CNT_THRESH * planner . settings . axis_steps_per_mm [ encoderAxis ] ) {
if ( ABS ( error ) > I2CPE_ERR_CNT_THRESH * planner . settings . axis_steps_per_mm [ encoderAxis ] ) {
const millis_t ms = millis ( ) ;
const millis_t ms = millis ( ) ;
if ( ELAPSED ( ms , nextErrorCountTime ) ) {
if ( ELAPSED ( ms , nextErrorCountTime ) ) {
SERIAL_CHAR ( axis_codes [ encoderAxis ] ) ;
SERIAL_CHAR ( AXIS_CHAR ( encoderAxis ) ) ;
SERIAL_ECHOLNPGM ( " : LARGE ERR " , error , " ; diffSum= " , diffSum ) ;
SERIAL_ECHOLNPGM ( " : LARGE ERR " , error , " ; diffSum= " , diffSum ) ;
errorCount + + ;
errorCount + + ;
nextErrorCountTime = ms + I2CPE_ERR_CNT_DEBOUNCE_MS ;
nextErrorCountTime = ms + I2CPE_ERR_CNT_DEBOUNCE_MS ;
@ -212,7 +212,7 @@ void I2CPositionEncoder::set_homed() {
homed = trusted = true ;
homed = trusted = true ;
# ifdef I2CPE_DEBUG
# ifdef I2CPE_DEBUG
SERIAL_CHAR ( axis_codes [ encoderAxis ] ) ;
SERIAL_CHAR ( AXIS_CHAR ( encoderAxis ) ) ;
SERIAL_ECHOLNPGM ( " axis encoder homed, offset of " , zeroOffset , " ticks. " ) ;
SERIAL_ECHOLNPGM ( " axis encoder homed, offset of " , zeroOffset , " ticks. " ) ;
# endif
# endif
}
}
@ -223,7 +223,7 @@ void I2CPositionEncoder::set_unhomed() {
homed = trusted = false ;
homed = trusted = false ;
# ifdef I2CPE_DEBUG
# ifdef I2CPE_DEBUG
SERIAL_CHAR ( axis_codes [ encoderAxis ] ) ;
SERIAL_CHAR ( AXIS_CHAR ( encoderAxis ) ) ;
SERIAL_ECHOLNPGM ( " axis encoder unhomed. " ) ;
SERIAL_ECHOLNPGM ( " axis encoder unhomed. " ) ;
# endif
# endif
}
}
@ -231,7 +231,7 @@ void I2CPositionEncoder::set_unhomed() {
bool I2CPositionEncoder : : passes_test ( const bool report ) {
bool I2CPositionEncoder : : passes_test ( const bool report ) {
if ( report ) {
if ( report ) {
if ( H ! = I2CPE_MAG_SIG_GOOD ) SERIAL_ECHOPGM ( " Warning. " ) ;
if ( H ! = I2CPE_MAG_SIG_GOOD ) SERIAL_ECHOPGM ( " Warning. " ) ;
SERIAL_CHAR ( axis_codes [ encoderAxis ] ) ;
SERIAL_CHAR ( AXIS_CHAR ( encoderAxis ) ) ;
serial_ternary ( H = = I2CPE_MAG_SIG_BAD , F ( " axis " ) , F ( " magnetic strip " ) , F ( " encoder " ) ) ;
serial_ternary ( H = = I2CPE_MAG_SIG_BAD , F ( " axis " ) , F ( " magnetic strip " ) , F ( " encoder " ) ) ;
switch ( H ) {
switch ( H ) {
case I2CPE_MAG_SIG_GOOD :
case I2CPE_MAG_SIG_GOOD :
@ -252,7 +252,7 @@ float I2CPositionEncoder::get_axis_error_mm(const bool report) {
error = ABS ( diff ) > 10000 ? 0 : diff ; // Huge error is a bad reading
error = ABS ( diff ) > 10000 ? 0 : diff ; // Huge error is a bad reading
if ( report ) {
if ( report ) {
SERIAL_CHAR ( axis_codes [ encoderAxis ] ) ;
SERIAL_CHAR ( AXIS_CHAR ( encoderAxis ) ) ;
SERIAL_ECHOLNPGM ( " axis target= " , target , " mm; actual= " , actual , " mm; err= " , error , " mm " ) ;
SERIAL_ECHOLNPGM ( " axis target= " , target , " mm; actual= " , actual , " mm; err= " , error , " mm " ) ;
}
}
@ -262,7 +262,7 @@ float I2CPositionEncoder::get_axis_error_mm(const bool report) {
int32_t I2CPositionEncoder : : get_axis_error_steps ( const bool report ) {
int32_t I2CPositionEncoder : : get_axis_error_steps ( const bool report ) {
if ( ! active ) {
if ( ! active ) {
if ( report ) {
if ( report ) {
SERIAL_CHAR ( axis_codes [ encoderAxis ] ) ;
SERIAL_CHAR ( AXIS_CHAR ( encoderAxis ) ) ;
SERIAL_ECHOLNPGM ( " axis encoder not active! " ) ;
SERIAL_ECHOLNPGM ( " axis encoder not active! " ) ;
}
}
return 0 ;
return 0 ;
@ -287,7 +287,7 @@ int32_t I2CPositionEncoder::get_axis_error_steps(const bool report) {
errorPrev = error ;
errorPrev = error ;
if ( report ) {
if ( report ) {
SERIAL_CHAR ( axis_codes [ encoderAxis ] ) ;
SERIAL_CHAR ( AXIS_CHAR ( encoderAxis ) ) ;
SERIAL_ECHOLNPGM ( " axis target= " , target , " ; actual= " , encoderCountInStepperTicksScaled , " ; err= " , error ) ;
SERIAL_ECHOLNPGM ( " axis target= " , target , " ; actual= " , encoderCountInStepperTicksScaled , " ; err= " , error ) ;
}
}
@ -657,7 +657,7 @@ void I2CPositionEncodersMgr::report_position(const int8_t idx, const bool units,
else {
else {
if ( noOffset ) {
if ( noOffset ) {
const int32_t raw_count = encoders [ idx ] . get_raw_count ( ) ;
const int32_t raw_count = encoders [ idx ] . get_raw_count ( ) ;
SERIAL_CHAR ( axis_codes [ encoders [ idx ] . get_axis ( ) ] , ' ' ) ;
SERIAL_CHAR ( AXIS_CHAR ( encoders [ idx ) . get_axis ( ) ] , ' ' ) ;
for ( uint8_t j = 31 ; j > 0 ; j - - )
for ( uint8_t j = 31 ; j > 0 ; j - - )
SERIAL_ECHO ( ( bool ) ( 0x00000001 & ( raw_count > > j ) ) ) ;
SERIAL_ECHO ( ( bool ) ( 0x00000001 & ( raw_count > > j ) ) ) ;
@ -712,7 +712,7 @@ void I2CPositionEncodersMgr::change_module_address(const uint8_t oldaddr, const
// and enable it (it will likely have failed initialization on power-up, before the address change).
// and enable it (it will likely have failed initialization on power-up, before the address change).
const int8_t idx = idx_from_addr ( newaddr ) ;
const int8_t idx = idx_from_addr ( newaddr ) ;
if ( idx > = 0 & & ! encoders [ idx ] . get_active ( ) ) {
if ( idx > = 0 & & ! encoders [ idx ] . get_active ( ) ) {
SERIAL_CHAR ( axis_codes [ encoders [ idx ] . get_axis ( ) ] ) ;
SERIAL_CHAR ( AXIS_CHAR ( encoders [ idx ) . get_axis ( ) ] ) ;
SERIAL_ECHOLNPGM ( " axis encoder was not detected on printer startup. Trying again. " ) ;
SERIAL_ECHOLNPGM ( " axis encoder was not detected on printer startup. Trying again. " ) ;
encoders [ idx ] . set_active ( encoders [ idx ] . passes_test ( true ) ) ;
encoders [ idx ] . set_active ( encoders [ idx ] . passes_test ( true ) ) ;
}
}
@ -814,7 +814,7 @@ void I2CPositionEncodersMgr::M860() {
if ( I2CPE_idx = = 0xFF ) {
if ( I2CPE_idx = = 0xFF ) {
LOOP_LOGICAL_AXES ( i ) {
LOOP_LOGICAL_AXES ( i ) {
if ( ! I2CPE_anyaxis | | parser . seen_test ( axis_codes [ i ] ) ) {
if ( ! I2CPE_anyaxis | | parser . seen_test ( AXIS_CHAR ( i ) ) ) {
const uint8_t idx = idx_from_axis ( AxisEnum ( i ) ) ;
const uint8_t idx = idx_from_axis ( AxisEnum ( i ) ) ;
if ( ( int8_t ) idx > = 0 ) report_position ( idx , hasU , hasO ) ;
if ( ( int8_t ) idx > = 0 ) report_position ( idx , hasU , hasO ) ;
}
}
@ -841,7 +841,7 @@ void I2CPositionEncodersMgr::M861() {
if ( I2CPE_idx = = 0xFF ) {
if ( I2CPE_idx = = 0xFF ) {
LOOP_LOGICAL_AXES ( i ) {
LOOP_LOGICAL_AXES ( i ) {
if ( ! I2CPE_anyaxis | | parser . seen ( axis_codes [ i ] ) ) {
if ( ! I2CPE_anyaxis | | parser . seen ( AXIS_CHAR ( i ) ) ) {
const uint8_t idx = idx_from_axis ( AxisEnum ( i ) ) ;
const uint8_t idx = idx_from_axis ( AxisEnum ( i ) ) ;
if ( ( int8_t ) idx > = 0 ) report_status ( idx ) ;
if ( ( int8_t ) idx > = 0 ) report_status ( idx ) ;
}
}
@ -869,7 +869,7 @@ void I2CPositionEncodersMgr::M862() {
if ( I2CPE_idx = = 0xFF ) {
if ( I2CPE_idx = = 0xFF ) {
LOOP_LOGICAL_AXES ( i ) {
LOOP_LOGICAL_AXES ( i ) {
if ( ! I2CPE_anyaxis | | parser . seen ( axis_codes [ i ] ) ) {
if ( ! I2CPE_anyaxis | | parser . seen ( AXIS_CHAR ( i ) ) ) {
const uint8_t idx = idx_from_axis ( AxisEnum ( i ) ) ;
const uint8_t idx = idx_from_axis ( AxisEnum ( i ) ) ;
if ( ( int8_t ) idx > = 0 ) test_axis ( idx ) ;
if ( ( int8_t ) idx > = 0 ) test_axis ( idx ) ;
}
}
@ -900,7 +900,7 @@ void I2CPositionEncodersMgr::M863() {
if ( I2CPE_idx = = 0xFF ) {
if ( I2CPE_idx = = 0xFF ) {
LOOP_LOGICAL_AXES ( i ) {
LOOP_LOGICAL_AXES ( i ) {
if ( ! I2CPE_anyaxis | | parser . seen ( axis_codes [ i ] ) ) {
if ( ! I2CPE_anyaxis | | parser . seen ( AXIS_CHAR ( i ) ) ) {
const uint8_t idx = idx_from_axis ( AxisEnum ( i ) ) ;
const uint8_t idx = idx_from_axis ( AxisEnum ( i ) ) ;
if ( ( int8_t ) idx > = 0 ) calibrate_steps_mm ( idx , iterations ) ;
if ( ( int8_t ) idx > = 0 ) calibrate_steps_mm ( idx , iterations ) ;
}
}
@ -976,7 +976,7 @@ void I2CPositionEncodersMgr::M865() {
if ( ! I2CPE_addr ) {
if ( ! I2CPE_addr ) {
LOOP_LOGICAL_AXES ( i ) {
LOOP_LOGICAL_AXES ( i ) {
if ( ! I2CPE_anyaxis | | parser . seen ( axis_codes [ i ] ) ) {
if ( ! I2CPE_anyaxis | | parser . seen ( AXIS_CHAR ( i ) ) ) {
const uint8_t idx = idx_from_axis ( AxisEnum ( i ) ) ;
const uint8_t idx = idx_from_axis ( AxisEnum ( i ) ) ;
if ( ( int8_t ) idx > = 0 ) report_module_firmware ( encoders [ idx ] . get_address ( ) ) ;
if ( ( int8_t ) idx > = 0 ) report_module_firmware ( encoders [ idx ] . get_address ( ) ) ;
}
}
@ -1007,7 +1007,7 @@ void I2CPositionEncodersMgr::M866() {
if ( I2CPE_idx = = 0xFF ) {
if ( I2CPE_idx = = 0xFF ) {
LOOP_LOGICAL_AXES ( i ) {
LOOP_LOGICAL_AXES ( i ) {
if ( ! I2CPE_anyaxis | | parser . seen ( axis_codes [ i ] ) ) {
if ( ! I2CPE_anyaxis | | parser . seen ( AXIS_CHAR ( i ) ) ) {
const uint8_t idx = idx_from_axis ( AxisEnum ( i ) ) ;
const uint8_t idx = idx_from_axis ( AxisEnum ( i ) ) ;
if ( ( int8_t ) idx > = 0 ) {
if ( ( int8_t ) idx > = 0 ) {
if ( hasR )
if ( hasR )
@ -1045,7 +1045,7 @@ void I2CPositionEncodersMgr::M867() {
if ( I2CPE_idx = = 0xFF ) {
if ( I2CPE_idx = = 0xFF ) {
LOOP_LOGICAL_AXES ( i ) {
LOOP_LOGICAL_AXES ( i ) {
if ( ! I2CPE_anyaxis | | parser . seen ( axis_codes [ i ] ) ) {
if ( ! I2CPE_anyaxis | | parser . seen ( AXIS_CHAR ( i ) ) ) {
const uint8_t idx = idx_from_axis ( AxisEnum ( i ) ) ;
const uint8_t idx = idx_from_axis ( AxisEnum ( i ) ) ;
if ( ( int8_t ) idx > = 0 ) {
if ( ( int8_t ) idx > = 0 ) {
const bool ena = onoff = = - 1 ? ! encoders [ I2CPE_idx ] . get_ec_enabled ( ) : ! ! onoff ;
const bool ena = onoff = = - 1 ? ! encoders [ I2CPE_idx ] . get_ec_enabled ( ) : ! ! onoff ;
@ -1081,7 +1081,7 @@ void I2CPositionEncodersMgr::M868() {
if ( I2CPE_idx = = 0xFF ) {
if ( I2CPE_idx = = 0xFF ) {
LOOP_LOGICAL_AXES ( i ) {
LOOP_LOGICAL_AXES ( i ) {
if ( ! I2CPE_anyaxis | | parser . seen ( axis_codes [ i ] ) ) {
if ( ! I2CPE_anyaxis | | parser . seen ( AXIS_CHAR ( i ) ) ) {
const uint8_t idx = idx_from_axis ( AxisEnum ( i ) ) ;
const uint8_t idx = idx_from_axis ( AxisEnum ( i ) ) ;
if ( ( int8_t ) idx > = 0 ) {
if ( ( int8_t ) idx > = 0 ) {
if ( newThreshold ! = - 9999 )
if ( newThreshold ! = - 9999 )
@ -1115,7 +1115,7 @@ void I2CPositionEncodersMgr::M869() {
if ( I2CPE_idx = = 0xFF ) {
if ( I2CPE_idx = = 0xFF ) {
LOOP_LOGICAL_AXES ( i ) {
LOOP_LOGICAL_AXES ( i ) {
if ( ! I2CPE_anyaxis | | parser . seen ( axis_codes [ i ] ) ) {
if ( ! I2CPE_anyaxis | | parser . seen ( AXIS_CHAR ( i ) ) ) {
const uint8_t idx = idx_from_axis ( AxisEnum ( i ) ) ;
const uint8_t idx = idx_from_axis ( AxisEnum ( i ) ) ;
if ( ( int8_t ) idx > = 0 ) report_error ( idx ) ;
if ( ( int8_t ) idx > = 0 ) report_error ( idx ) ;
}
}