chiark / gitweb /
added a m400, that finished all moves,
authorBernhard Kubicek <kubicek@gmx.at>
Sun, 13 Nov 2011 18:58:09 +0000 (19:58 +0100)
committerBernhard Kubicek <kubicek@gmx.at>
Sun, 13 Nov 2011 18:58:09 +0000 (19:58 +0100)
and the mechanism so that if an endstop is hit it the ISR, the steps_to_be_taken are stored, and some current_block data that will be deleted in the next move
If the normal loop() then finds such an event, the position is calculated (floats would have taken too long in the ISR) A serial message is generated.

Marlin/Marlin.h
Marlin/Marlin.pde
Marlin/stepper.cpp
Marlin/stepper.h

index e14471264f24a01b3845089301d8030158e12e8c..440a44a579e484040c78c060383a49a2bfdd65a0 100644 (file)
@@ -6,6 +6,7 @@
 #include <WProgram.h>
 #include "fastio.h"
 #include <avr/pgmspace.h>
+#include "Configuration.h"
 
 //#define SERIAL_ECHO(x) Serial << "echo: " << x;
 //#define SERIAL_ECHOLN(x) Serial << "echo: "<<x<<endl;
@@ -108,5 +109,6 @@ void enquecommand(const char *cmd); //put an ascii command at the end of the cur
 
 extern float homing_feedrate[];
 extern bool axis_relative_modes[];
+extern float current_position[NUM_AXIS] ;
 
 #endif
index 4c1ece07e3c9e3f8f94b21b90f3d26497c4bb3e8..e15f025514da5309d1e867bb08dc45333766c473 100644 (file)
@@ -39,7 +39,7 @@
 #include "cardreader.h"
 
 
-char version_string[] = "1.0.0 Alpha 1";
+#define VERSION_STRING  "1.0.0 Alpha 1"
 
 
 
@@ -99,6 +99,7 @@ char version_string[] = "1.0.0 Alpha 1";
 // M205 -  advanced settings:  minimum travel speed S=while printing T=travel only,  B=minimum segment time X= maximum xy jerk, Z=maximum Z jerk
 // M220 - set speed factor override percentage S:factor in percent
 // M301 - Set PID parameters P I and D
+// M400 - Finish all moves
 // M500 - stores paramters 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.
@@ -120,13 +121,14 @@ bool axis_relative_modes[] = AXIS_RELATIVE_MODES;
 volatile int feedmultiply=100; //100->1 200->2
 int saved_feedmultiply;
 volatile bool feedmultiplychanged=false;
+float current_position[NUM_AXIS] = {  0.0, 0.0, 0.0, 0.0};
+
 
 //===========================================================================
 //=============================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};
-static float current_position[NUM_AXIS] = {  0.0, 0.0, 0.0, 0.0};
 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;
@@ -211,7 +213,7 @@ void setup()
 { 
   Serial.begin(BAUDRATE);
   SERIAL_ECHO_START;
-  SERIAL_ECHOLN(version_string);
+  SERIAL_ECHOLNPGM(VERSION_STRING);
   SERIAL_PROTOCOLLNPGM("start");
   SERIAL_ECHO_START;
   SERIAL_ECHOPGM("Free Memory:");
@@ -269,6 +271,7 @@ void loop()
   //check heater every n milliseconds
   manage_heater();
   manage_inactivity(1);
+  checkHitEndstops();
   LCD_STATUS;
 }
 
