}
-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){
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();
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;
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;
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();
+ }
}
// 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);
-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