Browse Source

First arcs version. (Arcs not working ok)

Erik van der Zalm 12 years ago
parent
commit
0b82465168
4 changed files with 1784 additions and 1479 deletions
  1. 248
    245
      Marlin/Configuration.h
  2. 1371
    1234
      Marlin/Marlin.pde
  3. 133
    0
      Marlin/motion_control.cpp
  4. 32
    0
      Marlin/motion_control.h

+ 248
- 245
Marlin/Configuration.h View File

@@ -1,245 +1,248 @@
1
-#ifndef CONFIGURATION_H


2
-#define CONFIGURATION_H


3
-


4
-//#define DEBUG_STEPS


5
-


6
-// BASIC SETTINGS: select your board type, thermistor type, axis scaling, and endstop configuration


7
-


8
-//// The following define selects which electronics board you have. Please choose the one that matches your setup


9
-// MEGA/RAMPS up to 1.2 = 3,


10
-// RAMPS 1.3 = 33


11
-// Gen6 = 5,


12
-// Sanguinololu 1.2 and above = 62


13
-// Ultimaker = 7,


14
-#define MOTHERBOARD 7


15
-//#define MOTHERBOARD 5


16
-


17
-


18
-//// Thermistor settings:


19
-// 1 is 100k thermistor


20
-// 2 is 200k thermistor


21
-// 3 is mendel-parts thermistor


22
-// 4 is 10k thermistor


23
-// 5 is ParCan supplied 104GT-2 100K


24
-// 6 is EPCOS 100k


25
-// 7 is 100k Honeywell thermistor 135-104LAG-J01


26
-#define THERMISTORHEATER_1 3


27
-#define THERMISTORHEATER_2 3


28
-#define THERMISTORBED 3


29
-


30
-//#define HEATER_0_USES_THERMISTOR


31
-//#define HEATER_1_USES_THERMISTOR


32
-#define HEATER_0_USES_AD595


33
-//#define HEATER_1_USES_AD595


34
-


35
-// Select one of these only to define how the bed temp is read.


36
-//#define BED_USES_THERMISTOR


37
-//#define BED_USES_AD595


38
-


39
-#define HEATER_CHECK_INTERVAL 50


40
-#define BED_CHECK_INTERVAL 5000


41
-


42
-


43
-//// Endstop Settings


44
-#define ENDSTOPPULLUPS // Comment this out (using // at the start of the line) to disable the endstop pullup resistors


45
-// The pullups are needed if you directly connect a mechanical endswitch between the signal and ground pins.


46
-const bool ENDSTOPS_INVERTING = true; // set to true to invert the logic of the endstops. 


47
-// For optos H21LOB set to true, for Mendel-Parts newer optos TCST2103 set to false


48
-


49
-// This determines the communication speed of the printer


50
-#define BAUDRATE 250000


51
-//#define BAUDRATE 115200


52
-//#define BAUDRATE 230400


53
-


54
-// Comment out (using // at the start of the line) to disable SD support:


55
-


56
-// #define ULTRA_LCD  //any lcd 


57
-


58
-#define ULTIPANEL


59
-#define ULTIPANEL


60
-#ifdef ULTIPANEL


61
- //#define NEWPANEL  //enable this if you have a click-encoder panel


62
- #define SDSUPPORT


63
- #define ULTRA_LCD


64
- #define LCD_WIDTH 20


65
-#define LCD_HEIGHT 4


66
-#else //no panel but just lcd 


67
-  #ifdef ULTRA_LCD


68
-    #define LCD_WIDTH 16


69
-    #define LCD_HEIGHT 2


70
-  #endif


71
-#endif


72
-


73
-


74
-//#define SDSUPPORT // Enable SD Card Support in Hardware Console


75
-


76
-


77
-


78
-const int dropsegments=5; //everything with this number of steps  will be ignored as move


79
-


80
-//// ADVANCED SETTINGS - to tweak parameters


81
-


82
-#include "thermistortables.h"


83
-


84
-// For Inverting Stepper Enable Pins (Active Low) use 0, Non Inverting (Active High) use 1


85
-#define X_ENABLE_ON 0


86
-#define Y_ENABLE_ON 0


87
-#define Z_ENABLE_ON 0


88
-#define E_ENABLE_ON 0


89
-


90
-// Disables axis when it's not being used.


91
-#define DISABLE_X false


92
-#define DISABLE_Y false


