Use arrays for delta tower parameters

This commit is contained in:
Scott Lahteine 2017-03-07 17:42:04 -06:00
parent 47242a40bb
commit 58b3e98878
3 changed files with 73 additions and 99 deletions

View file

@ -332,12 +332,8 @@ float code_value_temp_diff();
delta_radius, delta_radius,
delta_diagonal_rod, delta_diagonal_rod,
delta_segments_per_second, delta_segments_per_second,
delta_diagonal_rod_trim_tower_1, delta_diagonal_rod_trim[ABC],
delta_diagonal_rod_trim_tower_2, delta_tower_angle_trim[ABC],
delta_diagonal_rod_trim_tower_3,
delta_tower_angle_trim_1,
delta_tower_angle_trim_2,
delta_tower_angle_trim_3,
delta_clip_start_height; delta_clip_start_height;
void recalc_delta_settings(float radius, float diagonal_rod); void recalc_delta_settings(float radius, float diagonal_rod);
#elif IS_SCARA #elif IS_SCARA

View file

@ -559,25 +559,15 @@ static uint8_t target_extruder;
float delta[ABC], float delta[ABC],
endstop_adj[ABC] = { 0 }; endstop_adj[ABC] = { 0 };
// these are the default values, can be overriden with M665 // These values are loaded or reset at boot time when setup() calls
float delta_radius = DELTA_RADIUS, // Config_RetrieveSettings(), which calls recalc_delta_settings().
delta_tower_angle_trim_1 = DELTA_TOWER_ANGLE_TRIM_1, float delta_radius,
delta_tower_angle_trim_2 = DELTA_TOWER_ANGLE_TRIM_2, delta_tower_angle_trim[ABC],
delta_tower_angle_trim_3 = DELTA_TOWER_ANGLE_TRIM_3, delta_tower[ABC][2],
delta_tower1_x = -sin(RADIANS(60 - delta_tower_angle_trim_1)) * (delta_radius + DELTA_RADIUS_TRIM_TOWER_1), // front left tower delta_diagonal_rod,
delta_tower1_y = -cos(RADIANS(60 - delta_tower_angle_trim_1)) * (delta_radius + DELTA_RADIUS_TRIM_TOWER_1), delta_diagonal_rod_trim[ABC],
delta_tower2_x = sin(RADIANS(60 + delta_tower_angle_trim_2)) * (delta_radius + DELTA_RADIUS_TRIM_TOWER_2), // front right tower delta_diagonal_rod_2_tower[ABC],
delta_tower2_y = -cos(RADIANS(60 + delta_tower_angle_trim_2)) * (delta_radius + DELTA_RADIUS_TRIM_TOWER_2), delta_segments_per_second,
delta_tower3_x = -sin(RADIANS( delta_tower_angle_trim_3)), // back middle tower
delta_tower3_y = cos(RADIANS( delta_tower_angle_trim_3)) * (delta_radius + DELTA_RADIUS_TRIM_TOWER_3),
delta_diagonal_rod = DELTA_DIAGONAL_ROD,
delta_diagonal_rod_trim_tower_1 = DELTA_DIAGONAL_ROD_TRIM_TOWER_1,
delta_diagonal_rod_trim_tower_2 = DELTA_DIAGONAL_ROD_TRIM_TOWER_2,
delta_diagonal_rod_trim_tower_3 = DELTA_DIAGONAL_ROD_TRIM_TOWER_3,
delta_diagonal_rod_2_tower_1 = sq(delta_diagonal_rod + delta_diagonal_rod_trim_tower_1),
delta_diagonal_rod_2_tower_2 = sq(delta_diagonal_rod + delta_diagonal_rod_trim_tower_2),
delta_diagonal_rod_2_tower_3 = sq(delta_diagonal_rod + delta_diagonal_rod_trim_tower_3),
delta_segments_per_second = DELTA_SEGMENTS_PER_SECOND,
delta_clip_start_height = Z_MAX_POS; delta_clip_start_height = Z_MAX_POS;
float delta_safe_distance_from_top(); float delta_safe_distance_from_top();
@ -6334,12 +6324,12 @@ inline void gcode_M205() {
if (code_seen('L')) delta_diagonal_rod = code_value_linear_units(); if (code_seen('L')) delta_diagonal_rod = code_value_linear_units();
if (code_seen('R')) delta_radius = code_value_linear_units(); if (code_seen('R')) delta_radius = code_value_linear_units();
if (code_seen('S')) delta_segments_per_second = code_value_float(); if (code_seen('S')) delta_segments_per_second = code_value_float();
if (code_seen('A')) delta_diagonal_rod_trim_tower_1 = code_value_linear_units(); if (code_seen('A')) delta_diagonal_rod_trim[A_AXIS] = code_value_linear_units();
if (code_seen('B')) delta_diagonal_rod_trim_tower_2 = code_value_linear_units(); if (code_seen('B')) delta_diagonal_rod_trim[B_AXIS] = code_value_linear_units();
if (code_seen('C')) delta_diagonal_rod_trim_tower_3 = code_value_linear_units(); if (code_seen('C')) delta_diagonal_rod_trim[C_AXIS] = code_value_linear_units();
if (code_seen('I')) delta_tower_angle_trim_1 = code_value_linear_units(); if (code_seen('I')) delta_tower_angle_trim[A_AXIS] = code_value_linear_units();
if (code_seen('J')) delta_tower_angle_trim_2 = code_value_linear_units(); if (code_seen('J')) delta_tower_angle_trim[B_AXIS] = code_value_linear_units();
if (code_seen('K')) delta_tower_angle_trim_3 = code_value_linear_units(); if (code_seen('K')) delta_tower_angle_trim[C_AXIS] = code_value_linear_units();
recalc_delta_settings(delta_radius, delta_diagonal_rod); recalc_delta_settings(delta_radius, delta_diagonal_rod);
} }
/** /**
@ -9143,15 +9133,15 @@ void ok_to_send() {
* settings have been changed (e.g., by M665). * settings have been changed (e.g., by M665).
*/ */
void recalc_delta_settings(float radius, float diagonal_rod) { void recalc_delta_settings(float radius, float diagonal_rod) {
delta_tower1_x = -sin(RADIANS(60 - delta_tower_angle_trim_1)) * (delta_radius + DELTA_RADIUS_TRIM_TOWER_1), // front left tower delta_tower[A_AXIS][X_AXIS] = -sin(RADIANS(60 - delta_tower_angle_trim[A_AXIS])) * (delta_radius + DELTA_RADIUS_TRIM_TOWER_1), // front left tower
delta_tower1_y = -cos(RADIANS(60 - delta_tower_angle_trim_1)) * (delta_radius + DELTA_RADIUS_TRIM_TOWER_1), delta_tower[A_AXIS][Y_AXIS] = -cos(RADIANS(60 - delta_tower_angle_trim[A_AXIS])) * (delta_radius + DELTA_RADIUS_TRIM_TOWER_1),
delta_tower2_x = sin(RADIANS(60 + delta_tower_angle_trim_2)) * (delta_radius + DELTA_RADIUS_TRIM_TOWER_2), // front right tower delta_tower[B_AXIS][X_AXIS] = sin(RADIANS(60 + delta_tower_angle_trim[B_AXIS])) * (delta_radius + DELTA_RADIUS_TRIM_TOWER_2), // front right tower
delta_tower2_y = -cos(RADIANS(60 + delta_tower_angle_trim_2)) * (delta_radius + DELTA_RADIUS_TRIM_TOWER_2), delta_tower[B_AXIS][Y_AXIS] = -cos(RADIANS(60 + delta_tower_angle_trim[B_AXIS])) * (delta_radius + DELTA_RADIUS_TRIM_TOWER_2),
delta_tower3_x = -sin(RADIANS( delta_tower_angle_trim_3)), // back middle tower delta_tower[C_AXIS][X_AXIS] = -sin(RADIANS( delta_tower_angle_trim[C_AXIS])) * (delta_radius + DELTA_RADIUS_TRIM_TOWER_3), // back middle tower
delta_tower3_y = cos(RADIANS( delta_tower_angle_trim_3)) * (delta_radius + DELTA_RADIUS_TRIM_TOWER_3), delta_tower[C_AXIS][Y_AXIS] = cos(RADIANS( delta_tower_angle_trim[C_AXIS])) * (delta_radius + DELTA_RADIUS_TRIM_TOWER_3),
delta_diagonal_rod_2_tower_1 = sq(diagonal_rod + delta_diagonal_rod_trim_tower_1); delta_diagonal_rod_2_tower[A_AXIS] = sq(diagonal_rod + delta_diagonal_rod_trim[A_AXIS]);
delta_diagonal_rod_2_tower_2 = sq(diagonal_rod + delta_diagonal_rod_trim_tower_2); delta_diagonal_rod_2_tower[B_AXIS] = sq(diagonal_rod + delta_diagonal_rod_trim[B_AXIS]);
delta_diagonal_rod_2_tower_3 = sq(diagonal_rod + delta_diagonal_rod_trim_tower_3); delta_diagonal_rod_2_tower[C_AXIS] = sq(diagonal_rod + delta_diagonal_rod_trim[C_AXIS]);
} }
#if ENABLED(DELTA_FAST_SQRT) #if ENABLED(DELTA_FAST_SQRT)
@ -9202,16 +9192,16 @@ void ok_to_send() {
// Macro to obtain the Z position of an individual tower // Macro to obtain the Z position of an individual tower
#define DELTA_Z(T) raw[Z_AXIS] + _SQRT( \ #define DELTA_Z(T) raw[Z_AXIS] + _SQRT( \
delta_diagonal_rod_2_tower_##T - HYPOT2( \ delta_diagonal_rod_2_tower[T] - HYPOT2( \
delta_tower##T##_x - raw[X_AXIS], \ delta_tower[T][X_AXIS] - raw[X_AXIS], \
delta_tower##T##_y - raw[Y_AXIS] \ delta_tower[T][Y_AXIS] - raw[Y_AXIS] \
) \ ) \
) )
#define DELTA_RAW_IK() do { \ #define DELTA_RAW_IK() do { \
delta[A_AXIS] = DELTA_Z(1); \ delta[A_AXIS] = DELTA_Z(A_AXIS); \
delta[B_AXIS] = DELTA_Z(2); \ delta[B_AXIS] = DELTA_Z(B_AXIS); \
delta[C_AXIS] = DELTA_Z(3); \ delta[C_AXIS] = DELTA_Z(C_AXIS); \
} while(0) } while(0)
#define DELTA_LOGICAL_IK() do { \ #define DELTA_LOGICAL_IK() do { \
@ -9281,7 +9271,7 @@ void ok_to_send() {
*/ */
void forward_kinematics_DELTA(float z1, float z2, float z3) { void forward_kinematics_DELTA(float z1, float z2, float z3) {
// Create a vector in old coordinates along x axis of new coordinate // Create a vector in old coordinates along x axis of new coordinate
float p12[3] = { delta_tower2_x - delta_tower1_x, delta_tower2_y - delta_tower1_y, z2 - z1 }; float p12[3] = { delta_tower[B_AXIS][X_AXIS] - delta_tower[A_AXIS][X_AXIS], delta_tower[B_AXIS][Y_AXIS] - delta_tower[A_AXIS][Y_AXIS], z2 - z1 };
// Get the Magnitude of vector. // Get the Magnitude of vector.
float d = sqrt( sq(p12[0]) + sq(p12[1]) + sq(p12[2]) ); float d = sqrt( sq(p12[0]) + sq(p12[1]) + sq(p12[2]) );
@ -9290,7 +9280,7 @@ void ok_to_send() {
float ex[3] = { p12[0] / d, p12[1] / d, p12[2] / d }; float ex[3] = { p12[0] / d, p12[1] / d, p12[2] / d };
// Get the vector from the origin of the new system to the third point. // Get the vector from the origin of the new system to the third point.
float p13[3] = { delta_tower3_x - delta_tower1_x, delta_tower3_y - delta_tower1_y, z3 - z1 }; float p13[3] = { delta_tower[C_AXIS][X_AXIS] - delta_tower[A_AXIS][X_AXIS], delta_tower[C_AXIS][Y_AXIS] - delta_tower[A_AXIS][Y_AXIS], z3 - z1 };
// Use the dot product to find the component of this vector on the X axis. // Use the dot product to find the component of this vector on the X axis.
float i = ex[0] * p13[0] + ex[1] * p13[1] + ex[2] * p13[2]; float i = ex[0] * p13[0] + ex[1] * p13[1] + ex[2] * p13[2];
@ -9318,15 +9308,15 @@ void ok_to_send() {
// We now have the d, i and j values defined in Wikipedia. // We now have the d, i and j values defined in Wikipedia.
// Plug them into the equations defined in Wikipedia for Xnew, Ynew and Znew // Plug them into the equations defined in Wikipedia for Xnew, Ynew and Znew
float Xnew = (delta_diagonal_rod_2_tower_1 - delta_diagonal_rod_2_tower_2 + sq(d)) / (d * 2), float Xnew = (delta_diagonal_rod_2_tower[A_AXIS] - delta_diagonal_rod_2_tower[B_AXIS] + sq(d)) / (d * 2),
Ynew = ((delta_diagonal_rod_2_tower_1 - delta_diagonal_rod_2_tower_3 + HYPOT2(i, j)) / 2 - i * Xnew) / j, Ynew = ((delta_diagonal_rod_2_tower[A_AXIS] - delta_diagonal_rod_2_tower[C_AXIS] + HYPOT2(i, j)) / 2 - i * Xnew) / j,
Znew = sqrt(delta_diagonal_rod_2_tower_1 - HYPOT2(Xnew, Ynew)); Znew = sqrt(delta_diagonal_rod_2_tower[A_AXIS] - HYPOT2(Xnew, Ynew));
// Start from the origin of the old coordinates and add vectors in the // Start from the origin of the old coordinates and add vectors in the
// old coords that represent the Xnew, Ynew and Znew to find the point // old coords that represent the Xnew, Ynew and Znew to find the point
// in the old system. // in the old system.
cartes[X_AXIS] = delta_tower1_x + ex[0] * Xnew + ey[0] * Ynew - ez[0] * Znew; cartes[X_AXIS] = delta_tower[A_AXIS][X_AXIS] + ex[0] * Xnew + ey[0] * Ynew - ez[0] * Znew;
cartes[Y_AXIS] = delta_tower1_y + ex[1] * Xnew + ey[1] * Ynew - ez[1] * Znew; cartes[Y_AXIS] = delta_tower[A_AXIS][Y_AXIS] + ex[1] * Xnew + ey[1] * Ynew - ez[1] * Znew;
cartes[Z_AXIS] = z1 + ex[2] * Xnew + ey[2] * Ynew - ez[2] * Znew; cartes[Z_AXIS] = z1 + ex[2] * Xnew + ey[2] * Ynew - ez[2] * Znew;
} }

View file

@ -89,12 +89,12 @@
* 360 M665 R delta_radius (float) * 360 M665 R delta_radius (float)
* 364 M665 L delta_diagonal_rod (float) * 364 M665 L delta_diagonal_rod (float)
* 368 M665 S delta_segments_per_second (float) * 368 M665 S delta_segments_per_second (float)
* 372 M665 A delta_diagonal_rod_trim_tower_1 (float) * 372 M665 A delta_diagonal_rod_trim[A] (float)
* 376 M665 B delta_diagonal_rod_trim_tower_2 (float) * 376 M665 B delta_diagonal_rod_trim[B] (float)
* 380 M665 C delta_diagonal_rod_trim_tower_3 (float) * 380 M665 C delta_diagonal_rod_trim[C] (float)
* 384 M665 I delta_tower_angle_trim_1 (float) * 384 M665 I delta_tower_angle_trim[A] (float)
* 388 M665 J delta_tower_angle_trim_2 (float) * 388 M665 J delta_tower_angle_trim[B] (float)
* 392 M665 K delta_tower_angle_trim_3 (float) * 392 M665 K delta_tower_angle_trim[C] (float)
* *
* Z_DUAL_ENDSTOPS (if not deltabot): 48 bytes * Z_DUAL_ENDSTOPS (if not deltabot): 48 bytes
* 348 M666 Z z_endstop_adj (float) * 348 M666 Z z_endstop_adj (float)
@ -357,12 +357,8 @@ void Config_Postprocess() {
EEPROM_WRITE(delta_radius); // 1 float EEPROM_WRITE(delta_radius); // 1 float
EEPROM_WRITE(delta_diagonal_rod); // 1 float EEPROM_WRITE(delta_diagonal_rod); // 1 float
EEPROM_WRITE(delta_segments_per_second); // 1 float EEPROM_WRITE(delta_segments_per_second); // 1 float
EEPROM_WRITE(delta_diagonal_rod_trim_tower_1); // 1 float EEPROM_WRITE(delta_diagonal_rod_trim); // 3 floats
EEPROM_WRITE(delta_diagonal_rod_trim_tower_2); // 1 float EEPROM_WRITE(delta_tower_angle_trim); // 3 floats
EEPROM_WRITE(delta_diagonal_rod_trim_tower_3); // 1 float
EEPROM_WRITE(delta_tower_angle_trim_1); // 1 float
EEPROM_WRITE(delta_tower_angle_trim_2); // 1 float
EEPROM_WRITE(delta_tower_angle_trim_3); // 1 float
#elif ENABLED(Z_DUAL_ENDSTOPS) #elif ENABLED(Z_DUAL_ENDSTOPS)
EEPROM_WRITE(z_endstop_adj); // 1 float EEPROM_WRITE(z_endstop_adj); // 1 float
dummy = 0.0f; dummy = 0.0f;
@ -685,12 +681,8 @@ void Config_Postprocess() {
EEPROM_READ(delta_radius); // 1 float EEPROM_READ(delta_radius); // 1 float
EEPROM_READ(delta_diagonal_rod); // 1 float EEPROM_READ(delta_diagonal_rod); // 1 float
EEPROM_READ(delta_segments_per_second); // 1 float EEPROM_READ(delta_segments_per_second); // 1 float
EEPROM_READ(delta_diagonal_rod_trim_tower_1); // 1 float EEPROM_READ(delta_diagonal_rod_trim); // 3 floats
EEPROM_READ(delta_diagonal_rod_trim_tower_2); // 1 float EEPROM_READ(delta_tower_angle_trim); // 3 floats
EEPROM_READ(delta_diagonal_rod_trim_tower_3); // 1 float
EEPROM_READ(delta_tower_angle_trim_1); // 1 float
EEPROM_READ(delta_tower_angle_trim_2); // 1 float
EEPROM_READ(delta_tower_angle_trim_3); // 1 float
#elif ENABLED(Z_DUAL_ENDSTOPS) #elif ENABLED(Z_DUAL_ENDSTOPS)
EEPROM_READ(z_endstop_adj); EEPROM_READ(z_endstop_adj);
dummy = 0.0f; dummy = 0.0f;
@ -909,19 +901,15 @@ void Config_ResetDefault() {
#endif #endif
#if ENABLED(DELTA) #if ENABLED(DELTA)
const float adj[ABC] = DELTA_ENDSTOP_ADJ; const float adj[ABC] = DELTA_ENDSTOP_ADJ,
endstop_adj[A_AXIS] = adj[A_AXIS]; drt[ABC] = { DELTA_DIAGONAL_ROD_TRIM_TOWER_1, DELTA_DIAGONAL_ROD_TRIM_TOWER_2, DELTA_DIAGONAL_ROD_TRIM_TOWER_3 },
endstop_adj[B_AXIS] = adj[B_AXIS]; dta[ABC] = { DELTA_TOWER_ANGLE_TRIM_1, DELTA_TOWER_ANGLE_TRIM_2, DELTA_TOWER_ANGLE_TRIM_3 };
endstop_adj[C_AXIS] = adj[C_AXIS]; COPY(endstop_adj, adj);
delta_radius = DELTA_RADIUS; delta_radius = DELTA_RADIUS;
delta_diagonal_rod = DELTA_DIAGONAL_ROD; delta_diagonal_rod = DELTA_DIAGONAL_ROD;
delta_segments_per_second = DELTA_SEGMENTS_PER_SECOND; delta_segments_per_second = DELTA_SEGMENTS_PER_SECOND;
delta_diagonal_rod_trim_tower_1 = DELTA_DIAGONAL_ROD_TRIM_TOWER_1; COPY(delta_diagonal_rod_trim, drt);
delta_diagonal_rod_trim_tower_2 = DELTA_DIAGONAL_ROD_TRIM_TOWER_2; COPY(delta_tower_angle_trim, dta);
delta_diagonal_rod_trim_tower_3 = DELTA_DIAGONAL_ROD_TRIM_TOWER_3;
delta_tower_angle_trim_1 = DELTA_TOWER_ANGLE_TRIM_1;
delta_tower_angle_trim_2 = DELTA_TOWER_ANGLE_TRIM_2;
delta_tower_angle_trim_3 = DELTA_TOWER_ANGLE_TRIM_3;
#elif ENABLED(Z_DUAL_ENDSTOPS) #elif ENABLED(Z_DUAL_ENDSTOPS)
z_endstop_adj = 0; z_endstop_adj = 0;
#endif #endif
@ -1198,12 +1186,12 @@ void Config_ResetDefault() {
SERIAL_ECHOPAIR(" M665 L", delta_diagonal_rod); SERIAL_ECHOPAIR(" M665 L", delta_diagonal_rod);
SERIAL_ECHOPAIR(" R", delta_radius); SERIAL_ECHOPAIR(" R", delta_radius);
SERIAL_ECHOPAIR(" S", delta_segments_per_second); SERIAL_ECHOPAIR(" S", delta_segments_per_second);
SERIAL_ECHOPAIR(" A", delta_diagonal_rod_trim_tower_1); SERIAL_ECHOPAIR(" A", delta_diagonal_rod_trim[A_AXIS]);
SERIAL_ECHOPAIR(" B", delta_diagonal_rod_trim_tower_2); SERIAL_ECHOPAIR(" B", delta_diagonal_rod_trim[B_AXIS]);
SERIAL_ECHOPAIR(" C", delta_diagonal_rod_trim_tower_3); SERIAL_ECHOPAIR(" C", delta_diagonal_rod_trim[C_AXIS]);
SERIAL_ECHOPAIR(" I", delta_tower_angle_trim_1); SERIAL_ECHOPAIR(" I", delta_tower_angle_trim[A_AXIS]);
SERIAL_ECHOPAIR(" J", delta_tower_angle_trim_2); SERIAL_ECHOPAIR(" J", delta_tower_angle_trim[B_AXIS]);
SERIAL_ECHOPAIR(" K", delta_tower_angle_trim_3); SERIAL_ECHOPAIR(" K", delta_tower_angle_trim[C_AXIS]);
SERIAL_EOL; SERIAL_EOL;
#elif ENABLED(Z_DUAL_ENDSTOPS) #elif ENABLED(Z_DUAL_ENDSTOPS)
CONFIG_ECHO_START; CONFIG_ECHO_START;