Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Option to use stepper motor as a winder #16

Open
wants to merge 5 commits into
base: Release-Candidate
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Mackerel/Configuration.h
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ debug notes:
#define EXTRUDER_RPM_PID_INTEGRATOR_WIND_LIMIT 100000000 //absolute value of integrator windup max value
#define EXTRUDER_RPM_DT 1.0 //Time step for PID


//#define USE_WINDER_STEPPER

#define DEFAULT_LENGTH_CUTOFF 150000 //length in mm where extruder will shut down

Expand Down
2 changes: 1 addition & 1 deletion Mackerel/Mackerel.h
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ extern float min_pos[3];
extern float max_pos[3];
extern bool axis_known_position[3];
extern float zprobe_zoffset;
extern int winderSpeed;
extern int winderOrFanSpeed;
#ifdef BARICUDA
extern int ValvePressure;
extern int EtoPPressure;
Expand Down
82 changes: 43 additions & 39 deletions Mackerel/Mackerel_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ float extruder_offset[NUM_EXTRUDER_OFFSETS][EXTRUDERS] = {
};
#endif
uint8_t active_extruder = 0;
int winderSpeed=0;
int winderOrFanSpeed=0;
#ifdef SERVO_ENDSTOPS
int servo_endstops[] = SERVO_ENDSTOPS;
int servo_endstop_angles[] = SERVO_ENDSTOP_ANGLES;
Expand Down Expand Up @@ -364,6 +364,7 @@ static uint8_t tmp_extruder;

static float extruder_increment; //used to calculate the increment to add to create the next planning move for the extruder motor
static float puller_increment; //used to calculate the increment to add to create the next planning move for the puller motor
static float winder_increment; //used to calculate the increment to add to create the next planning move for the winder motor
static unsigned long timebuff=0;
static unsigned long deltatime=0;
static unsigned long lasttime=0;
Expand Down Expand Up @@ -672,11 +673,11 @@ void loop()
deltatime = timebuff-lasttime; //calculate delta times
lasttime = timebuff; //keep track of last sample time


if(extrude_length < fil_length_cutoff)
winderSpeed = default_winder_speed*255/winder_rpm_factor; //keep winder on all the time unless at end of spool


#ifndef USE_WINDER_STEPPER
if(extrude_length < fil_length_cutoff && (extrude_status & ES_ENABLE_SET)) {
winderOrFanSpeed = default_winder_speed*255/winder_rpm_factor; //keep winder on all the time unless at end of spool
}
#endif



Expand All @@ -695,7 +696,7 @@ void loop()