93
-#define DISABLE_Z false


94
-#define DISABLE_E false


95
-


96
-// Inverting axis direction


97
-#define INVERT_X_DIR true    // for Mendel set to false, for Orca set to true


98
-#define INVERT_Y_DIR false   // for Mendel set to true, for Orca set to false


99
-#define INVERT_Z_DIR true    // for Mendel set to false, for Orca set to true


100
-#define INVERT_E_DIR false   // for direct drive extruder v9 set to true, for geared extruder set to false


101
-


102
-//// ENDSTOP SETTINGS:


103
-// Sets direction of endstops when homing; 1=MAX, -1=MIN


104
-#define X_HOME_DIR -1


105
-#define Y_HOME_DIR -1


106
-#define Z_HOME_DIR -1


107
-


108
-#define min_software_endstops false //If true, axis won't move to coordinates less than zero.


109
-#define max_software_endstops false  //If true, axis won't move to coordinates greater than the defined lengths below.


110
-#define X_MAX_LENGTH 210


111
-#define Y_MAX_LENGTH 210


112
-#define Z_MAX_LENGTH 210


113
-


114
-//// MOVEMENT SETTINGS


115
-#define NUM_AXIS 4 // The axis order in all axis related arrays is X, Y, Z, E


116
-//note: on bernhards ultimaker 200 200 12 are working well.


117
-#define HOMING_FEEDRATE {50*60, 50*60, 12*60, 0}  // set the homing speeds


118
-//the followint checks if an extrusion is existent in the move. if _not_, the speed of the move is set to the maximum speed. 


119
-//!!!!!!Use only if you know that your printer works at the maximum declared speeds.


120
-// works around the skeinforge cool-bug. There all moves are slowed to have a minimum layer time. However slow travel moves= ooze


121
-#define TRAVELING_AT_MAXSPEED  


122
-#define AXIS_RELATIVE_MODES {false, false, false, false}


123
-


124
-#define MAX_STEP_FREQUENCY 40000 // Max step frequency for Ultimaker (5000 pps / half step)


125
-


126
-// default settings 


127
-


128
-#define DEFAULT_AXIS_STEPS_PER_UNIT   {79.87220447,79.87220447,200*8/3,14}                    // default steps per unit for ultimaker 


129
-#define DEFAULT_MAX_FEEDRATE          {160*60, 160*60, 10*60, 500000}        


130
-#define DEFAULT_MAX_ACCELERATION      {9000,9000,150,10000}    // X, Y, Z, E maximum start speed for accelerated moves. E default values are good for skeinforge 40+, for older versions raise them a lot.


131
-


132
-#define DEFAULT_ACCELERATION          3000    // X, Y, Z and E max acceleration in mm/s^2 for printing moves 


133
-#define DEFAULT_RETRACT_ACCELERATION  7000   // X, Y, Z and E max acceleration in mm/s^2 for r retracts


134
-


135
-#define DEFAULT_MINIMUMFEEDRATE       10     // minimum feedrate


136
-#define DEFAULT_MINTRAVELFEEDRATE     10


137
-


138
-// minimum time in microseconds that a movement needs to take if the buffer is emptied.   Increase this number if you see blobs while printing high speed & high detail.  It will slowdown on the detailed stuff.


139
-#define DEFAULT_MINSEGMENTTIME        20000


140
-#define DEFAULT_XYJERK                30.0*60    


141
-#define DEFAULT_ZJERK                 10.0*60


142
-


143
-


144
-// The watchdog waits for the watchperiod in milliseconds whenever an M104 or M109 increases the target temperature


145
-//this enables the watchdog interrupt.


146
-#define USE_WATCHDOG


147
-//you cannot reboot on a mega2560 due to a bug in he bootloader. Hence, you have to reset manually, and this is done hereby:


148
-#define RESET_MANUAL


149
-


150
-#define WATCHDOG_TIMEOUT 4


151
-


152
-


153
-


154
-//// Experimental watchdog and minimal temp


155
-// The watchdog waits for the watchperiod in milliseconds whenever an M104 or M109 increases the target temperature


156
-// If the temperature has not increased at the end of that period, the target temperature is set to zero. It can be reset with another M104/M109


157
-//#define WATCHPERIOD 5000 //5 seconds


158
-


159
-// Actual temperature must be close to target for this long before M109 returns success


160
-//#define TEMP_RESIDENCY_TIME 20  // (seconds)


