summaryrefslogtreecommitdiff
path: root/Sprinter/Sprinter.pde
diff options
context:
space:
mode:
Diffstat (limited to 'Sprinter/Sprinter.pde')
-rw-r--r--Sprinter/Sprinter.pde99
1 files changed, 37 insertions, 62 deletions
diff --git a/Sprinter/Sprinter.pde b/Sprinter/Sprinter.pde
index 3243d78..95fcd47 100644
--- a/Sprinter/Sprinter.pde
+++ b/Sprinter/Sprinter.pde
@@ -311,11 +311,7 @@ void setup()
SET_OUTPUT(E_STEP_PIN);
#endif
#ifdef RAMP_ACCELERATION
- for(int i=0; i < NUM_AXIS; i++){
- axis_max_interval[i] = 100000000.0 / (max_start_speed_units_per_second[i] * axis_steps_per_unit[i]);
- axis_steps_per_sqr_second[i] = max_acceleration_units_per_sq_second[i] * axis_steps_per_unit[i];
- axis_travel_steps_per_sqr_second[i] = max_travel_acceleration_units_per_sq_second[i] * axis_steps_per_unit[i];
- }
+ setup_acceleration();
#endif
#ifdef HEATER_USES_MAX6675
@@ -787,7 +783,7 @@ inline void process_commands()
#endif
return;
//break;
- case 109: // M109 - Wait for extruder heater to reach target.
+ case 109: { // M109 - Wait for extruder heater to reach target.
if (code_seen('S')) target_raw = temp2analogh(code_value());
#ifdef WATCHPERIOD
if(target_raw>current_raw){
@@ -798,65 +794,39 @@ inline void process_commands()
}
#endif
codenum = millis();
+
/* See if we are heating up or cooling down */
- if( current_raw < target_raw )
- /* We are heating up */
- #ifdef TEMP_RESIDENCY_TIME
- long residencyStart;
- residencyStart = -1;
- /* continue to loop until we have reached the target temp
- _and_ until TEMP_RESIDENCY_TIME hasn't passed since we reached it */
- while( current_raw < target_raw
- || (residencyStart > -1 && (millis() - residencyStart) < TEMP_RESIDENCY_TIME*1000) ) {
- #else
- while(current_raw < target_raw) {
- #endif
- if( (millis() - codenum) > 1000 ) //Print Temp Reading every 1 second while heating up.
- {
- Serial.print("T:");
- Serial.println( analog2temp(current_raw) );
- codenum = millis();
- }
- manage_heater();
- #ifdef TEMP_RESIDENCY_TIME
- /* start/restart the TEMP_RESIDENCY_TIME timer whenever we reach target temp for the first time
- or when current temp falls outside the hysteresis after target temp was reached */
- if ( (residencyStart == -1 && current_raw >= target_raw)
- || (residencyStart > -1 && labs(analog2temp(current_raw) - analog2temp(target_raw)) > TEMP_HYSTERESIS) ) {
- residencyStart = millis();
- }
- #endif
- }
- else if( current_raw > target_raw )
- /* We are cooling down */
- #ifdef TEMP_RESIDENCY_TIME
- long residencyStart;
- residencyStart = -1;
- /* continue to loop until we have reached the target temp
- _and_ until TEMP_RESIDENCY_TIME hasn't passed since we reached it */
- while( current_raw > target_raw
- || (residencyStart > -1 && (millis() - residencyStart) < TEMP_RESIDENCY_TIME*1000) ) {
- #else
- while(current_raw > target_raw) {
- #endif
- if( (millis() - codenum) > 1000 ) //Print Temp Reading every 1 second while heating up.
+ bool target_direction = (current_raw < target_raw); // true if heating, false if cooling
+
+ #ifdef TEMP_RESIDENCY_TIME
+ long residencyStart;
+ residencyStart = -1;
+ /* continue to loop until we have reached the target temp
+ _and_ until TEMP_RESIDENCY_TIME hasn't passed since we reached it */
+ while( (target_direction ? (current_raw < target_raw) : (current_raw > target_raw))
+ || (residencyStart > -1 && (millis() - residencyStart) < TEMP_RESIDENCY_TIME*1000) ) {
+ #else
+ while ( target_direction ? (current_raw < target_raw) : (current_raw > target_raw) ) {
+ #endif
+ if( (millis() - codenum) > 1000 ) //Print Temp Reading every 1 second while heating up/cooling down
{
Serial.print("T:");
- Serial.println( analog2temp(current_raw) );
- codenum = millis();
+ Serial.println( analog2temp(current_raw) );
+ codenum = millis();
}
manage_heater();
#ifdef TEMP_RESIDENCY_TIME
/* start/restart the TEMP_RESIDENCY_TIME timer whenever we reach target temp for the first time
or when current temp falls outside the hysteresis after target temp was reached */
- if ( (residencyStart == -1 && current_raw <= target_raw)
+ if ( (residencyStart == -1 && target_direction && current_raw >= target_raw)
+ || (residencyStart == -1 && !target_direction && current_raw <= target_raw)
|| (residencyStart > -1 && labs(analog2temp(current_raw) - analog2temp(target_raw)) > TEMP_HYSTERESIS) ) {
residencyStart = millis();
}
#endif
- }
-
- break;
+ }
+ }
+ break;
case 190: // M190 - Wait bed for heater to reach target.
#if TEMP_1_PIN > -1
if (code_seen('S')) target_bed_raw = temp2analogh(code_value());
@@ -917,15 +887,10 @@ inline void process_commands()
if(code_seen(axis_codes[i])) axis_steps_per_unit[i] = code_value();
}
- //Update start speed intervals and axis order. TODO: refactor axis_max_interval[] calculation into a function, as it
- // should also be used in setup() as well
#ifdef RAMP_ACCELERATION
- long temp_max_intervals[NUM_AXIS];
- for(int i=0; i < NUM_AXIS; i++) {
- axis_max_interval[i] = 100000000.0 / (max_start_speed_units_per_second[i] * axis_steps_per_unit[i]);//TODO: do this for
- // all steps_per_unit related variables
- }
+ setup_acceleration();
#endif
+
break;
case 115: // M115
Serial.print("FIRMWARE_NAME:Sprinter FIRMWARE_URL:http%%3A/github.com/kliment/Sprinter/ PROTOCOL_VERSION:1.0 MACHINE_TYPE:Mendel EXTRUDER_COUNT:1 UUID:");
@@ -1277,8 +1242,8 @@ inline void linear_move(unsigned long axis_steps_remaining[]) // make linear mov
if (acceleration_enabled && steps_done == 0) {
interval = max_interval;
} else if (acceleration_enabled && steps_done <= plateau_steps) {
- long current_speed = (long) ((((long) steps_per_sqr_second) / 10000)
- * ((micros() - start_move_micros) / 100) + (long) min_speed_steps_per_second);
+ long current_speed = (long) ((((long) steps_per_sqr_second) / 100)
+ * ((micros() - start_move_micros) / 100)/100 + (long) min_speed_steps_per_second);
interval = 100000000 / current_speed;
if (interval < full_interval) {
accelerating = false;
@@ -1664,6 +1629,16 @@ if( (millis()-previous_millis_cmd) > max_inactive_time ) if(max_inactive_time)
if( (millis()-previous_millis_cmd) > stepper_inactive_time ) if(stepper_inactive_time) { disable_x(); disable_y(); disable_z(); disable_e(); }
}
+#ifdef RAMP_ACCELERATION
+void setup_acceleration() {
+ for (int i=0; i < NUM_AXIS; i++) {
+ axis_max_interval[i] = 100000000.0 / (max_start_speed_units_per_second[i] * axis_steps_per_unit[i]);
+ axis_steps_per_sqr_second[i] = max_acceleration_units_per_sq_second[i] * axis_steps_per_unit[i];
+ axis_travel_steps_per_sqr_second[i] = max_travel_acceleration_units_per_sq_second[i] * axis_steps_per_unit[i];
+ }
+}
+#endif
+
#ifdef DEBUG
void log_message(char* message) {
Serial.print("DEBUG"); Serial.println(message);