From 0f095d94d8553b5ef341602977ef727cc9fc81ce Mon Sep 17 00:00:00 2001 From: kliment Date: Wed, 6 Apr 2011 23:56:39 +0200 Subject: SD write support. Safety check for step count. --- Tonokip_Firmware/Tonokip_Firmware.pde | 85 ++++++++++++++++++++++++++++++----- 1 file changed, 73 insertions(+), 12 deletions(-) diff --git a/Tonokip_Firmware/Tonokip_Firmware.pde b/Tonokip_Firmware/Tonokip_Firmware.pde index e441121..a0d48b4 100644 --- a/Tonokip_Firmware/Tonokip_Firmware.pde +++ b/Tonokip_Firmware/Tonokip_Firmware.pde @@ -53,7 +53,7 @@ unsigned long previous_micros=0, previous_micros_x=0, previous_micros_y=0, previ unsigned long x_steps_to_take, y_steps_to_take, z_steps_to_take, e_steps_to_take; float destination_x =0.0, destination_y = 0.0, destination_z = 0.0, destination_e = 0.0; float current_x = 0.0, current_y = 0.0, current_z = 0.0, current_e = 0.0; -float x_interval, y_interval, z_interval, e_interval; // for speed delay +long x_interval, y_interval, z_interval, e_interval; // for speed delay float feedrate = 1500, next_feedrate; float time_for_move; long gcode_N, gcode_LastN; @@ -96,6 +96,7 @@ uint32_t filesize=0; uint32_t sdpos=0; bool sdmode=false; bool sdactive=false; +bool savetosd=false; int16_t n; void initsd(){ @@ -114,6 +115,28 @@ else sdactive=true; } + +inline void write_command(char *buf){ + char* begin=buf; + char* npos=0; + char* end=buf+strlen(buf)-1; + + file.writeError = false; + if((npos=strchr(buf, 'N')) != NULL){ + begin = strchr(npos,' ')+1; + end =strchr(npos, '*')-1; + } + end[1]='\r'; + end[2]='\n'; + end[3]='\0'; + //Serial.println(begin); + file.write(begin); + if (file.writeError){ + Serial.println("error writing to file"); + } +} + + #endif @@ -121,7 +144,6 @@ void setup() { Serial.begin(BAUDRATE); Serial.println("start"); - for(int i=0;i 0 && buflen delta_x;// && delta_y > delta_e && delta_y > delta_z; boolean steep_x = delta_x >= delta_y;// && delta_x > delta_e && delta_x > delta_z; //boolean steep_z = delta_z > delta_x && delta_z > delta_y && delta_z > delta_e; int error_x; int error_y; int error_z; - float full_velocity_units = 0.3; + long full_velocity_units = 30; unsigned long full_velocity_steps; if(steep_y) { error_x = delta_y / 2; previous_micros_y=micros(); interval = y_interval; - full_velocity_steps = full_velocity_units * y_steps_per_unit; + full_velocity_steps = full_velocity_units * y_steps_per_unit /100; if (full_velocity_steps > y_steps_remaining) full_velocity_steps = y_steps_remaining; } else if (steep_x) { error_y = delta_x / 2; previous_micros_x=micros(); interval = x_interval; - full_velocity_steps = full_velocity_units * x_steps_per_unit; + full_velocity_steps = full_velocity_units * x_steps_per_unit /100; if (full_velocity_steps > x_steps_remaining) full_velocity_steps = x_steps_remaining; } - float full_interval = interval; + long full_interval = interval; unsigned long steps_done = 0; unsigned int steps_acceleration_check = 100; @@ -723,7 +784,7 @@ void linear_move(unsigned long x_steps_remaining, unsigned long y_steps_remainin if(Y_MAX_PIN > -1) if(direction_y) if(digitalRead(Y_MAX_PIN) != ENDSTOPS_INVERTING) y_steps_remaining=0; if(steep_y) { timediff = micros() - previous_micros_y; - while(timediff >= interval) { + while(timediff >= interval && y_steps_remaining>0) { y_steps_remaining--; timediff-=interval; error_x = error_x - delta_x; do_y_step(); @@ -734,7 +795,7 @@ void linear_move(unsigned long x_steps_remaining, unsigned long y_steps_remainin } } else if (steep_x) { timediff=micros() - previous_micros_x; - while(timediff >= interval) { + while(timediff >= interval && x_steps_remaining>0) { x_steps_remaining--; timediff-=interval; error_y = error_y - delta_y; do_x_step(); -- cgit v1.2.1