161
-//#define TEMP_HYSTERESIS 5       // (C°) range of +/- temperatures considered "close" to the target one


162
-


163
-//// The minimal temperature defines the temperature below which the heater will not be enabled


164
-#define HEATER_0_MINTEMP 5


165
-//#define HEATER_1_MINTEMP 5


166
-//#define BED_MINTEMP 5


167
-


168
-


169
-// When temperature exceeds max temp, your heater will be switched off.


170
-// This feature exists to protect your hotend from overheating accidentally, but *NOT* from thermistor short/failure!


171
-// You should use MINTEMP for thermistor short/failure protection.


172
-#define HEATER_0_MAXTEMP 275


173
-//#define_HEATER_1_MAXTEMP 275


174
-//#define BED_MAXTEMP 150


175
-


176
-


177
-


178
-


179
-


180
-


181
-


182
-#define PIDTEMP


183
-#ifdef PIDTEMP


184
-  /// PID settings:


185
-  // Uncomment the following line to enable PID support.


186
-  //#define SMOOTHING


187
-  //#define SMOOTHFACTOR 5.0


188
-  //float current_raw_average=0;


189
-    #define K1 0.95 //smoothing of the PID


190
-  //#define PID_DEBUG // Sends debug data to the serial port. 


191
-  //#define PID_OPENLOOP 1 // Puts PID in open loop. M104 sets the output power in %


192
-  #define PID_MAX 255 // limits current to nozzle


193
-  #define PID_INTEGRAL_DRIVE_MAX 255


194
-  #define PID_dT 0.1


195
- //machine with red silicon: 1950:45 second ; with fan fully blowin 3000:47


196
-


197
-  #define PID_CRITIAL_GAIN 3000


198
-  #define PID_SWING_AT_CRITIAL 45 //seconds


199
-  #define PIDIADD 5


200
-  /*


201
-  //PID according to Ziegler-Nichols method


202
-  float Kp = 0.6*PID_CRITIAL_GAIN; 


203
-  float Ki =PIDIADD+2*Kp/PID_SWING_AT_CRITIAL*PID_dT;  


204
-  float Kd = Kp*PID_SWING_AT_CRITIAL/8./PID_dT;  


205
-  */


206
-  //PI according to Ziegler-Nichols method


207
-  #define  DEFAULT_Kp (PID_CRITIAL_GAIN/2.2) 


208
-  #define  DEFAULT_Ki (1.2*Kp/PID_SWING_AT_CRITIAL*PID_dT)


209
-  #define  DEFAULT_Kd (0)


210
-  


211
-  #define PID_ADD_EXTRUSION_RATE  


212
-  #ifdef PID_ADD_EXTRUSION_RATE


213
-    #define  DEFAULT_Kc (5) //heatingpower=Kc*(e_speed)


214
-  #endif


215
-#endif // PIDTEMP


216
-


217
-// extruder advance constant (s2/mm3)


218
-//


219
-// advance (steps) = STEPS_PER_CUBIC_MM_E * EXTUDER_ADVANCE_K * cubic mm per second ^ 2


220
-//


221
-// hooke's law says:		force = k * distance


222
-// bernoulli's priniciple says:	v ^ 2 / 2 + g . h + pressure / density = constant


223
-// so: v ^ 2 is proportional to number of steps we advance the extruder


224
-//#define ADVANCE


225
-


226
-#ifdef ADVANCE


227
-#define EXTRUDER_ADVANCE_K .3


228
-


229
-#define D_FILAMENT 1.7


230
-#define STEPS_MM_E 65


231
-#define EXTRUTION_AREA (0.25 * D_FILAMENT * D_FILAMENT * 3.14159)


232
-#define STEPS_PER_CUBIC_MM_E (axis_steps_per_unit[E_AXIS]/ EXTRUTION_AREA)


233
-


234
-#endif // ADVANCE


235
-


236
-// THE BLOCK_BUFFER_SIZE NEEDS TO BE A POWER OF 2, e.g. 8,16,32 


237
-#if defined SDSUPPORT


238
-// The number of linear motions that can be in the plan at any give time.  


239
-  #define BLOCK_BUFFER_SIZE 16   // SD,LCD,Buttons take more memory, block buffer needs to be smaller


240
-#else


241
-  #define BLOCK_BUFFER_SIZE 16 // maximize block buffer


242
-#endif


243
-


244
-


245
-#endif


