]> jspc29.x-matter.uni-frankfurt.de Git - coral.git/commitdiff
greatly improved the concept of moving the plate
authorMichael Wiebusch <m.wiebusch@gsi.de>
Mon, 15 Dec 2014 15:10:24 +0000 (16:10 +0100)
committerMichael Wiebusch <m.wiebusch@gsi.de>
Mon, 15 Dec 2014 15:10:24 +0000 (16:10 +0100)
firmware/main.c
firmware/plate.c
firmware/plate.h

index 9cd835f46e5bd903a0fd9fb3e73db46ef5bbf310..a192a88edc9aac58c07dd13251e11fd8a2432e65 100644 (file)
@@ -48,13 +48,6 @@ 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;
 
 void parse_command(void){
@@ -160,11 +153,13 @@ void parse_command(void){
           dest = um_to_steps(num_sign*(((int32_t) predot) *1000 + ((int32_t) postdot)));
           
           if (axis == X) {
-            steps = dest - get_plate_pos_x(); // experimental correction!
-            move_and_report(steps,0);
+//             steps = dest - get_plate_pos_x(); // experimental correction!
+//             move_and_report(steps,0);
+            set_target_plate_pos_x(dest);
           } else if (axis == Y) {
-            steps = dest - get_plate_pos_y();
-            move_and_report(0,steps);
+//             steps = dest - get_plate_pos_y();
+//             move_and_report(0,steps);
+            set_target_plate_pos_y(dest);
           }
 //           pos_report();
           
@@ -182,9 +177,11 @@ void parse_command(void){
           steps = um_to_steps(num_sign*(((int32_t) predot) *1000 + ((int32_t) postdot)));
           
           if (axis == X) {
-            move_and_report(steps,0);
+//             move_and_report(steps,0);
+            set_target_plate_pos_x(get_target_plate_pos_x()+steps);
           } else if (axis == Y) {
-            move_and_report(0,steps);
+//             move_and_report(0,steps);
+            set_target_plate_pos_y(get_target_plate_pos_y()+steps);
           }
 //           pos_report();
           break;
@@ -192,6 +189,8 @@ void parse_command(void){
         case SETZERO:
           set_plate_pos_x(0);
           set_plate_pos_y(0);
+          set_target_plate_pos_x(0);
+          set_target_plate_pos_y(0);
           pos_report();
           break;
           
@@ -233,15 +232,16 @@ int main(void){
   sei();
   
   touchpad_set_rel_mode_100dpi();// use touchpad in relative mode
-  int8_t dx, dy = 0;
 
   while (1) {
     Usb2SerialTask();
     parse_command(); // read data from virtual comport
     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
-    move_and_report(dx,dy);
+    inc_target_plate_pos_x(4*delta_x());
+    inc_target_plate_pos_y(-4*delta_y());
+    if(move_plate()){
+      pos_report();
+    }
   }
 
 
index 9c881e7b6b1fe3761949d756c9c23a9e1aa84f72..aeb7be5fb1d246f7439ffa59640f683966c8ce73 100644 (file)
 // plate stuff
 
 int32_t plate_pos_x = 0,plate_pos_y = 0;
+int32_t target_plate_pos_x = 0,target_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_x(int32_t value){
+  plate_pos_x = value;
+}
 void set_plate_pos_y(int32_t value){
   plate_pos_y = value;
 }
+int32_t get_target_plate_pos_x(void){
+  return target_plate_pos_x;
+}
+int32_t get_target_plate_pos_y(void){
+  return target_plate_pos_y;
+}
+void set_target_plate_pos_x(int32_t value){
+  target_plate_pos_x = value;
+}
+void set_target_plate_pos_y(int32_t value){
+  target_plate_pos_y = value;
+}
+void inc_target_plate_pos_x(int32_t value){
+  target_plate_pos_x += value;
+}
+void inc_target_plate_pos_y(int32_t value){
+  target_plate_pos_y += value;
+}
 
 
-uint8_t move_plate(int32_t dx, int32_t dy){
-  static int32_t todo_x,todo_y = 0;
+uint8_t move_plate(void){
+  int32_t todo_x,todo_y = 0;
   int8_t signum;
   static uint8_t busy = 0;
-  todo_x += dx;
-  todo_y += dy;
+  todo_x = target_plate_pos_x-plate_pos_x;
+  todo_y = target_plate_pos_y-plate_pos_y;
   
-  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;
+    target_plate_pos_x = plate_pos_x;
   }
   if(XEND2_state() && (sign(todo_x) == -1) ){
     todo_x = 0;
+    target_plate_pos_x = plate_pos_x;
   }
   if(YEND1_state() && (sign(todo_y) == 1) ){
     todo_y = 0;
+    target_plate_pos_y = plate_pos_y;
   }
   if(YEND2_state() && (sign(todo_y) == -1) ){
     todo_y = 0;
+    target_plate_pos_y = plate_pos_y;
   }
   
+  if( (todo_x!=0) || (todo_y!=0) ){
+    busy = 1;
+  };
+  
   
   signum = sign(todo_x);
   motor_step(X,signum);
index 5d7ea9efb13b709fa69af5da08c5f7a6f24be590..55fad924c54da1b636a0995be161e4f24ce1a053 100644 (file)
@@ -4,12 +4,18 @@
 
 
 
-uint8_t move_plate(int32_t dx, int32_t dy);
+uint8_t move_plate(void);
 
 
 
 
 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
+void set_plate_pos_x(int32_t value);
+void set_plate_pos_y(int32_t value);
+int32_t get_target_plate_pos_x(void);
+int32_t get_target_plate_pos_y(void);
+void set_target_plate_pos_x(int32_t value);
+void set_target_plate_pos_y(int32_t value);
+void inc_target_plate_pos_x(int32_t value);
+void inc_target_plate_pos_y(int32_t value);
\ No newline at end of file