]> jspc29.x-matter.uni-frankfurt.de Git - coral.git/commitdiff
now working quite nice, solved a lot of old bugs, correct length scaling
authorMichael Wiebusch <m.wiebusch@gsi.de>
Fri, 12 Dec 2014 19:42:04 +0000 (20:42 +0100)
committerMichael Wiebusch <m.wiebusch@gsi.de>
Fri, 12 Dec 2014 19:42:04 +0000 (20:42 +0100)
firmware/main.c
firmware/misc.c
firmware/misc.h
firmware/motors.c
firmware/motors.h

index fed609984041e8cb09e4e24462b97616e529ea21..912b737dc7c0d5f3426e3b8d4f4af48c7621fd31 100644 (file)
@@ -9,18 +9,30 @@
 #include "pins.h"
 
 
-int16_t plate_pos_x = 0,plate_pos_y = 0;
-  
-void print_steps_in_mm(int16_t steps) {
-  int16_t predot,postdot;
+#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;
+}
+
+int32_t um_to_steps (int32_t um){
+  return um*STEPS_PER_ROUND/UM_PER_ROUND;
+}
   
-  predot = steps/24;
-  postdot = ((abs(steps)%24)*417)/10;
-  uart_print_signed_number(predot,3);
+void print_steps_in_mm(int32_t steps) {
+  int32_t um = steps_to_um(steps);
+  uint16_t predot = abs(um/1000);
+  uint16_t postdot = abs(um%1000);
+  uart_print_sign(steps);
+  uart_print_number(predot,3);
   uart_putc('.');
   uart_print_number_wlzeros(postdot,3);
-  
 }
+
+
   
 void pos_report(void){ 
     uart_puts("x_pos: ");
@@ -126,19 +138,20 @@ void parse_command(void){
         
       }
       
-      int16_t steps = 0,dest=0;
+      int32_t steps = 0,dest=0;
       
       switch (action) {
         case GOTO:
           uart_puts("GOTO ");
           uart_putc(88+axis);// x or y
           uart_putc(' ');
-          uart_print_signed_number(predot*num_sign,3);
+          uart_print_sign(num_sign);
+          uart_print_number(predot,3);
           uart_putc('.');
           uart_print_number_wlzeros(postdot,3);
           uart_puts("\r\n"); 
           
-          dest = num_sign *( predot*24 +(postdot*10)/416);
+          dest = um_to_steps(num_sign*(((int32_t) predot) *1000 + ((int32_t) postdot)));
           
           if (axis == X) {
             steps = dest - plate_pos_x; // experimental correction!
@@ -156,12 +169,13 @@ void parse_command(void){
           uart_puts("MOVE ");
           uart_putc(88+axis);// x or y
           uart_putc(' ');
-          uart_print_signed_number(predot*num_sign,3);
+          uart_print_sign(num_sign);
+          uart_print_number(predot,3);
           uart_putc('.');
           uart_print_number_wlzeros(postdot,3);
           uart_puts("\r\n"); 
           
-          steps = num_sign *( predot*24 +(postdot*10)/416);
+          steps = um_to_steps(num_sign*(((int32_t) predot) *1000 + ((int32_t) postdot)));
           
           if (axis == X) {
             move_plate(steps,0);
index b09a03d7805bd833cb98defc5d4d2ad69619c1c8..623ec9e12a935247b2da8bd3596d31ca51818372 100644 (file)
@@ -36,23 +36,31 @@ int8_t sign(int16_t x) {
 
 
 void uart_print_number(uint32_t zahl, uint8_t no_digits) {
-  my_uitoa(abs(zahl),stringbuffer,no_digits,' ');
+  my_uitoa(zahl,stringbuffer,no_digits,' ');
   uart_puts(stringbuffer);
 }
 
 
 void uart_print_number_wlzeros(uint32_t zahl, uint8_t no_digits) {
-  my_uitoa(abs(zahl),stringbuffer,no_digits,'0');
+  my_uitoa(zahl,stringbuffer,no_digits,'0');
   uart_puts(stringbuffer);
 }
 
-void uart_print_signed_number(uint32_t zahl, uint8_t no_digits) {
+void uart_print_signed_number(int32_t zahl, uint8_t no_digits) {
   my_uitoa(abs(zahl),stringbuffer,no_digits,' ');
-  if (sign(zahl) < 0) {
+  if (zahl < 0) {
     uart_putc('-');
   } else {
     uart_putc('+');
   }
   uart_puts(stringbuffer);
   
+}
+
+void uart_print_sign(int32_t zahl){
+  if (zahl < 0) {
+    uart_putc('-');
+  } else {
+    uart_putc('+');
+  }
 }
\ No newline at end of file
index c2a9b16dee005fdc5df1ce767d170a66b1cade68..cf0df80e0f46c7f1b79c6dfdbfa401c39c46b5c6 100644 (file)
@@ -5,8 +5,8 @@ uint32_t times_ten_pow(uint8_t exponent);
 int8_t sign(int16_t x);
 void uart_print_number(uint32_t zahl, uint8_t no_digits);
 void uart_print_number_wlzeros(uint32_t zahl, uint8_t no_digits);
-void uart_print_signed_number(uint32_t zahl, uint8_t no_digits);
-
+void uart_print_signed_number(int32_t zahl, uint8_t no_digits);
+void uart_print_sign(int32_t zahl);
 
 
 
index 59d628110bcebbb720839e71e3b97bf8dbd0e346..94bc4ab16a7a19e06400ce94b0cf0bda8da0bb66 100644 (file)
@@ -7,7 +7,20 @@
 
 
 
-
+// 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 */
 
@@ -93,8 +106,8 @@ uint8_t motor_step(uint8_t motor, int8_t direction) { // motor: M1 or M2, direct
 
 
 
-uint8_t move_plate(int16_t dx, int16_t dy){
-  static int16_t todo_x,todo_y = 0;
+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;
index 2d507e9fc1524bd38674218ad673d3ec1c70e088..4008f40cc0d7146d0b603eab58254cc5fe667869 100644 (file)
@@ -51,7 +51,7 @@ 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(int16_t dx, int16_t dy);
+uint8_t move_plate(int32_t dx, int32_t dy);