1
+#ifndef CONFIGURATION_H
2
+#define CONFIGURATION_H
3
+
4
+//#define DEBUG_STEPS
5
+
6
+#define MM_PER_ARC_SEGMENT 1
7
+#define N_ARC_CORRECTION 25
8
+
9
+// BASIC SETTINGS: select your board type, thermistor type, axis scaling, and endstop configuration
10
+
11
+//// The following define selects which electronics board you have. Please choose the one that matches your setup
12
+// MEGA/RAMPS up to 1.2 = 3,
13
+// RAMPS 1.3 = 33
14
+// Gen6 = 5,
15
+// Sanguinololu 1.2 and above = 62
16
+// Ultimaker = 7,
17
+#define MOTHERBOARD 7
18
+//#define MOTHERBOARD 5
19
+
20
+
21
+//// Thermistor settings:
22
+// 1 is 100k thermistor
23
+// 2 is 200k thermistor
24
+// 3 is mendel-parts thermistor
25
+// 4 is 10k thermistor
26
+// 5 is ParCan supplied 104GT-2 100K
27
+// 6 is EPCOS 100k
28
+// 7 is 100k Honeywell thermistor 135-104LAG-J01
29
+#define THERMISTORHEATER_1 3
30
+#define THERMISTORHEATER_2 3
31
+#define THERMISTORBED 3
32
+
33
+//#define HEATER_0_USES_THERMISTOR
34
+//#define HEATER_1_USES_THERMISTOR
35
+#define HEATER_0_USES_AD595
36
+//#define HEATER_1_USES_AD595
37
+
38
+// Select one of these only to define how the bed temp is read.
39
+//#define BED_USES_THERMISTOR
40
+//#define BED_USES_AD595
41
+
42
+#define HEATER_CHECK_INTERVAL 50
43
+#define BED_CHECK_INTERVAL 5000
44
+
45
+
46
+//// Endstop Settings
47
+#define ENDSTOPPULLUPS // Comment this out (using // at the start of the line) to disable the endstop pullup resistors
48
+// The pullups are needed if you directly connect a mechanical endswitch between the signal and ground pins.
49
+const bool ENDSTOPS_INVERTING = true; // set to true to invert the logic of the endstops. 
50
+// For optos H21LOB set to true, for Mendel-Parts newer optos TCST2103 set to false
51
+
52
+// This determines the communication speed of the printer
53
+#define BAUDRATE 250000
54
+//#define BAUDRATE 115200
55
+//#define BAUDRATE 230400
56
+
57
+// Comment out (using // at the start of the line) to disable SD support:
58
+
59
+// #define ULTRA_LCD  //any lcd 
60
+
61
+#define ULTIPANEL
62
+#define ULTIPANEL
63
+#ifdef ULTIPANEL
64
+ //#define NEWPANEL  //enable this if you have a click-encoder panel
65
+ #define SDSUPPORT
66
+ #define ULTRA_LCD
67
+ #define LCD_WIDTH 20
68
+#define LCD_HEIGHT 4
69
+#else //no panel but just lcd 
70
+  #ifdef ULTRA_LCD
71
+    #define LCD_WIDTH 16
72
+    #define LCD_HEIGHT 2
73
+  #endif
74
+#endif
75
+
76
+
77
+//#define SDSUPPORT // Enable SD Card Support in Hardware Console
78
+
79
+
80
+
81
+const int dropsegments=5; //everything with this number of steps  will be ignored as move
82
+
83
+//// ADVANCED SETTINGS - to tweak parameters
84
+
85
+#include "thermistortables.h"
86
+
87
+// For Inverting Stepper Enable Pins (Active Low) use 0, Non Inverting (Active High) use 1
88
+#define X_ENABLE_ON 0
89
+#define Y_ENABLE_ON 0
90
+#define Z_ENABLE_ON 0
91
+#define E_ENABLE_ON 0
92
+
93
+// Disables axis when it's not being used.
94
+#define DISABLE_X false
95
+#define DISABLE_Y false
96
+#define DISABLE_Z false
97
+#define DISABLE_E false
98
+
99
+// Inverting axis direction
100
+#define INVERT_X_DIR true    // for Mendel set to false, for Orca set to true
101
+#define INVERT_Y_DIR false   // for Mendel set to true, for Orca set to false
102
+#define INVERT_Z_DIR true    // for Mendel set to false, for Orca set to true
103
+#define INVERT_E_DIR false   // for direct drive extruder v9 set to true, for geared extruder set to false
104
+
105
+//// ENDSTOP SETTINGS:
106
+// Sets direction of endstops when homing; 1=MAX, -1=MIN
107
+#define X_HOME_DIR -1
108
+#define Y_HOME_DIR -1
109
+#define Z_HOME_DIR -1
110
+
111
+#define min_software_endstops false //If true, axis won't move to coordinates less than zero.
112
+#define max_software_endstops false  //If true, axis won't move to coordinates greater than the defined lengths below.
113
+#define X_MAX_LENGTH 210
114
+#define Y_MAX_LENGTH 210
115
+#define Z_MAX_LENGTH 210
116
+
117
+//// MOVEMENT SETTINGS
118
+#define NUM_AXIS 4 // The axis order in all axis related arrays is X, Y, Z, E
119
+//note: on bernhards ultimaker 200 200 12 are working well.
120
+#define HOMING_FEEDRATE {50*60, 50*60, 12*60, 0}  // set the homing speeds
121
+//the followint checks if an extrusion is existent in the move. if _not_, the speed of the move is set to the maximum speed. 
122
+//!!!!!!Use only if you know that your printer works at the maximum declared speeds.
123
+// works around the skeinforge cool-bug. There all moves are slowed to have a minimum layer time. However slow travel moves= ooze
124
+#define TRAVELING_AT_MAXSPEED  
125
+#define AXIS_RELATIVE_MODES {false, false, false, false}
126
+
127
+#define MAX_STEP_FREQUENCY 40000 // Max step frequency for Ultimaker (5000 pps / half step)
128
+
129
+// default settings 
130
+
131
+#define DEFAULT_AXIS_STEPS_PER_UNIT   {79.87220447,79.87220447,200*8/3,14}                    // default steps per unit for ultimaker 
132
+#define DEFAULT_MAX_FEEDRATE          {160*60, 160*60, 10*60, 500000}        
133
+#define DEFAULT_MAX_ACCELERATION      {9000,9000,150,10000}    // X, Y, Z, E maximum start speed for accelerated moves. E default values are good for skeinforge 40+, for older versions raise them a lot.
134
+
135
+#define DEFAULT_ACCELERATION          3000    // X, Y, Z and E max acceleration in mm/s^2 for printing moves 
136
+#define DEFAULT_RETRACT_ACCELERATION  7000   // X, Y, Z and E max acceleration in mm/s^2 for r retracts
137
+
138
+#define DEFAULT_MINIMUMFEEDRATE       10     // minimum feedrate
139
+#define DEFAULT_MINTRAVELFEEDRATE     10
140
+
141
+// minimum time in microseconds that a movement needs to take if the buffer is emptied.   Increase this number if you see blobs while printing high speed & high detail.  It will slowdown on the detailed stuff.
142
+#define DEFAULT_MINSEGMENTTIME        20000
143
+#define DEFAULT_XYJERK                30.0*60    
144
+#define DEFAULT_ZJERK                 10.0*60
145
+
146
+
147
+// The watchdog waits for the watchperiod in milliseconds whenever an M104 or M109 increases the target temperature
148
+//this enables the watchdog interrupt.
149
+#define USE_WATCHDOG
150
+//you cannot reboot on a mega2560 due to a bug in he bootloader. Hence, you have to reset manually, and this is done hereby:
151
+#define RESET_MANUAL
152
+
153
+#define WATCHDOG_TIMEOUT 4
154
+
155
+
156
+
157
+//// Experimental watchdog and minimal temp
158
+// The watchdog waits for the watchperiod in milliseconds whenever an M104 or M109 increases the target temperature
159
+// If the temperature has not increased at the end of that period, the target temperature is set to zero. It can be reset with another M104/M109
160
+//#define WATCHPERIOD 5000 //5 seconds
161
+
162
+// Actual temperature must be close to target for this long before M109 returns success
163
+//#define TEMP_RESIDENCY_TIME 20  // (seconds)
164
+//#define TEMP_HYSTERESIS 5       // (C°) range of +/- temperatures considered "close" to the target one
165
+
166
+//// The minimal temperature defines the temperature below which the heater will not be enabled
167
+#define HEATER_0_MINTEMP 5
168
+//#define HEATER_1_MINTEMP 5
169
+//#define BED_MINTEMP 5
170
+
171
+
172
+// When temperature exceeds max temp, your heater will be switched off.
173
+// This feature exists to protect your hotend from overheating accidentally, but *NOT* from thermistor short/failure!
174
+// You should use MINTEMP for thermistor short/failure protection.
175
+#define HEATER_0_MAXTEMP 275
176
+//#define_HEATER_1_MAXTEMP 275
177
+//#define BED_MAXTEMP 150
178
+
179
+
180
+
181
+
182
+
183
+
184
+
185
+#define PIDTEMP
186
+#ifdef PIDTEMP
187
+  /// PID settings:
188
+  // Uncomment the following line to enable PID support.
189
+  //#define SMOOTHING
190
+  //#define SMOOTHFACTOR 5.0
191
+  //float current_raw_average=0;
192
+    #define K1 0.95 //smoothing of the PID
193
+  //#define PID_DEBUG // Sends debug data to the serial port. 
194
+  //#define PID_OPENLOOP 1 // Puts PID in open loop. M104 sets the output power in %
195
+  #define PID_MAX 255 // limits current to nozzle
196
+  #define PID_INTEGRAL_DRIVE_MAX 255
197
+  #define PID_dT 0.1
198
+ //machine with red silicon: 1950:45 second ; with fan fully blowin 3000:47
199
+
200
+  #define PID_CRITIAL_GAIN 3000
201
+  #define PID_SWING_AT_CRITIAL 45 //seconds
202
+  #define PIDIADD 5
203
+  /*
204
+  //PID according to Ziegler-Nichols method
205
+  float Kp = 0.6*PID_CRITIAL_GAIN; 
206
+  float Ki =PIDIADD+2*Kp/PID_SWING_AT_CRITIAL*PID_dT;  
207
+  float Kd = Kp*PID_SWING_AT_CRITIAL/8./PID_dT;  
208
+  */
209
+  //PI according to Ziegler-Nichols method
210
+  #define  DEFAULT_Kp (PID_CRITIAL_GAIN/2.2) 
211
+  #define  DEFAULT_Ki (1.2*Kp/PID_SWING_AT_CRITIAL*PID_dT)
212
+  #define  DEFAULT_Kd (0)
213
+  
214
+  #define PID_ADD_EXTRUSION_RATE  
215
+  #ifdef PID_ADD_EXTRUSION_RATE
216
+    #define  DEFAULT_Kc (5) //heatingpower=Kc*(e_speed)
217
+  #endif
218
+#endif // PIDTEMP
219
+
220
+// extruder advance constant (s2/mm3)
221
+//
222
+// advance (steps) = STEPS_PER_CUBIC_MM_E * EXTUDER_ADVANCE_K * cubic mm per second ^ 2
223
+//
224
+// hooke's law says:		force = k * distance
225
+// bernoulli's priniciple says:	v ^ 2 / 2 + g . h + pressure / density = constant
226
+// so: v ^ 2 is proportional to number of steps we advance the extruder
227
+//#define ADVANCE
228
+
229
+#ifdef ADVANCE
230
+#define EXTRUDER_ADVANCE_K .3
231
+
232
+#define D_FILAMENT 1.7
233
+#define STEPS_MM_E 65
234
+#define EXTRUTION_AREA (0.25 * D_FILAMENT * D_FILAMENT * 3.14159)
235
+#define STEPS_PER_CUBIC_MM_E (axis_steps_per_unit[E_AXIS]/ EXTRUTION_AREA)
236
+
237
+#endif // ADVANCE
238
+
239
+// THE BLOCK_BUFFER_SIZE NEEDS TO BE A POWER OF 2, e.g. 8,16,32 
240
+#if defined SDSUPPORT
241
+// The number of linear motions that can be in the plan at any give time.  
242
+  #define BLOCK_BUFFER_SIZE 16   // SD,LCD,Buttons take more memory, block buffer needs to be smaller
243
+#else
244
+  #define BLOCK_BUFFER_SIZE 16 // maximize block buffer
245
+#endif
246
+
247
+
248
+#endif

