|
@@ -1,3 +1,5 @@
|
|
1
|
+/* -*- c++ -*- */
|
|
2
|
+
|
1
|
3
|
/*
|
2
|
4
|
Reprap firmware based on Sprinter and grbl.
|
3
|
5
|
Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
|
|
@@ -141,6 +143,8 @@ volatile bool feedmultiplychanged=false;
|
141
|
143
|
volatile int extrudemultiply=100; //100->1 200->2
|
142
|
144
|
float current_position[NUM_AXIS] = { 0.0, 0.0, 0.0, 0.0 };
|
143
|
145
|
float add_homeing[3]={0,0,0};
|
|
146
|
+float min_pos[3] = { X_MIN_POS, Y_MIN_POS, Z_MIN_POS };
|
|
147
|
+float max_pos[3] = { X_MAX_POS, Y_MAX_POS, Z_MAX_POS };
|
144
|
148
|
uint8_t active_extruder = 0;
|
145
|
149
|
unsigned char FanSpeed=0;
|
146
|
150
|
|
|
@@ -199,6 +203,13 @@ bool Stopped=false;
|
199
|
203
|
|
200
|
204
|
void get_arc_coordinates();
|
201
|
205
|
|
|
206
|
+void serial_echopair_P(const char *s_P, float v)
|
|
207
|
+ { serialprintPGM(s_P); SERIAL_ECHO(v); }
|
|
208
|
+void serial_echopair_P(const char *s_P, double v)
|
|
209
|
+ { serialprintPGM(s_P); SERIAL_ECHO(v); }
|
|
210
|
+void serial_echopair_P(const char *s_P, unsigned long v)
|
|
211
|
+ { serialprintPGM(s_P); SERIAL_ECHO(v); }
|
|
212
|
+
|
202
|
213
|
extern "C"{
|
203
|
214
|
extern unsigned int __bss_end;
|
204
|
215
|
extern unsigned int __heap_start;
|
|
@@ -541,32 +552,65 @@ bool code_seen(char code)
|
541
|
552
|
return (strchr_pointer != NULL); //Return True if a character was found
|
542
|
553
|
}
|
543
|
554
|
|
544
|
|
-#define HOMEAXIS(LETTER) \
|
545
|
|
- if ((LETTER##_MIN_PIN > -1 && LETTER##_HOME_DIR==-1) || (LETTER##_MAX_PIN > -1 && LETTER##_HOME_DIR==1))\
|
546
|
|
- { \
|
547
|
|
- current_position[LETTER##_AXIS] = 0; \
|
548
|
|
- plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]); \
|
549
|
|
- destination[LETTER##_AXIS] = 1.5 * LETTER##_MAX_LENGTH * LETTER##_HOME_DIR; \
|
550
|
|
- feedrate = homing_feedrate[LETTER##_AXIS]; \
|
551
|
|
- plan_buffer_line(destination[X_AXIS], destination[Y_AXIS], destination[Z_AXIS], destination[E_AXIS], feedrate/60, active_extruder); \
|
552
|
|
- st_synchronize();\
|
553
|
|
- \
|
554
|
|
- current_position[LETTER##_AXIS] = 0;\
|
555
|
|
- plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]);\
|
556
|
|
- destination[LETTER##_AXIS] = -LETTER##_HOME_RETRACT_MM * LETTER##_HOME_DIR;\
|
557
|
|
- plan_buffer_line(destination[X_AXIS], destination[Y_AXIS], destination[Z_AXIS], destination[E_AXIS], feedrate/60, active_extruder); \
|
558
|
|
- st_synchronize();\
|
559
|
|
- \
|
560
|
|
- destination[LETTER##_AXIS] = 2*LETTER##_HOME_RETRACT_MM * LETTER##_HOME_DIR;\
|
561
|
|
- feedrate = homing_feedrate[LETTER##_AXIS]/2 ; \
|
562
|
|
- plan_buffer_line(destination[X_AXIS], destination[Y_AXIS], destination[Z_AXIS], destination[E_AXIS], feedrate/60, active_extruder); \
|
563
|
|
- st_synchronize();\
|
564
|
|
- \
|
565
|
|
- current_position[LETTER##_AXIS] = LETTER##_HOME_POS;\
|
566
|
|
- destination[LETTER##_AXIS] = current_position[LETTER##_AXIS];\
|
567
|
|
- feedrate = 0.0;\
|
568
|
|
- endstops_hit_on_purpose();\
|
|
555
|
+#define DEFINE_PGM_READ_ANY(type, reader) \
|
|
556
|
+ static inline type pgm_read_any(const type *p) \
|
|
557
|
+ { return pgm_read_##reader##_near(p); }
|
|
558
|
+
|
|
559
|
+DEFINE_PGM_READ_ANY(float, float);
|
|
560
|
+DEFINE_PGM_READ_ANY(signed char, byte);
|
|
561
|
+
|
|
562
|
+#define XYZ_CONSTS_FROM_CONFIG(type, array, CONFIG) \
|
|
563
|
+static const PROGMEM type array##_P[3] = \
|
|
564
|
+ { X_##CONFIG, Y_##CONFIG, Z_##CONFIG }; \
|
|
565
|
+static inline type array(int axis) \
|
|
566
|
+ { return pgm_read_any(&array##_P[axis]); }
|
|
567
|
+
|
|
568
|
+XYZ_CONSTS_FROM_CONFIG(float, base_min_pos, MIN_POS);
|
|
569
|
+XYZ_CONSTS_FROM_CONFIG(float, base_max_pos, MAX_POS);
|
|
570
|
+XYZ_CONSTS_FROM_CONFIG(float, base_home_pos, HOME_POS);
|
|
571
|
+XYZ_CONSTS_FROM_CONFIG(float, max_length, MAX_LENGTH);
|
|
572
|
+XYZ_CONSTS_FROM_CONFIG(float, home_retract_mm, HOME_RETRACT_MM);
|
|
573
|
+XYZ_CONSTS_FROM_CONFIG(signed char, home_dir, HOME_DIR);
|
|
574
|
+
|
|
575
|
+static void axis_is_at_home(int axis) {
|
|
576
|
+ current_position[axis] = base_home_pos(axis) + add_homeing[axis];
|
|
577
|
+ min_pos[axis] = base_min_pos(axis) + add_homeing[axis];
|
|
578
|
+ max_pos[axis] = base_max_pos(axis) + add_homeing[axis];
|
|
579
|
+}
|
|
580
|
+
|
|
581
|
+static void homeaxis(int axis) {
|
|
582
|
+#define HOMEAXIS_DO(LETTER) \
|
|
583
|
+ ((LETTER##_MIN_PIN > -1 && LETTER##_HOME_DIR==-1) || (LETTER##_MAX_PIN > -1 && LETTER##_HOME_DIR==1))
|
|
584
|
+
|
|
585
|
+ if (axis==X_AXIS ? HOMEAXIS_DO(X) :
|
|
586
|
+ axis==Y_AXIS ? HOMEAXIS_DO(Y) :
|
|
587
|
+ axis==Z_AXIS ? HOMEAXIS_DO(Z) :
|
|
588
|
+ 0) {
|
|
589
|
+ current_position[axis] = 0;
|
|
590
|
+ plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]);
|
|
591
|
+ destination[axis] = 1.5 * max_length(axis) * home_dir(axis);
|
|
592
|
+ feedrate = homing_feedrate[axis];
|
|
593
|
+ plan_buffer_line(destination[X_AXIS], destination[Y_AXIS], destination[Z_AXIS], destination[E_AXIS], feedrate/60, active_extruder);
|
|
594
|
+ st_synchronize();
|
|
595
|
+
|
|
596
|
+ current_position[axis] = 0;
|
|
597
|
+ plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]);
|
|
598
|
+ destination[axis] = -home_retract_mm(axis) * home_dir(axis);
|
|
599
|
+ plan_buffer_line(destination[X_AXIS], destination[Y_AXIS], destination[Z_AXIS], destination[E_AXIS], feedrate/60, active_extruder);
|
|
600
|
+ st_synchronize();
|
|
601
|
+
|
|
602
|
+ destination[axis] = 2*home_retract_mm(axis) * home_dir(axis);
|
|
603
|
+ feedrate = homing_feedrate[axis]/2 ;
|
|
604
|
+ plan_buffer_line(destination[X_AXIS], destination[Y_AXIS], destination[Z_AXIS], destination[E_AXIS], feedrate/60, active_extruder);
|
|
605
|
+ st_synchronize();
|
|
606
|
+
|
|
607
|
+ axis_is_at_home(axis);
|
|
608
|
+ destination[axis] = current_position[axis];
|
|
609
|
+ feedrate = 0.0;
|
|
610
|
+ endstops_hit_on_purpose();
|
569
|
611
|
}
|
|
612
|
+}
|
|
613
|
+#define HOMEAXIS(LETTER) homeaxis(LETTER##_AXIS)
|
570
|
614
|
|
571
|
615
|
void process_commands()
|
572
|
616
|
{
|
|
@@ -676,8 +720,8 @@ void process_commands()
|
676
|
720
|
plan_buffer_line(destination[X_AXIS], destination[Y_AXIS], destination[Z_AXIS], destination[E_AXIS], feedrate/60, active_extruder);
|
677
|
721
|
st_synchronize();
|
678
|
722
|
|
679
|
|
- current_position[X_AXIS] = X_HOME_POS;
|
680
|
|
- current_position[Y_AXIS] = Y_HOME_POS;
|
|
723
|
+ axis_is_at_home(X_AXIS);
|
|
724
|
+ axis_is_at_home(Y_AXIS);
|
681
|
725
|
plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]);
|
682
|
726
|
destination[X_AXIS] = current_position[X_AXIS];
|
683
|
727
|
destination[Y_AXIS] = current_position[Y_AXIS];
|
|
@@ -1539,19 +1583,25 @@ void get_arc_coordinates()
|
1539
|
1583
|
}
|
1540
|
1584
|
}
|
1541
|
1585
|
|
1542
|
|
-void prepare_move()
|
|
1586
|
+void clamp_to_software_endstops(float target[3])
|
1543
|
1587
|
{
|
1544
|
1588
|
if (min_software_endstops) {
|
1545
|
|
- if (destination[X_AXIS] < X_MIN_POS) destination[X_AXIS] = X_MIN_POS;
|
1546
|
|
- if (destination[Y_AXIS] < Y_MIN_POS) destination[Y_AXIS] = Y_MIN_POS;
|
1547
|
|
- if (destination[Z_AXIS] < Z_MIN_POS) destination[Z_AXIS] = Z_MIN_POS;
|
|
1589
|
+ if (target[X_AXIS] < min_pos[X_AXIS]) target[X_AXIS] = min_pos[X_AXIS];
|
|
1590
|
+ if (target[Y_AXIS] < min_pos[Y_AXIS]) target[Y_AXIS] = min_pos[Y_AXIS];
|
|
1591
|
+ if (target[Z_AXIS] < min_pos[Z_AXIS]) target[Z_AXIS] = min_pos[Z_AXIS];
|
1548
|
1592
|
}
|
1549
|
1593
|
|
1550
|
1594
|
if (max_software_endstops) {
|
1551
|
|
- if (destination[X_AXIS] > X_MAX_POS) destination[X_AXIS] = X_MAX_POS;
|
1552
|
|
- if (destination[Y_AXIS] > Y_MAX_POS) destination[Y_AXIS] = Y_MAX_POS;
|
1553
|
|
- if (destination[Z_AXIS] > Z_MAX_POS) destination[Z_AXIS] = Z_MAX_POS;
|
|
1595
|
+ if (target[X_AXIS] > max_pos[X_AXIS]) target[X_AXIS] = max_pos[X_AXIS];
|
|
1596
|
+ if (target[Y_AXIS] > max_pos[Y_AXIS]) target[Y_AXIS] = max_pos[Y_AXIS];
|
|
1597
|
+ if (target[Z_AXIS] > max_pos[Z_AXIS]) target[Z_AXIS] = max_pos[Z_AXIS];
|
1554
|
1598
|
}
|
|
1599
|
+}
|
|
1600
|
+
|
|
1601
|
+void prepare_move()
|
|
1602
|
+{
|
|
1603
|
+ clamp_to_software_endstops(destination);
|
|
1604
|
+
|
1555
|
1605
|
previous_millis_cmd = millis();
|
1556
|
1606
|
plan_buffer_line(destination[X_AXIS], destination[Y_AXIS], destination[Z_AXIS], destination[E_AXIS], feedrate*feedmultiply/60/100.0, active_extruder);
|
1557
|
1607
|
for(int8_t i=0; i < NUM_AXIS; i++) {
|