@ -159,6 +159,10 @@
// M400 - Finish all moves
// M400 - Finish all moves
// M401 - Lower z-probe if present
// M401 - Lower z-probe if present
// M402 - Raise 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
// M500 - stores parameters in EEPROM
// M501 - reads parameters from EEPROM (if you need reset them after you changed them temporarily).
// 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.
// 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
# endif
} ;
} ;
float current_position [ NUM_AXIS ] = { 0.0 , 0.0 , 0.0 , 0.0 } ;
float current_position [ NUM_AXIS ] = { 0.0 , 0.0 , 0.0 , 0.0 } ;
float add_hom e ing[ 3 ] = { 0 , 0 , 0 } ;
float add_hom ing[ 3 ] = { 0 , 0 , 0 } ;
# ifdef DELTA
# ifdef DELTA
float endstop_adj [ 3 ] = { 0 , 0 , 0 } ;
float endstop_adj [ 3 ] = { 0 , 0 , 0 } ;
# endif
# endif
@ -313,12 +317,28 @@ float axis_scaling[3]={1,1,1}; // Build size scaling, default to 1
bool cancel_heatup = false ;
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=============================
//=============================Private Variables=============================
//===========================================================================
//===========================================================================
const char axis_codes [ NUM_AXIS ] = { ' X ' , ' Y ' , ' Z ' , ' E ' } ;
const char axis_codes [ NUM_AXIS ] = { ' X ' , ' Y ' , ' Z ' , ' E ' } ;
static float destination [ NUM_AXIS ] = { 0.0 , 0.0 , 0.0 , 0.0 } ;
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 } ;
static float delta [ 3 ] = { 0.0 , 0.0 , 0.0 } ;
# endif
static float offset [ 3 ] = { 0.0 , 0.0 , 0.0 } ;
static float offset [ 3 ] = { 0.0 , 0.0 , 0.0 } ;
static bool home_all_axis = true ;
static bool home_all_axis = true ;
static float feedrate = 1500.0 , next_feedrate , saved_feedrate ;
static float feedrate = 1500.0 , next_feedrate , saved_feedrate ;
@ -506,6 +526,7 @@ void servo_init()
# endif
# endif
}
}
void setup ( )
void setup ( )
{
{
setup_killpin ( ) ;
setup_killpin ( ) ;
@ -556,6 +577,7 @@ void setup()
setup_photpin ( ) ;
setup_photpin ( ) ;
servo_init ( ) ;
servo_init ( ) ;
lcd_init ( ) ;
lcd_init ( ) ;
_delay_ms ( 1000 ) ; // wait 1sec to display the splash screen
_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 ) {
static float x_home_pos ( int extruder ) {
if ( extruder = = 0 )
if ( extruder = = 0 )
return base_home_pos ( X_AXIS ) + add_hom e ing[ X_AXIS ] ;
return base_home_pos ( X_AXIS ) + add_hom ing[ X_AXIS ] ;
else
else
// In dual carriage mode the extruder offset provides an override of the
// In dual carriage mode the extruder offset provides an override of the
// second X-carriage offset when homed - otherwise X2_HOME_POS is used.
// 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 ;
return ;
}
}
else if ( dual_x_carriage_mode = = DXC_DUPLICATION_MODE & & active_extruder = = 0 ) {
else if ( dual_x_carriage_mode = = DXC_DUPLICATION_MODE & & active_extruder = = 0 ) {
current_position [ X_AXIS ] = base_home_pos ( X_AXIS ) + add_hom e ing[ X_AXIS ] ;
current_position [ X_AXIS ] = base_home_pos ( X_AXIS ) + add_hom ing[ X_AXIS ] ;
min_pos [ X_AXIS ] = base_min_pos ( X_AXIS ) + add_hom e ing[ X_AXIS ] ;
min_pos [ X_AXIS ] = base_min_pos ( X_AXIS ) + add_hom ing[ X_AXIS ] ;
max_pos [ X_AXIS ] = min ( base_max_pos ( X_AXIS ) + add_hom e ing[ X_AXIS ] ,
max_pos [ X_AXIS ] = min ( base_max_pos ( X_AXIS ) + add_hom ing[ X_AXIS ] ,
max ( extruder_offset [ X_AXIS ] [ 1 ] , X2_MAX_POS ) - duplicate_extruder_x_offset ) ;
max ( extruder_offset [ X_AXIS ] [ 1 ] , X2_MAX_POS ) - duplicate_extruder_x_offset ) ;
return ;
return ;
}
}
@ -914,11 +936,11 @@ static void axis_is_at_home(int axis) {
for ( i = 0 ; i < 2 ; i + + )
for ( i = 0 ; i < 2 ; i + + )
{
{
delta [ i ] - = add_hom e ing[ i ] ;
delta [ i ] - = add_hom ing[ i ] ;
}
}
// SERIAL_ECHOPGM("addhome X="); SERIAL_ECHO(add_hom e ing[X_AXIS]);
// SERIAL_ECHOPGM("addhome X="); SERIAL_ECHO(add_hom ing[X_AXIS]);
// SERIAL_ECHOPGM(" addhome Y="); SERIAL_ECHO(add_hom e ing[Y_AXIS]);
// SERIAL_ECHOPGM(" addhome Y="); SERIAL_ECHO(add_hom ing[Y_AXIS]);
// SERIAL_ECHOPGM(" addhome Theta="); SERIAL_ECHO(delta[X_AXIS]);
// SERIAL_ECHOPGM(" addhome Theta="); SERIAL_ECHO(delta[X_AXIS]);
// SERIAL_ECHOPGM(" addhome Psi+Theta="); SERIAL_ECHOLN(delta[Y_AXIS]);
// SERIAL_ECHOPGM(" addhome Psi+Theta="); SERIAL_ECHOLN(delta[Y_AXIS]);
@ -936,14 +958,14 @@ static void axis_is_at_home(int axis) {
}
}
else
else
{
{
current_position [ axis ] = base_home_pos ( axis ) + add_hom e ing[ axis ] ;
current_position [ axis ] = base_home_pos ( axis ) + add_hom ing[ axis ] ;
min_pos [ axis ] = base_min_pos ( axis ) + add_hom e ing[ axis ] ;
min_pos [ axis ] = base_min_pos ( axis ) + add_hom ing[ axis ] ;
max_pos [ axis ] = base_max_pos ( axis ) + add_hom e ing[ axis ] ;
max_pos [ axis ] = base_max_pos ( axis ) + add_hom ing[ axis ] ;
}
}
# else
# else
current_position [ axis ] = base_home_pos ( axis ) + add_hom e ing[ axis ] ;
current_position [ axis ] = base_home_pos ( axis ) + add_hom ing[ axis ] ;
min_pos [ axis ] = base_min_pos ( axis ) + add_hom e ing[ axis ] ;
min_pos [ axis ] = base_min_pos ( axis ) + add_hom ing[ axis ] ;
max_pos [ axis ] = base_max_pos ( axis ) + add_hom e ing[ axis ] ;
max_pos [ axis ] = base_max_pos ( axis ) + add_hom ing[ axis ] ;
# endif
# endif
}
}
@ -1516,7 +1538,7 @@ void process_commands()
# ifdef SCARA
# ifdef SCARA
current_position [ X_AXIS ] = code_value ( ) ;
current_position [ X_AXIS ] = code_value ( ) ;
# else
# else
current_position [ X_AXIS ] = code_value ( ) + add_hom e ing[ 0 ] ;
current_position [ X_AXIS ] = code_value ( ) + add_hom ing[ 0 ] ;
# endif
# endif
}
}
}
}
@ -1526,7 +1548,7 @@ void process_commands()
# ifdef SCARA
# ifdef SCARA
current_position [ Y_AXIS ] = code_value ( ) ;
current_position [ Y_AXIS ] = code_value ( ) ;
# else
# else
current_position [ Y_AXIS ] = code_value ( ) + add_hom e ing[ 1 ] ;
current_position [ Y_AXIS ] = code_value ( ) + add_hom ing[ 1 ] ;
# endif
# endif
}
}
}
}
@ -1591,7 +1613,7 @@ void process_commands()
if ( code_seen ( axis_codes [ Z_AXIS ] ) ) {
if ( code_seen ( axis_codes [ Z_AXIS ] ) ) {
if ( code_value_long ( ) ! = 0 ) {
if ( code_value_long ( ) ! = 0 ) {
current_position [ Z_AXIS ] = code_value ( ) + add_hom e ing[ 2 ] ;
current_position [ Z_AXIS ] = code_value ( ) + add_hom ing[ 2 ] ;
}
}
}
}
# ifdef ENABLE_AUTO_BED_LEVELING
# ifdef ENABLE_AUTO_BED_LEVELING
@ -1820,10 +1842,10 @@ void process_commands()
current_position [ i ] = code_value ( ) ;
current_position [ i ] = code_value ( ) ;
}
}
else {
else {
current_position [ i ] = code_value ( ) + add_hom e ing[ i ] ;
current_position [ i ] = code_value ( ) + add_hom ing[ i ] ;
}
}
# else
# else
current_position [ i ] = code_value ( ) + add_hom e ing[ i ] ;
current_position [ i ] = code_value ( ) + add_hom ing[ i ] ;
# endif
# endif
plan_set_position ( current_position [ X_AXIS ] , current_position [ Y_AXIS ] , current_position [ Z_AXIS ] , current_position [ E_AXIS ] ) ;
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_PROTOCOLLN ( " " ) ;
SERIAL_PROTOCOLPGM ( " SCARA Cal - Theta: " ) ;
SERIAL_PROTOCOLPGM ( " SCARA Cal - Theta: " ) ;
SERIAL_PROTOCOL ( delta [ X_AXIS ] + add_hom e ing[ 0 ] ) ;
SERIAL_PROTOCOL ( delta [ X_AXIS ] + add_hom ing[ 0 ] ) ;
SERIAL_PROTOCOLPGM ( " Psi+Theta (90): " ) ;
SERIAL_PROTOCOLPGM ( " Psi+Theta (90): " ) ;
SERIAL_PROTOCOL ( delta [ Y_AXIS ] - delta [ X_AXIS ] - 90 + add_hom e ing[ 1 ] ) ;
SERIAL_PROTOCOL ( delta [ Y_AXIS ] - delta [ X_AXIS ] - 90 + add_hom ing[ 1 ] ) ;
SERIAL_PROTOCOLLN ( " " ) ;
SERIAL_PROTOCOLLN ( " " ) ;
SERIAL_PROTOCOLPGM ( " SCARA step Cal - Theta: " ) ;
SERIAL_PROTOCOLPGM ( " SCARA step Cal - Theta: " ) ;
@ -2778,6 +2800,8 @@ Sigma_Exit:
} else {
} else {
//reserved for setting filament diameter via UFID or filament measuring device
//reserved for setting filament diameter via UFID or filament measuring device
break ;
break ;
}
}
tmp_extruder = active_extruder ;
tmp_extruder = active_extruder ;
if ( code_seen ( ' T ' ) ) {
if ( code_seen ( ' T ' ) ) {
@ -2830,19 +2854,19 @@ Sigma_Exit:
if ( code_seen ( ' E ' ) ) max_e_jerk = code_value ( ) ;
if ( code_seen ( ' E ' ) ) max_e_jerk = code_value ( ) ;
}
}
break ;
break ;
case 206 : // M206 additional hom e ing offset
case 206 : // M206 additional hom ing offset
for ( int8_t i = 0 ; i < 3 ; i + + )
for ( int8_t i = 0 ; i < 3 ; i + + )
{
{
if ( code_seen ( axis_codes [ i ] ) ) add_hom e ing[ i ] = code_value ( ) ;
if ( code_seen ( axis_codes [ i ] ) ) add_hom ing[ i ] = code_value ( ) ;
}
}
# ifdef SCARA
# ifdef SCARA
if ( code_seen ( ' T ' ) ) // Theta
if ( code_seen ( ' T ' ) ) // Theta
{
{
add_hom e ing[ 0 ] = code_value ( ) ;
add_hom ing[ 0 ] = code_value ( ) ;
}
}
if ( code_seen ( ' P ' ) ) // Psi
if ( code_seen ( ' P ' ) ) // Psi
{
{
add_hom e ing[ 1 ] = code_value ( ) ;
add_hom ing[ 1 ] = code_value ( ) ;
}
}
# endif
# endif
break ;
break ;
@ -3340,6 +3364,70 @@ Sigma_Exit:
}
}
break ;
break ;
# endif
# 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
case 500 : // M500 Store settings in EEPROM
{
{
Config_StoreSettings ( ) ;
Config_StoreSettings ( ) ;