@ -159,6 +159,10 @@
// M400 - Finish all moves
// M401 - Lower z-probe if present
// M402 - Raise z-probe if present
// M404 - N<dia in mm> Enter the nominal filament width (3mm, 1.75mm ) or will display nominal filament width without parameters
// M405 - Turn on Filament Sensor extrusion control. Optional D<delay in cm> to set delay in centimeters between sensor and extruder
// M406 - Turn off Filament Sensor extrusion control
// M407 - Displays measured filament diameter
// M500 - stores parameters in EEPROM
// M501 - reads parameters from EEPROM (if you need reset them after you changed them temporarily).
// M502 - reverts to the default "factory settings". You still need to store them in EEPROM afterwards if you want to.
@ -220,7 +224,7 @@ float volumetric_multiplier[EXTRUDERS] = {1.0
# endif
} ;
float current_position [ NUM_AXIS ] = { 0.0 , 0.0 , 0.0 , 0.0 } ;
float add_home ing [ 3 ] = { 0 , 0 , 0 } ;
float add_homing [ 3 ] = { 0 , 0 , 0 } ;
# ifdef DELTA
float endstop_adj [ 3 ] = { 0 , 0 , 0 } ;
# endif
@ -313,12 +317,28 @@ float axis_scaling[3]={1,1,1}; // Build size scaling, default to 1
bool cancel_heatup = false ;
# ifdef FILAMENT_SENSOR
//Variables for Filament Sensor input
float filament_width_nominal = DEFAULT_NOMINAL_FILAMENT_DIA ; //Set nominal filament width, can be changed with M404
bool filament_sensor = false ; //M405 turns on filament_sensor control, M406 turns it off
float filament_width_meas = DEFAULT_MEASURED_FILAMENT_DIA ; //Stores the measured filament diameter
signed char measurement_delay [ MAX_MEASUREMENT_DELAY + 1 ] ; //ring buffer to delay measurement store extruder factor after subtracting 100
int delay_index1 = 0 ; //index into ring buffer
int delay_index2 = - 1 ; //index into ring buffer - set to -1 on startup to indicate ring buffer needs to be initialized
float delay_dist = 0 ; //delay distance counter
int meas_delay_cm = MEASUREMENT_DELAY_CM ; //distance delay setting
# endif
//===========================================================================
//=============================Private Variables=============================
//===========================================================================
const char axis_codes [ NUM_AXIS ] = { ' X ' , ' Y ' , ' Z ' , ' E ' } ;
static float destination [ NUM_AXIS ] = { 0.0 , 0.0 , 0.0 , 0.0 } ;
# ifndef DELTA
static float delta [ 3 ] = { 0.0 , 0.0 , 0.0 } ;
# endif
static float offset [ 3 ] = { 0.0 , 0.0 , 0.0 } ;
static bool home_all_axis = true ;
static float feedrate = 1500.0 , next_feedrate , saved_feedrate ;
@ -506,6 +526,7 @@ void servo_init()
# endif
}
void setup ( )
{
setup_killpin ( ) ;
@ -555,6 +576,7 @@ void setup()
st_init ( ) ; // Initialize stepper, this enables interrupts!
setup_photpin ( ) ;
servo_init ( ) ;
lcd_init ( ) ;
_delay_ms ( 1000 ) ; // wait 1sec to display the splash screen
@ -852,7 +874,7 @@ static int dual_x_carriage_mode = DEFAULT_DUAL_X_CARRIAGE_MODE;
static float x_home_pos ( int extruder ) {
if ( extruder = = 0 )
return base_home_pos ( X_AXIS ) + add_home ing [ X_AXIS ] ;
return base_home_pos ( X_AXIS ) + add_homing [ X_AXIS ] ;
else
// In dual carriage mode the extruder offset provides an override of the
// second X-carriage offset when homed - otherwise X2_HOME_POS is used.
@ -884,9 +906,9 @@ static void axis_is_at_home(int axis) {
return ;
}
else if ( dual_x_carriage_mode = = DXC_DUPLICATION_MODE & & active_extruder = = 0 ) {
current_position [ X_AXIS ] = base_home_pos ( X_AXIS ) + add_home ing [ X_AXIS ] ;
min_pos [ X_AXIS ] = base_min_pos ( X_AXIS ) + add_home ing [ X_AXIS ] ;
max_pos [ X_AXIS ] = min ( base_max_pos ( X_AXIS ) + add_home ing [ X_AXIS ] ,
current_position [ X_AXIS ] = base_home_pos ( X_AXIS ) + add_homing [ X_AXIS ] ;
min_pos [ X_AXIS ] = base_min_pos ( X_AXIS ) + add_homing [ X_AXIS ] ;
max_pos [ X_AXIS ] = min ( base_max_pos ( X_AXIS ) + add_homing [ X_AXIS ] ,
max ( extruder_offset [ X_AXIS ] [ 1 ] , X2_MAX_POS ) - duplicate_extruder_x_offset ) ;
return ;
}
@ -914,11 +936,11 @@ static void axis_is_at_home(int axis) {
for ( i = 0 ; i < 2 ; i + + )
{
delta [ i ] - = add_home ing [ i ] ;
delta [ i ] - = add_homing [ i ] ;
}
// SERIAL_ECHOPGM("addhome X="); SERIAL_ECHO(add_home ing[X_AXIS]);
// SERIAL_ECHOPGM(" addhome Y="); SERIAL_ECHO(add_home ing[Y_AXIS]);
// SERIAL_ECHOPGM("addhome X="); SERIAL_ECHO(add_homing[X_AXIS]);
// SERIAL_ECHOPGM(" addhome Y="); SERIAL_ECHO(add_homing[Y_AXIS]);
// SERIAL_ECHOPGM(" addhome Theta="); SERIAL_ECHO(delta[X_AXIS]);
// SERIAL_ECHOPGM(" addhome Psi+Theta="); SERIAL_ECHOLN(delta[Y_AXIS]);
@ -936,14 +958,14 @@ static void axis_is_at_home(int axis) {
}
else
{
current_position [ axis ] = base_home_pos ( axis ) + add_home ing [ axis ] ;
min_pos [ axis ] = base_min_pos ( axis ) + add_home ing [ axis ] ;
max_pos [ axis ] = base_max_pos ( axis ) + add_home ing [ axis ] ;
current_position [ axis ] = base_home_pos ( axis ) + add_homing [ axis ] ;
min_pos [ axis ] = base_min_pos ( axis ) + add_homing [ axis ] ;
max_pos [ axis ] = base_max_pos ( axis ) + add_homing [ axis ] ;
}
# else
current_position [ axis ] = base_home_pos ( axis ) + add_home ing [ axis ] ;
min_pos [ axis ] = base_min_pos ( axis ) + add_home ing [ axis ] ;
max_pos [ axis ] = base_max_pos ( axis ) + add_home ing [ axis ] ;
current_position [ axis ] = base_home_pos ( axis ) + add_homing [ axis ] ;
min_pos [ axis ] = base_min_pos ( axis ) + add_homing [ axis ] ;
max_pos [ axis ] = base_max_pos ( axis ) + add_homing [ axis ] ;
# endif
}
@ -1432,12 +1454,12 @@ void process_commands()
HOMEAXIS ( Z ) ;
calculate_delta ( current_position ) ;
plan_set_position ( delta [ X_AXIS ] , delta [ Y_AXIS ] , delta [ Z_AXIS ] , current_position [ E_AXIS ] ) ;
plan_set_position ( delta [ X_AXIS ] , delta [ Y_AXIS ] , delta [ Z_AXIS ] , current_position [ E_AXIS ] ) ;
# else // NOT DELTA
home_all_axis = ! ( ( code_seen ( axis_codes [ X_AXIS ] ) ) | | ( code_seen ( axis_codes [ Y_AXIS ] ) ) | | ( code_seen ( axis_codes [ Z_AXIS ] ) ) ) ;
# if Z_HOME_DIR > 0 // If homing away from BED do Z first
if ( ( home_all_axis ) | | ( code_seen ( axis_codes [ Z_AXIS ] ) ) ) {
HOMEAXIS ( Z ) ;
@ -1516,7 +1538,7 @@ void process_commands()
# ifdef SCARA
current_position [ X_AXIS ] = code_value ( ) ;
# else
current_position [ X_AXIS ] = code_value ( ) + add_home ing [ 0 ] ;
current_position [ X_AXIS ] = code_value ( ) + add_homing [ 0 ] ;
# endif
}
}
@ -1526,7 +1548,7 @@ void process_commands()
# ifdef SCARA
current_position [ Y_AXIS ] = code_value ( ) ;
# else
current_position [ Y_AXIS ] = code_value ( ) + add_home ing [ 1 ] ;
current_position [ Y_AXIS ] = code_value ( ) + add_homing [ 1 ] ;
# endif
}
}
@ -1591,7 +1613,7 @@ void process_commands()
if ( code_seen ( axis_codes [ Z_AXIS ] ) ) {
if ( code_value_long ( ) ! = 0 ) {
current_position [ Z_AXIS ] = code_value ( ) + add_home ing [ 2 ] ;
current_position [ Z_AXIS ] = code_value ( ) + add_homing [ 2 ] ;
}
}
# ifdef ENABLE_AUTO_BED_LEVELING
@ -1820,10 +1842,10 @@ void process_commands()
current_position [ i ] = code_value ( ) ;
}
else {
current_position [ i ] = code_value ( ) + add_home ing [ i ] ;
current_position [ i ] = code_value ( ) + add_homing [ i ] ;
}
# else
current_position [ i ] = code_value ( ) + add_home ing [ i ] ;
current_position [ i ] = code_value ( ) + add_homing [ i ] ;
# endif
plan_set_position ( current_position [ X_AXIS ] , current_position [ Y_AXIS ] , current_position [ Z_AXIS ] , current_position [ E_AXIS ] ) ;
}
@ -2702,9 +2724,9 @@ Sigma_Exit:
SERIAL_PROTOCOLLN ( " " ) ;
SERIAL_PROTOCOLPGM ( " SCARA Cal - Theta: " ) ;
SERIAL_PROTOCOL ( delta [ X_AXIS ] + add_home ing [ 0 ] ) ;
SERIAL_PROTOCOL ( delta [ X_AXIS ] + add_homing [ 0 ] ) ;
SERIAL_PROTOCOLPGM ( " Psi+Theta (90): " ) ;
SERIAL_PROTOCOL ( delta [ Y_AXIS ] - delta [ X_AXIS ] - 90 + add_home ing [ 1 ] ) ;
SERIAL_PROTOCOL ( delta [ Y_AXIS ] - delta [ X_AXIS ] - 90 + add_homing [ 1 ] ) ;
SERIAL_PROTOCOLLN ( " " ) ;
SERIAL_PROTOCOLPGM ( " SCARA step Cal - Theta: " ) ;
@ -2778,6 +2800,8 @@ Sigma_Exit:
} else {
//reserved for setting filament diameter via UFID or filament measuring device
break ;
}
tmp_extruder = active_extruder ;
if ( code_seen ( ' T ' ) ) {
@ -2830,19 +2854,19 @@ Sigma_Exit:
if ( code_seen ( ' E ' ) ) max_e_jerk = code_value ( ) ;
}
break ;
case 206 : // M206 additional home ing offset
case 206 : // M206 additional homing offset
for ( int8_t i = 0 ; i < 3 ; i + + )
{
if ( code_seen ( axis_codes [ i ] ) ) add_home ing [ i ] = code_value ( ) ;
if ( code_seen ( axis_codes [ i ] ) ) add_homing [ i ] = code_value ( ) ;
}
# ifdef SCARA
if ( code_seen ( ' T ' ) ) // Theta
{
add_home ing [ 0 ] = code_value ( ) ;
add_homing [ 0 ] = code_value ( ) ;
}
if ( code_seen ( ' P ' ) ) // Psi
{
add_home ing [ 1 ] = code_value ( ) ;
add_homing [ 1 ] = code_value ( ) ;
}
# endif
break ;
@ -3340,6 +3364,70 @@ Sigma_Exit:
}
break ;
# endif
# ifdef FILAMENT_SENSOR
case 404 : //M404 Enter the nominal filament width (3mm, 1.75mm ) N<3.0> or display nominal filament width
{
# if (FILWIDTH_PIN > -1)
if ( code_seen ( ' N ' ) ) filament_width_nominal = code_value ( ) ;
else {
SERIAL_PROTOCOLPGM ( " Filament dia (nominal mm): " ) ;
SERIAL_PROTOCOLLN ( filament_width_nominal ) ;
}
# endif
}
break ;
case 405 : //M405 Turn on filament sensor for control
{
if ( code_seen ( ' D ' ) ) meas_delay_cm = code_value ( ) ;
if ( meas_delay_cm > MAX_MEASUREMENT_DELAY )
meas_delay_cm = MAX_MEASUREMENT_DELAY ;
if ( delay_index2 = = - 1 ) //initialize the ring buffer if it has not been done since startup
{
int temp_ratio = widthFil_to_size_ratio ( ) ;
for ( delay_index1 = 0 ; delay_index1 < ( MAX_MEASUREMENT_DELAY + 1 ) ; + + delay_index1 ) {
measurement_delay [ delay_index1 ] = temp_ratio - 100 ; //subtract 100 to scale within a signed byte
}
delay_index1 = 0 ;
delay_index2 = 0 ;
}
filament_sensor = true ;
//SERIAL_PROTOCOLPGM("Filament dia (measured mm):");
//SERIAL_PROTOCOL(filament_width_meas);
//SERIAL_PROTOCOLPGM("Extrusion ratio(%):");
//SERIAL_PROTOCOL(extrudemultiply);
}
break ;
case 406 : //M406 Turn off filament sensor for control
{
filament_sensor = false ;
}
break ;
case 407 : //M407 Display measured filament diameter
{
SERIAL_PROTOCOLPGM ( " Filament dia (measured mm): " ) ;
SERIAL_PROTOCOLLN ( filament_width_meas ) ;
}
break ;
# endif
case 500 : // M500 Store settings in EEPROM
{
Config_StoreSettings ( ) ;