if(extrude_length >= fil_length_cutoff){ //check whether we extruded enough filament
setTargetHotend0(0);
winderSpeed = 0;
winderOrFanSpeed = 0;
digitalWrite(CONTROLLERFAN_PIN, 0); //stop Fan
extrude_status= extrude_status & ES_ENABLE_CLEAR; //update extrude_status to shut down extruder
extrude_status= extrude_status & ES_STATS_CLEAR; //shut down statistics
Expand Down Expand Up @@ -741,30 +742,18 @@ void loop()

if((extrude_status & ES_ENABLE_SET) >0){





//old
// feedrate=20*60;
// extruder_increment=feedmultiply/100.0;
// puller_increment=extruder_increment*pullermultiply/1000.0;

//extruder_feedrate=feedrate*extruder_increment/60.0;
//puller_feedrate=extruder_feedrate*pullermultiply/1000.0;

//new
extruder_increment=extruder_rpm_set/EXTRUDER_RPM_MAX*8; //make extruder increment 1 unit for max RPM and scale down as RPM input decreases *8 for more duration (removes pulsing)
extruder_feedrate=extruder_rpm_set/0.6;
puller_increment=puller_feedrate*0.6/EXTRUDER_RPM_MAX*8; //make puller increment vary to control it *8 for more duration (removes pulsing)





//calculate move - always scale step size to feedmultiply (was previously fix step side of 0.1)
destination[P_AXIS] = puller_increment + current_position[P_AXIS]; //puller


#ifdef USE_WINDER_STEPPER
winder_increment=default_winder_speed*0.6/EXTRUDER_RPM_MAX*8; //We dont need the RMP factor because our stepper has no "default RPM".
//RPM factor applies only non stepper mottors they have default RPM when supplied full voltage
destination[X_AXIS] = winder_increment + current_position[X_AXIS]; //winder if enabled is using the X_AXIS
#endif


if((extrude_status & ES_HOT_SET) && (extrude_status & ES_SWITCH_SET)) //check that extruder is at temp and switch in on
Expand Down Expand Up @@ -942,9 +931,19 @@ void loop()
}
//send move
previous_millis_cmd = millis(); //refresh the kill watchdog timer
plan_buffer_line(destination[X_AXIS], destination[Y_AXIS], destination[Z_AXIS], destination[E_AXIS], destination[P_AXIS], feedrate, active_extruder); //FMM added P_AXIS

#ifndef USE_WINDER_STEPPER
plan_buffer_line(destination[X_AXIS], destination[Y_AXIS], destination[Z_AXIS], destination[E_AXIS], destination[P_AXIS], feedrate, active_extruder); //FMM added P_AXIS
current_position[E_AXIS]=destination[E_AXIS];
current_position[P_AXIS]=destination[P_AXIS];
current_position[P_AXIS]=destination[P_AXIS];
#else
int max_move_feedrate = max(extruder_feedrate, max(puller_feedrate, (float)default_winder_speed));
plan_buffer_line(destination[X_AXIS], destination[Y_AXIS], destination[Z_AXIS], destination[E_AXIS], destination[P_AXIS], max_move_feedrate , active_extruder); //FMM added P_AXIS

current_position[X_AXIS]=destination[X_AXIS];
current_position[E_AXIS]=destination[E_AXIS];
current_position[P_AXIS]=destination[P_AXIS];
#endif
}
else{
extruder_increment=0;
Expand Down Expand Up @@ -973,7 +972,7 @@ void loop()
MYSERIAL.print("MQTT:/FE/winder/val/");
json_pair_first("ts_m",time_snap,0);
json_pair("rpm",default_winder_speed,2);
json_pair_last("set",winderSpeed,2);
json_pair_last("set",winderOrFanSpeed,2);


#ifdef FILAMENT_SENSOR
Expand Down Expand Up @@ -2271,9 +2270,9 @@ void process_commands()
break;
}
}
#if defined(WINDER_PIN) && WINDER_PIN > -1
if (pin_number == WINDER_PIN)
winderSpeed = pin_status;
#if defined(WINDER_OR_FAN_PIN) && WINDER_OR_FAN_PIN > -1
if (pin_number == WINDER_OR_FAN_PIN)
winderOrFanSpeed = pin_status;
#endif
if (pin_number > -1)
{
Expand Down Expand Up @@ -2489,19 +2488,19 @@ void process_commands()
#endif
break;

#if defined(WINDER_PIN) && WINDER_PIN > -1
#if defined(WINDER_OR_FAN_PIN) && WINDER_OR_FAN_PIN > -1
case 106: //M106 Fan On
if (code_seen('S')){
winderSpeed=constrain(code_value(),0,255);
winderOrFanSpeed=constrain(code_value(),0,255);
}
else {
winderSpeed=255;
winderOrFanSpeed=255;
}
break;
case 107: //M107 Fan Off
winderSpeed = 0;
winderOrFanSpeed = 0;
break;
#endif //WINDER_PIN
#endif //WINDER_OR_FAN_PIN
#ifdef BARICUDA
// PWM for HEATER_1_PIN
#if defined(HEATER_1_PIN) && HEATER_1_PIN > -1
Expand Down Expand Up @@ -2562,7 +2561,7 @@ void process_commands()
disable_p();
disable_e2();
finishAndDisableSteppers();
winderSpeed = 0;
winderOrFanSpeed = 0;
delay(1000); // Wait a little before to switch off
#if defined(SUICIDE_PIN) && SUICIDE_PIN > -1
st_synchronize();
Expand Down Expand Up @@ -3466,7 +3465,7 @@ void process_commands()
SERIAL_PROTOCOL_F(puller_feedrate, 2);
// Winder speed
SERIAL_PROTOCOLPGM(" W:");
SERIAL_PROTOCOL(winderSpeed);
SERIAL_PROTOCOL(winderOrFanSpeed);
//
#if defined(TEMP_0_PIN) && TEMP_0_PIN > -1
// SERIAL_PROTOCOLPGM(" T:");
Expand Down Expand Up @@ -3668,14 +3667,19 @@ void get_arc_coordinates()

void clamp_to_software_endstops(float target[3])
{
//when using X axis as winder we don't need the endstops
if (min_software_endstops) {
#ifndef USE_WINDER_STEPPER
if (target[X_AXIS] < min_pos[X_AXIS]) target[X_AXIS] = min_pos[X_AXIS];
#endif
if (target[Y_AXIS] < min_pos[Y_AXIS]) target[Y_AXIS] = min_pos[Y_AXIS];
if (target[Z_AXIS] < min_pos[Z_AXIS]) target[Z_AXIS] = min_pos[Z_AXIS];
}

if (max_software_endstops) {
#ifndef USE_WINDER_STEPPER
if (target[X_AXIS] > max_pos[X_AXIS]) target[X_AXIS] = max_pos[X_AXIS];
#endif
if (target[Y_AXIS] > max_pos[Y_AXIS]) target[Y_AXIS] = max_pos[Y_AXIS];
if (target[Z_AXIS] > max_pos[Z_AXIS]) target[Z_AXIS] = max_pos[Z_AXIS];
}
Expand Down Expand Up @@ -3822,7 +3826,7 @@ void prepare_arc_move(char isclockwise) {

#if defined(CONTROLLERFAN_PIN) && CONTROLLERFAN_PIN > -1

#if defined(WINDER_PIN)
#if defined(WINDER_OR_FAN_PIN)
#if CONTROLLERFAN_PIN == FAN_PIN
#error "You cannot set CONTROLLERFAN_PIN equal to FAN_PIN"
#endif
Expand Down
1 change: 1 addition & 0 deletions Mackerel/language.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@
#define MSG_MOVE_Z "Move Z"
#define MSG_MOVE_E "Extruder"
#define MSG_MOVE_P "Puller"
#define MSG_MOVE_W "Winder"
#define MSG_MOVE_01MM "Move 0.1mm"
#define MSG_MOVE_1MM "Move 1mm"
#define MSG_MOVE_10MM "Move 10mm"
Expand Down
4 changes: 2 additions & 2 deletions Mackerel/pins.h
Original file line number Diff line number Diff line change
Expand Up @@ -513,7 +513,7 @@
#if MOTHERBOARD == 33 || MOTHERBOARD == 35 || MOTHERBOARD == 67 || MOTHERBOARD == 68
#define FAN_PIN 9 // (Sprinter config)
#else
#define WINDER_PIN 8 // FMM used for the winder motor
#define WINDER_OR_FAN_PIN 8 // FMM used for the winder motor
#endif

#if MOTHERBOARD == 77
Expand Down Expand Up @@ -2591,7 +2591,7 @@
#endif

#define SENSITIVE_PINS {0, 1, X_STEP_PIN, X_DIR_PIN, X_ENABLE_PIN, X_MIN_PIN, X_MAX_PIN, Y_STEP_PIN, Y_DIR_PIN, Y_ENABLE_PIN, Y_MIN_PIN, Y_MAX_PIN, Z_STEP_PIN, Z_DIR_PIN, Z_ENABLE_PIN, Z_MIN_PIN, Z_MAX_PIN, PS_ON_PIN, \
HEATER_BED_PIN, WINDER_PIN, \
HEATER_BED_PIN, WINDER_OR_FAN_PIN, \
_E0_PINS _P_PINS _E2_PINS \
analogInputToDigitalPin(TEMP_0_PIN), analogInputToDigitalPin(TEMP_1_PIN), analogInputToDigitalPin(TEMP_2_PIN), analogInputToDigitalPin(TEMP_BED_PIN) }
#endif
Expand Down
10 changes: 5 additions & 5 deletions Mackerel/planner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,7 @@ void check_axes_activity()
unsigned char z_active = 0;
unsigned char e_active = 0;
unsigned char p_active = 0;
unsigned char tail_winder_speed = winderSpeed;
unsigned char tail_winder_speed = winderOrFanSpeed;
#ifdef BARICUDA
unsigned char tail_valve_pressure = ValvePressure;
unsigned char tail_e_to_p_pressure = EtoPPressure;
Expand Down Expand Up @@ -485,7 +485,7 @@ void check_axes_activity()
disable_e0();
disable_e2();
}
#if defined(WINDER_PIN) && WINDER_PIN > -1
#if defined(WINDER_OR_FAN_PIN) && WINDER_OR_FAN_PIN > -1
#ifdef FAN_KICKSTART_TIME
static unsigned long fan_kick_end;
if (tail_fan_speed) {
Expand All @@ -503,9 +503,9 @@ void check_axes_activity()
#ifdef FAN_SOFT_PWM
fanSpeedSoftPwm = tail_fan_speed;
#else
analogWrite(WINDER_PIN,tail_winder_speed);
analogWrite(WINDER_OR_FAN_PIN, tail_winder_speed);
#endif//!FAN_SOFT_PWM
#endif//WINDER_PIN > -1
#endif//WINDER_OR_FAN_PIN > -1
#ifdef AUTOTEMP
getHighESpeed();
#endif
Expand Down Expand Up @@ -615,7 +615,7 @@ block->steps_y = labs((target[X_AXIS]-position[X_AXIS]) - (target[Y_AXIS]-positi
return;
}

block->winder_speed = winderSpeed;
block->winder_speed = winderOrFanSpeed;
#ifdef BARICUDA
block->valve_pressure = ValvePressure;
block->e_to_p_pressure = EtoPPressure;
Expand Down
11 changes: 6 additions & 5 deletions Mackerel/stepper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ ISR(TIMER1_COMPA_vect)
out_bits = current_block->direction_bits;

//FMM Disable X,Y,Z output
/*

// Set the direction bits (X_AXIS=A_AXIS and Y_AXIS=B_AXIS for COREXY)
if((out_bits & (1<<X_AXIS))!=0){
#ifdef DUAL_X_CARRIAGE
Expand Down Expand Up @@ -454,6 +454,7 @@ ISR(TIMER1_COMPA_vect)
}
}

/* No need for Y and Z axes sofar
#ifndef COREXY
if ((out_bits & (1<<Y_AXIS)) != 0) { // -direction
#else
Expand Down Expand Up @@ -529,8 +530,8 @@ ISR(TIMER1_COMPA_vect)
#endif
}
}

*/ // FMM disable x,y,z endstop checking to improve pulse speed.
*/
// FMM disable x,y,z endstop checking to improve pulse speed.

#ifndef ADVANCE
if ((out_bits & (1<<E_AXIS)) != 0) { // -direction
Expand Down Expand Up @@ -582,7 +583,7 @@ ISR(TIMER1_COMPA_vect)
}
#endif //ADVANCE

/*//disable x
//write x axis
counter_x += current_block->steps_x;
if (counter_x > 0) {
#ifdef DUAL_X_CARRIAGE
Expand Down Expand Up @@ -616,7 +617,7 @@ ISR(TIMER1_COMPA_vect)
WRITE(X_STEP_PIN, INVERT_X_STEP_PIN);
#endif
}
*/ //end disable x
//end write x axis

/*//disable y
counter_y += current_block->steps_y;
Expand Down
10 changes: 5 additions & 5 deletions Mackerel/temperature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ int getHeaterPower(int heater) {
(defined(EXTRUDER_1_AUTO_FAN_PIN) && EXTRUDER_1_AUTO_FAN_PIN > -1) || \
(defined(EXTRUDER_2_AUTO_FAN_PIN) && EXTRUDER_2_AUTO_FAN_PIN > -1)

#if defined(WINDER_PIN) && WINDER_PIN > -1
#if defined(WINDER_OR_FAN_PIN) && WINDER_OR_FAN_PIN > -1
#if EXTRUDER_0_AUTO_FAN_PIN == FAN_PIN
#error "You cannot set EXTRUDER_0_AUTO_FAN_PIN equal to FAN_PIN"
#endif
Expand Down Expand Up @@ -524,7 +524,7 @@ void manage_heater()
previous_millis_bed_heater = millis();
#endif

// #if TEMP_SENSOR_BED != 0
// #if TEMP_SENSOR_BED != 0

// #ifdef PIDTEMPBED

Expand Down Expand Up @@ -803,10 +803,10 @@ void tp_init()
#if defined(HEATER_BED_PIN) && (HEATER_BED_PIN > -1)
SET_OUTPUT(HEATER_BED_PIN);
#endif
#if defined(WINDER_PIN) && (WINDER_PIN > -1)
SET_OUTPUT(WINDER_PIN);
#if defined(WINDER_OR_FAN_PIN) && (WINDER_OR_FAN_PIN > -1)
SET_OUTPUT(WINDER_OR_FAN_PIN);
#ifdef FAST_PWM_FAN
setPwmFrequency(WINDER_PIN, 1); // No prescaling. Pwm frequency = F_CPU/256/8
setPwmFrequency(WINDER_OR_FAN_PIN, 1); // No prescaling. Pwm frequency = F_CPU/256/8
#endif
#ifdef FAN_SOFT_PWM
soft_pwm_fan = fanSpeedSoftPwm / 2;
Expand Down
Loading