+ 1371
- 1234
Marlin/Marlin.pde
File diff suppressed because it is too large
View File


+ 133
- 0
Marlin/motion_control.cpp View File

@@ -0,0 +1,133 @@
1
+/*
2
+  motion_control.c - high level interface for issuing motion commands
3
+  Part of Grbl
4
+
5
+  Copyright (c) 2009-2011 Simen Svale Skogsrud
6
+  Copyright (c) 2011 Sungeun K. Jeon
7
+  
8
+  Grbl is free software: you can redistribute it and/or modify
9
+  it under the terms of the GNU General Public License as published by
10
+  the Free Software Foundation, either version 3 of the License, or
11
+  (at your option) any later version.
12
+
13
+  Grbl is distributed in the hope that it will be useful,
14
+  but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
+  GNU General Public License for more details.
17
+
18
+  You should have received a copy of the GNU General Public License
19
+  along with Grbl.  If not, see <http://www.gnu.org/licenses/>.
20
+*/
21
+
22
+//#include "motion_control.h"
23
+#include "Configuration.h"
24
+#include "Marlin.h"
25
+//#include <util/delay.h>
26
+//#include <math.h>
27
+//#include <stdlib.h>
28
+#include "stepper.h"
29
+#include "planner.h"
30
+
31
+// The arc is approximated by generating a huge number of tiny, linear segments. The length of each 
32
+// segment is configured in settings.mm_per_arc_segment.  
33
+void mc_arc(float *position, float *target, float *offset, uint8_t axis_0, uint8_t axis_1, 
34
+  uint8_t axis_linear, float feed_rate, float radius, uint8_t isclockwise)
35
+{      
36
+//   int acceleration_manager_was_enabled = plan_is_acceleration_manager_enabled();
37
+//   plan_set_acceleration_manager_enabled(false); // disable acceleration management for the duration of the arc
38
+  Serial.println("mc_arc");
39
+  float center_axis0 = position[axis_0] + offset[axis_0];
40
+  float center_axis1 = position[axis_1] + offset[axis_1];
41
+  float linear_travel = target[axis_linear] - position[axis_linear];
42
+  float r_axis0 = -offset[axis_0];  // Radius vector from center to current location
43
+  float r_axis1 = -offset[axis_1];
44
+  float rt_axis0 = target[axis_0] - center_axis0;
45
+  float rt_axis1 = target[axis_1] - center_axis1;
46
+  
47
+  // CCW angle between position and target from circle center. Only one atan2() trig computation required.
48
+  float angular_travel = atan2(r_axis0*rt_axis1-r_axis1*rt_axis0, r_axis0*rt_axis0+r_axis1*rt_axis1);
49
+  if (angular_travel < 0) { angular_travel += 2*M_PI; }
50
+  if (isclockwise) { angular_travel -= 2*M_PI; }
51
+  
52
+  float millimeters_of_travel = hypot(angular_travel*radius, fabs(linear_travel));
53
+  if (millimeters_of_travel == 0.0) { return; }
54
+  uint16_t segments = floor(millimeters_of_travel/MM_PER_ARC_SEGMENT);
55
+/*  
56
+  // Multiply inverse feed_rate to compensate for the fact that this movement is approximated
57
+  // by a number of discrete segments. The inverse feed_rate should be correct for the sum of 
58
+  // all segments.
59
+  if (invert_feed_rate) { feed_rate *= segments; }
60
+*/
61
+  float theta_per_segment = angular_travel/segments;
62
+  float linear_per_segment = linear_travel/segments;
63
+  
64
+  /* Vector rotation by transformation matrix: r is the original vector, r_T is the rotated vector,
65
+     and phi is the angle of rotation. Based on the solution approach by Jens Geisler.
66
+         r_T = [cos(phi) -sin(phi);
67
+                sin(phi)  cos(phi] * r ;
68
+     
69
+     For arc generation, the center of the circle is the axis of rotation and the radius vector is 
70
+     defined from the circle center to the initial position. Each line segment is formed by successive
71
+     vector rotations. This requires only two cos() and sin() computations to form the rotation
72
+     matrix for the duration of the entire arc. Error may accumulate from numerical round-off, since
73
+     all double numbers are single precision on the Arduino. (True double precision will not have
74
+     round off issues for CNC applications.) Single precision error can accumulate to be greater than
75
+     tool precision in some cases. Therefore, arc path correction is implemented. 
76
+
77
+     Small angle approximation may be used to reduce computation overhead further. This approximation
78
+     holds for everything, but very small circles and large mm_per_arc_segment values. In other words,
79
+     theta_per_segment would need to be greater than 0.1 rad and N_ARC_CORRECTION would need to be large
80
+     to cause an appreciable drift error. N_ARC_CORRECTION~=25 is more than small enough to correct for 
81
+     numerical drift error. N_ARC_CORRECTION may be on the order a hundred(s) before error becomes an
82
+     issue for CNC machines with the single precision Arduino calculations.
83
+     
84
+     This approximation also allows mc_arc to immediately insert a line segment into the planner 
85
+     without the initial overhead of computing cos() or sin(). By the time the arc needs to be applied
86
+     a correction, the planner should have caught up to the lag caused by the initial mc_arc overhead. 
87
+     This is important when there are successive arc motions. 
88
+  */
89
+  // Vector rotation matrix values
90
+  float cos_T = 1-0.5*theta_per_segment*theta_per_segment; // Small angle approximation
91
+  float sin_T = theta_per_segment;
92
+  
93
+  float arc_target[3];
94
+  float sin_Ti;
95
+  float cos_Ti;
96
+  float r_axisi;
97
+  uint16_t i;
98
+  int8_t count = 0;
99
+
100
+  // Initialize the linear axis
101
+  arc_target[axis_linear] = position[axis_linear];
102
+
103
+  for (i = 1; i<segments; i++) { // Increment (segments-1)
104
+    
105
+    if (count < N_ARC_CORRECTION) {
106
+      // Apply vector rotation matrix 
107
+      r_axisi = r_axis0*sin_T + r_axis1*cos_T;
108
+      r_axis0 = r_axis0*cos_T - r_axis1*sin_T;
109
+      r_axis1 = r_axisi;
110
+      count++;
111
+    } else {
112
+      // Arc correction to radius vector. Computed only every N_ARC_CORRECTION increments.
113
+      // Compute exact location by applying transformation matrix from initial radius vector(=-offset).
114
+      cos_Ti = cos(i*theta_per_segment);
115
+      sin_Ti = sin(i*theta_per_segment);
116
+      r_axis0 = -offset[axis_0]*cos_Ti + offset[axis_1]*sin_Ti;
117
+      r_axis1 = -offset[axis_0]*sin_Ti - offset[axis_1]*cos_Ti;
118
+      count = 0;
119
+    }
120
+
121
+    // Update arc_target location
122
+    arc_target[axis_0] = center_axis0 + r_axis0;
123
+    arc_target[axis_1] = center_axis1 + r_axis1;
124
+    arc_target[axis_linear] += linear_per_segment;
125
+    plan_buffer_line(arc_target[X_AXIS], arc_target[Y_AXIS], arc_target[Z_AXIS], target[E_AXIS], feed_rate);
126
+    
127
+  }
128
+  // Ensure last segment arrives at target location.
129
+  plan_buffer_line(target[X_AXIS], target[Y_AXIS], target[Z_AXIS], target[E_AXIS], feed_rate);
130
+
131
+//   plan_set_acceleration_manager_enabled(acceleration_manager_was_enabled);
132
+}
133
+

