From: Michael Wiebusch Date: Fri, 12 Dec 2014 21:24:27 +0000 (+0100) Subject: now endstops work AND report as desired X-Git-Url: https://jspc29.x-matter.uni-frankfurt.de/git/?a=commitdiff_plain;h=24f075a99f45885705c9ee7195d163601c57af76;p=coral.git now endstops work AND report as desired --- diff --git a/firmware/main.c b/firmware/main.c index 912b737..9cd835f 100644 --- a/firmware/main.c +++ b/firmware/main.c @@ -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); } diff --git a/firmware/makefile b/firmware/makefile index 6de0b6a..9e05df6 100644 --- a/firmware/makefile +++ b/firmware/makefile @@ -18,7 +18,7 @@ F_CPU = 16000000 F_USB = $(F_CPU) OPTIMIZATION = s TARGET = main -SRC = $(TARGET).c Descriptors.c $(LUFA_SRC_USB) $(LUFA_SRC_USBCLASS) pins.c TM1001A.c motors.c misc.c USBtoSerial.c +SRC = $(TARGET).c Descriptors.c $(LUFA_SRC_USB) $(LUFA_SRC_USBCLASS) plate.c pins.c TM1001A.c motors.c misc.c USBtoSerial.c LUFA_PATH = ../LUFA/LUFA-130303/LUFA CC_FLAGS = -DUSE_LUFA_CONFIG_HEADER -IConfig/ LD_FLAGS = diff --git a/firmware/motors.c b/firmware/motors.c index 94bc4ab..c635258 100644 --- a/firmware/motors.c +++ b/firmware/motors.c @@ -2,25 +2,11 @@ #include #include #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 - -} - - - - - - diff --git a/firmware/motors.h b/firmware/motors.h index 4008f40..6fca92d 100644 --- a/firmware/motors.h +++ b/firmware/motors.h @@ -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 index 0000000..9c881e7 --- /dev/null +++ b/firmware/plate.c @@ -0,0 +1,89 @@ +#include +#include +#include +#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 index 0000000..5d7ea9e --- /dev/null +++ b/firmware/plate.h @@ -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