]> jspc29.x-matter.uni-frankfurt.de Git - coral.git/commitdiff
now endstops work AND report as desired
authorMichael Wiebusch <m.wiebusch@gsi.de>
Fri, 12 Dec 2014 21:24:27 +0000 (22:24 +0100)
committerMichael Wiebusch <m.wiebusch@gsi.de>
Fri, 12 Dec 2014 21:24:27 +0000 (22:24 +0100)
firmware/main.c
firmware/makefile
firmware/motors.c
firmware/motors.h
firmware/plate.c [new file with mode: 0644]
firmware/plate.h [new file with mode: 0644]

index 912b737dc7c0d5f3426e3b8d4f4af48c7621fd31..9cd835f46e5bd903a0fd9fb3e73db46ef5bbf310 100644 (file)
@@ -7,12 +7,12 @@
 #include "motors.h"
 #include "misc.h"
 #include "pins.h"
+#include "plate.h"
 
 
 #define UM_PER_ROUND 3000
 #define STEPS_PER_ROUND 200
 
-int32_t plate_pos_x = 0,plate_pos_y = 0;
 
 int32_t steps_to_um (int32_t steps){
   return steps*UM_PER_ROUND/STEPS_PER_ROUND;
@@ -36,9 +36,9 @@ void print_steps_in_mm(int32_t steps) {
   
 void pos_report(void){ 
     uart_puts("x_pos: ");
-    print_steps_in_mm(plate_pos_x);
+    print_steps_in_mm(get_plate_pos_x());
     uart_puts("  y_pos: ");
-    print_steps_in_mm(plate_pos_y);
+    print_steps_in_mm(get_plate_pos_y());
     uart_puts("  end_sw: ");
     uart_print_number_wlzeros(XEND2_state(),1);
     uart_print_number_wlzeros(XEND1_state(),1);
@@ -48,6 +48,12 @@ void pos_report(void){
 }
 
 
+void move_and_report(int32_t dx, int32_t dy){
+  if(move_plate(dx,dy)){
+    pos_report();
+  }
+}
+
 
 typedef enum {POSITION, GOTO, MOVEREL, SETZERO} action_t;
 
@@ -154,15 +160,13 @@ void parse_command(void){
           dest = um_to_steps(num_sign*(((int32_t) predot) *1000 + ((int32_t) postdot)));
           
           if (axis == X) {
-            steps = dest - plate_pos_x; // experimental correction!
-            move_plate(steps,0);
-            plate_pos_x += steps;
+            steps = dest - get_plate_pos_x(); // experimental correction!
+            move_and_report(steps,0);
           } else if (axis == Y) {
-            steps = dest - plate_pos_y;
-            move_plate(0,steps);
-            plate_pos_y += steps;
+            steps = dest - get_plate_pos_y();
+            move_and_report(0,steps);
           }
-          pos_report();
+//           pos_report();
           
           break;
         case MOVEREL:
@@ -178,18 +182,16 @@ void parse_command(void){
           steps = um_to_steps(num_sign*(((int32_t) predot) *1000 + ((int32_t) postdot)));
           
           if (axis == X) {
-            move_plate(steps,0);
-            plate_pos_x += steps;
+            move_and_report(steps,0);
           } else if (axis == Y) {
-            move_plate(0,steps);
-            plate_pos_y += steps;
+            move_and_report(0,steps);
           }
-          pos_report();
+//           pos_report();
           break;
           
         case SETZERO:
-          plate_pos_x = 0;
-          plate_pos_y = 0;
+          set_plate_pos_x(0);
+          set_plate_pos_y(0);
           pos_report();
           break;
           
@@ -232,7 +234,6 @@ int main(void){
   
   touchpad_set_rel_mode_100dpi();// use touchpad in relative mode
   int8_t dx, dy = 0;
-  uint8_t busy = 0, last_busy = 0;
 
   while (1) {
     Usb2SerialTask();
@@ -240,17 +241,7 @@ int main(void){
     touchpad_read(); // read data from touchpad
     dx = 4*delta_x();// returns the amount your finger has moved in x direction since last readout
     dy = -4*delta_y();// returns the amount your finger has moved in y direction since last readout
-
-    plate_pos_x += dx;
-    plate_pos_y += dy;
-    
-    last_busy = busy;
-    busy = move_plate(dx,dy);
-    
-    if (last_busy && !(busy)){
-      pos_report();
-
-    }
+    move_and_report(dx,dy);
   }
 
 
index 6de0b6aefa7179dba66762b9a181a3d9103e085e..9e05df638a8e734d1f0270cf8ca17c854e0674fd 100644 (file)
@@ -18,7 +18,7 @@ F_CPU        = 16000000
 F_USB        = $(F_CPU)\r
 OPTIMIZATION = s\r
 TARGET       = main\r
-SRC          = $(TARGET).c Descriptors.c $(LUFA_SRC_USB) $(LUFA_SRC_USBCLASS) pins.c TM1001A.c motors.c misc.c USBtoSerial.c\r
+SRC          = $(TARGET).c Descriptors.c $(LUFA_SRC_USB) $(LUFA_SRC_USBCLASS) plate.c pins.c TM1001A.c motors.c misc.c USBtoSerial.c\r
 LUFA_PATH    = ../LUFA/LUFA-130303/LUFA\r
 CC_FLAGS     = -DUSE_LUFA_CONFIG_HEADER -IConfig/\r
 LD_FLAGS     =\r
index 94bc4ab16a7a19e06400ce94b0cf0bda8da0bb66..c6352586fa632da911bf4f016f0cfc85419090da 100644 (file)
@@ -2,25 +2,11 @@
 #include <stdlib.h>
 #include <util/delay.h>
 #include "motors.h"
-#include "misc.h"
 #include "pins.h"
 
 
 
-// int32_t plate_pos_x = 0,plate_pos_y = 0;
-// 
-// int32_t get_plate_pos_x(){
-//   return plate_pos_x;
-// }
-// void set_plate_pos_x(int32_t value){
-//   plate_pos_x = value;
-// }
-// int32_t get_plate_pos_y(){
-//   return plate_pos_x;
-// }
-// void set_plate_pos_y(int32_t value){
-//   plate_pos_x = value;
-// }
+
 
 /* motor stuff */
 
@@ -106,59 +92,6 @@ uint8_t motor_step(uint8_t motor, int8_t direction) { // motor: M1 or M2, direct
 
 
 
-uint8_t move_plate(int32_t dx, int32_t dy){
-  static int32_t todo_x,todo_y = 0;
-  int8_t signum;
-  uint8_t busy = 0;
-  todo_x += dx;
-  todo_y += dy;
-  
-  //if end switch closed, stop moving against the stop!
-  if(XEND1_state() && (sign(todo_x) == 1) ){
-    todo_x = 0;
-  }
-  if(XEND2_state() && (sign(todo_x) == -1) ){
-    todo_x = 0;
-  }
-  if(YEND1_state() && (sign(todo_y) == 1) ){
-    todo_y = 0;
-  }
-  if(YEND2_state() && (sign(todo_y) == -1) ){
-    todo_y = 0;
-  }
-  
-  
-  signum = sign(todo_x);
-  if(signum != 0) {
-    busy = 1;
-  }
-  motor_step(X,signum);
-  todo_x -= signum;
-  
-  
-  
-  signum = sign(todo_y);
-  if(signum != 0) {
-    busy = 1;
-  }
-  motor_step(Y,signum);
-  todo_y -= signum;
-  
-  
-  
-  _delay_us(PHASE_DELAY_US);
-  
-
-  
-  return busy; // busy
-  
-}
-
-
-
-
-
-
 
   
 
index 4008f40cc0d7146d0b603eab58254cc5fe667869..6fca92d63d8749c4555721eca7d9a8ab5d742b80 100644 (file)
@@ -1,5 +1,3 @@
-#define PHASE_DELAY_US 0
-
 
 #define X 0
 #define Y 1
@@ -51,7 +49,6 @@ void set_x(uint8_t byte);
 void set_y(uint8_t byte);
 void init_motors(void);
 uint8_t motor_step(uint8_t motor, int8_t direction);
-uint8_t move_plate(int32_t dx, int32_t dy);
 
 
 
diff --git a/firmware/plate.c b/firmware/plate.c
new file mode 100644 (file)
index 0000000..9c881e7
--- /dev/null
@@ -0,0 +1,89 @@
+#include <avr/io.h> 
+#include <stdlib.h>
+#include <util/delay.h>
+#include "motors.h"
+#include "plate.h"
+#include "misc.h"
+#include "pins.h"
+
+
+
+// plate stuff
+
+int32_t plate_pos_x = 0,plate_pos_y = 0;
+
+int32_t get_plate_pos_x(void){
+  return plate_pos_x;
+}
+void set_plate_pos_x(int32_t value){
+  plate_pos_x = value;
+}
+int32_t get_plate_pos_y(void){
+  return plate_pos_y;
+}
+void set_plate_pos_y(int32_t value){
+  plate_pos_y = value;
+}
+
+
+uint8_t move_plate(int32_t dx, int32_t dy){
+  static int32_t todo_x,todo_y = 0;
+  int8_t signum;
+  static uint8_t busy = 0;
+  todo_x += dx;
+  todo_y += dy;
+  
+  if( (dx!=0) || (dy!=0) ){
+    busy = 1;
+  };
+  
+
+  
+  //if end switch closed, stop moving against the stop!
+  if(XEND1_state() && (sign(todo_x) == 1) ){
+    todo_x = 0;
+  }
+  if(XEND2_state() && (sign(todo_x) == -1) ){
+    todo_x = 0;
+  }
+  if(YEND1_state() && (sign(todo_y) == 1) ){
+    todo_y = 0;
+  }
+  if(YEND2_state() && (sign(todo_y) == -1) ){
+    todo_y = 0;
+  }
+  
+  
+  signum = sign(todo_x);
+  motor_step(X,signum);
+  todo_x -= signum;
+  plate_pos_x += signum;
+  
+  
+  
+  signum = sign(todo_y);
+  motor_step(Y,signum);
+  todo_y -= signum;
+  plate_pos_y += signum;
+  
+  
+  
+  _delay_us(PHASE_DELAY_US);
+  
+  if( busy && (todo_x==0) && (todo_y==0) ){
+    busy=0;
+    return 1;
+  } else {
+    return 0;
+  }
+}
+
+
+
+
+
+
+
+  
+
+
diff --git a/firmware/plate.h b/firmware/plate.h
new file mode 100644 (file)
index 0000000..5d7ea9e
--- /dev/null
@@ -0,0 +1,15 @@
+#define PHASE_DELAY_US 0
+
+
+
+
+
+uint8_t move_plate(int32_t dx, int32_t dy);
+
+
+
+
+int32_t get_plate_pos_x(void);
+void set_plate_pos_x(int32_t value);
+int32_t get_plate_pos_y(void);
+void set_plate_pos_y(int32_t value);
\ No newline at end of file