#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;
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);
}
+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;
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:
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;
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();
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);
}
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
#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 */
-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
-
-}
-
-
-
-
-
-
-#define PHASE_DELAY_US 0
-
#define X 0
#define Y 1
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);
--- /dev/null
+#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;
+ }
+}
+
+
+
+
+
+
+
+
+
+
--- /dev/null
+#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