|
@@ -1139,8 +1139,8 @@ inline void get_coordinates()
|
1139
|
1139
|
inline void get_arc_coordinates()
|
1140
|
1140
|
{
|
1141
|
1141
|
get_coordinates();
|
1142
|
|
- if(code_seen("I")) offset[0] = code_value();
|
1143
|
|
- if(code_seen("J")) offset[1] = code_value();
|
|
1142
|
+ if(code_seen('I')) offset[0] = code_value();
|
|
1143
|
+ if(code_seen('J')) offset[1] = code_value();
|
1144
|
1144
|
}
|
1145
|
1145
|
|
1146
|
1146
|
void prepare_move()
|
|
@@ -1152,119 +1152,16 @@ void prepare_move()
|
1152
|
1152
|
}
|
1153
|
1153
|
|
1154
|
1154
|
void prepare_arc_move(char isclockwise) {
|
1155
|
|
-#if 0
|
1156
|
|
- if (radius_mode) {
|
1157
|
|
- /*
|
1158
|
|
- We need to calculate the center of the circle that has the designated radius and passes
|
1159
|
|
- through both the current position and the target position. This method calculates the following
|
1160
|
|
- set of equations where [x,y] is the vector from current to target position, d == magnitude of
|
1161
|
|
- that vector, h == hypotenuse of the triangle formed by the radius of the circle, the distance to
|
1162
|
|
- the center of the travel vector. A vector perpendicular to the travel vector [-y,x] is scaled to the
|
1163
|
|
- length of h [-y/d*h, x/d*h] and added to the center of the travel vector [x/2,y/2] to form the new point
|
1164
|
|
- [i,j] at [x/2-y/d*h, y/2+x/d*h] which will be the center of our arc.
|
1165
|
|
-
|
1166
|
|
- d^2 == x^2 + y^2
|
1167
|
|
- h^2 == r^2 - (d/2)^2
|
1168
|
|
- i == x/2 - y/d*h
|
1169
|
|
- j == y/2 + x/d*h
|
1170
|
|
-
|
1171
|
|
- O <- [i,j]
|
1172
|
|
- - |
|
1173
|
|
- r - |
|
1174
|
|
- - |
|
1175
|
|
- - | h
|
1176
|
|
- - |
|
1177
|
|
- [0,0] -> C -----------------+--------------- T <- [x,y]
|
1178
|
|
- | <------ d/2 ---->|
|
1179
|
|
-
|
1180
|
|
- C - Current position
|
1181
|
|
- T - Target position
|
1182
|
|
- O - center of circle that pass through both C and T
|
1183
|
|
- d - distance from C to T
|
1184
|
|
- r - designated radius
|
1185
|
|
- h - distance from center of CT to O
|
1186
|
|
-
|
1187
|
|
- Expanding the equations:
|
1188
|
|
-
|
1189
|
|
- d -> sqrt(x^2 + y^2)
|
1190
|
|
- h -> sqrt(4 * r^2 - x^2 - y^2)/2
|
1191
|
|
- i -> (x - (y * sqrt(4 * r^2 - x^2 - y^2)) / sqrt(x^2 + y^2)) / 2
|
1192
|
|
- j -> (y + (x * sqrt(4 * r^2 - x^2 - y^2)) / sqrt(x^2 + y^2)) / 2
|
1193
|
|
-
|
1194
|
|
- Which can be written:
|
1195
|
|
-
|
1196
|
|
- i -> (x - (y * sqrt(4 * r^2 - x^2 - y^2))/sqrt(x^2 + y^2))/2
|
1197
|
|
- j -> (y + (x * sqrt(4 * r^2 - x^2 - y^2))/sqrt(x^2 + y^2))/2
|
1198
|
|
-
|
1199
|
|
- Which we for size and speed reasons optimize to:
|
1200
|
|
-
|
1201
|
|
- h_x2_div_d = sqrt(4 * r^2 - x^2 - y^2)/sqrt(x^2 + y^2)
|
1202
|
|
- i = (x - (y * h_x2_div_d))/2
|
1203
|
|
- j = (y + (x * h_x2_div_d))/2
|
1204
|
|
-
|
1205
|
|
- */
|
1206
|
|
-
|
1207
|
|
- // Calculate the change in position along each selected axis
|
1208
|
|
- double x = target[gc.plane_axis_0]-gc.position[gc.plane_axis_0];
|
1209
|
|
- double y = target[gc.plane_axis_1]-gc.position[gc.plane_axis_1];
|
1210
|
|
-
|
1211
|
|
- clear_vector(offset);
|
1212
|
|
- double h_x2_div_d = -sqrt(4 * r*r - x*x - y*y)/hypot(x,y); // == -(h * 2 / d)
|
1213
|
|
- // If r is smaller than d, the arc is now traversing the complex plane beyond the reach of any
|
1214
|
|
- // real CNC, and thus - for practical reasons - we will terminate promptly:
|
1215
|
|
- if(isnan(h_x2_div_d)) { FAIL(STATUS_FLOATING_POINT_ERROR); return(gc.status_code); }
|
1216
|
|
- // Invert the sign of h_x2_div_d if the circle is counter clockwise (see sketch below)
|
1217
|
|
- if (gc.motion_mode == MOTION_MODE_CCW_ARC) { h_x2_div_d = -h_x2_div_d; }
|
1218
|
|
-
|
1219
|
|
- /* The counter clockwise circle lies to the left of the target direction. When offset is positive,
|
1220
|
|
- the left hand circle will be generated - when it is negative the right hand circle is generated.
|
1221
|
|
-
|
1222
|
|
-
|
1223
|
|
- T <-- Target position
|
1224
|
|
-
|
1225
|
|
- ^
|
1226
|
|
- Clockwise circles with this center | Clockwise circles with this center will have
|
1227
|
|
- will have > 180 deg of angular travel | < 180 deg of angular travel, which is a good thing!
|
1228
|
|
- \ | /
|
1229
|
|
- center of arc when h_x2_div_d is positive -> x <----- | -----> x <- center of arc when h_x2_div_d is negative
|
1230
|
|
- |
|
1231
|
|
- |
|
1232
|
|
-
|
1233
|
|
- C <-- Current position */
|
1234
|
|
-
|
1235
|
|
-
|
1236
|
|
- // Negative R is g-code-alese for "I want a circle with more than 180 degrees of travel" (go figure!),
|
1237
|
|
- // even though it is advised against ever generating such circles in a single line of g-code. By
|
1238
|
|
- // inverting the sign of h_x2_div_d the center of the circles is placed on the opposite side of the line of
|
1239
|
|
- // travel and thus we get the unadvisably long arcs as prescribed.
|
1240
|
|
- if (r < 0) {
|
1241
|
|
- h_x2_div_d = -h_x2_div_d;
|
1242
|
|
- r = -r; // Finished with r. Set to positive for mc_arc
|
1243
|
|
- }
|
1244
|
|
- // Complete the operation by calculating the actual center of the arc
|
1245
|
|
- offset[gc.plane_axis_0] = 0.5*(x-(y*h_x2_div_d));
|
1246
|
|
- offset[gc.plane_axis_1] = 0.5*(y+(x*h_x2_div_d));
|
1247
|
|
-
|
1248
|
|
- } else { // Offset mode specific computations
|
1249
|
|
-#endif
|
1250
|
|
- float r = hypot(offset[X_AXIS], offset[Y_AXIS]); // Compute arc radius for mc_arc
|
1251
|
|
-
|
1252
|
|
-// }
|
1253
|
|
-
|
1254
|
|
- // Set clockwise/counter-clockwise sign for mc_arc computations
|
1255
|
|
-// uint8_t isclockwise = false;
|
1256
|
|
-// if (gc.motion_mode == MOTION_MODE_CW_ARC) { isclockwise = true; }
|
|
1155
|
+ float r = hypot(offset[X_AXIS], offset[Y_AXIS]); // Compute arc radius for mc_arc
|
1257
|
1156
|
|
1258
|
1157
|
// Trace the arc
|
1259
|
1158
|
mc_arc(current_position, destination, offset, X_AXIS, Y_AXIS, Z_AXIS, feedrate*feedmultiply/60.0/100.0, r, isclockwise);
|
1260
|
|
-
|
1261
|
|
-// }
|
1262
|
1159
|
|
1263
|
1160
|
// As far as the parser is concerned, the position is now == target. In reality the
|
1264
|
1161
|
// motion control system might still be processing the action and the real tool position
|
1265
|
1162
|
// in any intermediate location.
|
1266
|
|
- for(int ii=0; ii < NUM_AXIS; ii++) {
|
1267
|
|
- current_position[ii] = destination[ii];
|
|
1163
|
+ for(int i=0; i < NUM_AXIS; i++) {
|
|
1164
|
+ current_position[i] = destination[i];
|
1268
|
1165
|
}
|
1269
|
1166
|
}
|
1270
|
1167
|
|