+ 32
- 0
Marlin/motion_control.h View File

@@ -0,0 +1,32 @@
1
+/*
2
+  motion_control.h - high level interface for issuing motion commands
3
+  Part of Grbl
4
+
5
+  Copyright (c) 2009-2011 Simen Svale Skogsrud
6
+  Copyright (c) 2011 Sungeun K. Jeon
7
+  
8
+  Grbl is free software: you can redistribute it and/or modify
9
+  it under the terms of the GNU General Public License as published by
10
+  the Free Software Foundation, either version 3 of the License, or
11
+  (at your option) any later version.
12
+
13
+  Grbl is distributed in the hope that it will be useful,
14
+  but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
+  GNU General Public License for more details.
17
+
18
+  You should have received a copy of the GNU General Public License
19
+  along with Grbl.  If not, see <http://www.gnu.org/licenses/>.
20
+*/
21
+
22
+#ifndef motion_control_h
23
+#define motion_control_h
24
+
25
+// Execute an arc in offset mode format. position == current xyz, target == target xyz, 
26
+// offset == offset from current xyz, axis_XXX defines circle plane in tool space, axis_linear is
27
+// the direction of helical travel, radius == circle radius, isclockwise boolean. Used
28
+// for vector transformation direction.
29
+void mc_arc(float *position, float *target, float *offset, unsigned char axis_0, unsigned char axis_1,
30
+  unsigned char axis_linear, float feed_rate, float radius, unsigned char isclockwise);
31
+  
32
+#endif

Loading…
Cancel
Save