@@ -443,20 +446,25 @@ inline bool code_seen(char code)
     destination[LETTER##_AXIS] = 1.5 * LETTER##_MAX_LENGTH * LETTER##_HOME_DIR; \
     feedrate = homing_feedrate[LETTER##_AXIS]; \
     prepare_move(); \
+    st_synchronize();\
     \
     current_position[LETTER##_AXIS] = 0;\
     plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]);\
     destination[LETTER##_AXIS] = -5 * LETTER##_HOME_DIR;\
     prepare_move(); \
+    st_synchronize();\
     \
     destination[LETTER##_AXIS] = 10 * LETTER##_HOME_DIR;\
     feedrate = homing_feedrate[LETTER##_AXIS]/2 ;  \
     prepare_move(); \
+    st_synchronize();\
     \
     current_position[LETTER##_AXIS] = (LETTER##_HOME_DIR == -1) ? 0 : LETTER##_MAX_LENGTH;\
     plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]);\
     destination[LETTER##_AXIS] = current_position[LETTER##_AXIS];\
     feedrate = 0.0;\
+    st_synchronize();\
+    endstops_hit_on_purpose();\
   }
 
 inline void process_commands()
@@ -522,6 +530,7 @@ inline void process_commands()
       feedrate = saved_feedrate;
       feedmultiply = saved_feedmultiply;
       previous_millis_cmd = millis();
+      endstops_hit_on_purpose();
       break;
     case 90: // G90
       relative_mode = false;
@@ -909,6 +918,11 @@ inline void process_commands()
       
       break;
     #endif //PIDTEMP
+    case 400: // finish all moves
+    {
+      st_synchronize();
+    }
+    break;
     case 500: // Store settings in EEPROM
     {
         StoreSettings();
index d5d41b173602d8e7fd3c5e2e5604462ee6e09c30..23066ef320c0546952e2ea4993686b356ec29e0b 100644 (file)
 #include "speed_lookuptable.h"\r
 \r
 \r
+\r
 //===========================================================================\r
 //=============================public variables  ============================\r
 //===========================================================================\r
 block_t *current_block;  // A pointer to the block currently being traced\r
 \r
 \r
+\r
 //===========================================================================\r
 //=============================private variables ============================\r
 //===========================================================================\r
@@ -62,7 +64,9 @@ static long acceleration_time, deceleration_time;
 static unsigned short acc_step_rate; // needed for deccelaration start point\r
 static char step_loops;\r
 \r
-\r
+volatile long endstops_trigsteps[3]={0,0,0};\r
+volatile long endstops_stepsTotal,endstops_stepsDone;\r
+static volatile bool endstops_hit=false;\r
 \r
 // if DEBUG_STEPS is enabled, M114 can be used to compare two methods of determining the X,Y,Z position of the printer.\r
 // for debugging purposes only, should be disabled by default\r
@@ -152,9 +156,49 @@ asm volatile ( \
 #define DISABLE_STEPPER_DRIVER_INTERRUPT() TIMSK1 &= ~(1<<OCIE1A)\r
 \r
 \r
+void endstops_triggered(const unsigned long &stepstaken)  \r
+{\r
+  //this will only work if there is no bufferig\r
+  //however, if you perform a move at which the endstops should be triggered, and wait for it to complete, i.e. by blocking command, it should work\r
+  //yes, it uses floats, but: if endstops are triggered, thats hopefully not critical anymore anyways.\r
+  //endstops_triggerpos;\r
+  \r
+  if(endstops_hit) //hitting a second time while the first hit is not reported\r
+    return;\r
+  if(current_block == NULL)\r
+    return;\r
+  endstops_stepsTotal=current_block->step_event_count;\r
+  endstops_stepsDone=stepstaken;\r
+  endstops_trigsteps[0]=current_block->steps_x;\r
+  endstops_trigsteps[1]=current_block->steps_y;\r
+  endstops_trigsteps[2]=current_block->steps_z;\r
+\r
+  endstops_hit=true;\r
+}\r
 \r
+void checkHitEndstops()\r
+{\r
+  if( !endstops_hit)\r
+   return;\r
+  float endstops_triggerpos[3]={0,0,0};\r
+  float ratiodone=endstops_stepsDone/float(endstops_stepsTotal);  //ratio of current_block thas was performed\r
+  \r
+  endstops_triggerpos[0]=current_position[0]-(endstops_trigsteps[0]*ratiodone)/float(axis_steps_per_unit[0]);\r
+  endstops_triggerpos[1]=current_position[1]-(endstops_trigsteps[1]*ratiodone)/float(axis_steps_per_unit[1]);\r
+  endstops_triggerpos[2]=current_position[2]-(endstops_trigsteps[2]*ratiodone)/float(axis_steps_per_unit[2]);\r
+ SERIAL_ECHO_START;\r
+ SERIAL_ECHOPGM("endstops hit: ");\r
+ SERIAL_ECHOPAIR(" X:",endstops_triggerpos[0]);\r
+ SERIAL_ECHOPAIR(" Y:",endstops_triggerpos[1]);\r
+ SERIAL_ECHOPAIR(" Z:",endstops_triggerpos[2]);\r
+ SERIAL_ECHOLN("");\r
+ endstops_hit=false;\r
+}\r
 \r
-\r
+void endstops_hit_on_purpose()\r
+{\r
+  endstops_hit=false;\r
+}\r
 \r
 //         __________________________\r
 //        /|                        |\     _________________         ^\r
@@ -296,6 +340,7 @@ ISR(TIMER1_COMPA_vect)
       #endif\r
       #if X_MIN_PIN > -1\r
             if(READ(X_MIN_PIN) != ENDSTOPS_INVERTING) {\r
+              endstops_triggered(step_events_completed);\r
               step_events_completed = current_block->step_event_count;\r
             }\r
       #endif\r
@@ -307,6 +352,7 @@ ISR(TIMER1_COMPA_vect)
       #endif\r
       #if X_MAX_PIN > -1\r
         if((READ(X_MAX_PIN) != ENDSTOPS_INVERTING)  && (current_block->steps_x >0)){\r
+          endstops_triggered(step_events_completed);\r
           step_events_completed = current_block->step_event_count;\r
         }\r
         #endif\r
@@ -319,6 +365,7 @@ ISR(TIMER1_COMPA_vect)
       #endif\r
       #if Y_MIN_PIN > -1\r
         if(READ(Y_MIN_PIN) != ENDSTOPS_INVERTING) {\r
+          endstops_triggered(step_events_completed);\r
           step_events_completed = current_block->step_event_count;\r
         }\r
       #endif\r
@@ -330,6 +377,7 @@ ISR(TIMER1_COMPA_vect)
       #endif\r
       #if Y_MAX_PIN > -1\r
       if((READ(Y_MAX_PIN) != ENDSTOPS_INVERTING) && (current_block->steps_y >0)){\r
+          endstops_triggered(step_events_completed);\r
           step_events_completed = current_block->step_event_count;\r
         }\r
       #endif\r
@@ -342,6 +390,7 @@ ISR(TIMER1_COMPA_vect)
       #endif\r
       #if Z_MIN_PIN > -1\r
         if(READ(Z_MIN_PIN) != ENDSTOPS_INVERTING) {\r
+          endstops_triggered(step_events_completed);\r
           step_events_completed = current_block->step_event_count;\r
         }\r
       #endif\r
@@ -353,6 +402,7 @@ ISR(TIMER1_COMPA_vect)
       #endif\r
       #if Z_MAX_PIN > -1\r
         if((READ(Z_MAX_PIN) != ENDSTOPS_INVERTING)  && (current_block->steps_z >0)){\r
+          endstops_triggered(step_events_completed);\r
           step_events_completed = current_block->step_event_count;\r
         }\r
       #endif\r
index fb649692d334ab8d84b5ce4cba3038f2b0748812..ecbc713e360d129184adbf6b2a06e21624766cae 100644 (file)
@@ -39,6 +39,13 @@ void st_wake_up();
   extern volatile long count_position[NUM_AXIS];\r
   extern volatile int count_direction[NUM_AXIS];\r
 #endif\r
+  \r
+void checkHitEndstops(); //call from somwhere to create an serial error message with the locations the endstops where hit, in case they were triggered\r
+void endstops_hit_on_purpose(); //avoid creation of the message, i.e. after homeing and before a routine call of checkHitEndstops();\r
+\r
+\r
 \r
 extern block_t *current_block;  // A pointer to the block currently being traced\r
+\r
+\r
 #endif\r