Add custom types for position (#15204)
This commit is contained in:
@@ -50,17 +50,16 @@
|
||||
#include "../core/debug_out.h"
|
||||
|
||||
// Initialized by settings.load()
|
||||
float delta_height,
|
||||
delta_endstop_adj[ABC] = { 0 },
|
||||
delta_radius,
|
||||
float delta_height;
|
||||
abc_float_t delta_endstop_adj{0};
|
||||
float delta_radius,
|
||||
delta_diagonal_rod,
|
||||
delta_segments_per_second,
|
||||
delta_calibration_radius,
|
||||
delta_tower_angle_trim[ABC];
|
||||
|
||||
float delta_tower[ABC][2],
|
||||
delta_diagonal_rod_2_tower[ABC],
|
||||
delta_clip_start_height = Z_MAX_POS;
|
||||
delta_calibration_radius;
|
||||
abc_float_t delta_tower_angle_trim;
|
||||
xy_float_t delta_tower[ABC];
|
||||
abc_float_t delta_diagonal_rod_2_tower;
|
||||
float delta_clip_start_height = Z_MAX_POS;
|
||||
|
||||
float delta_safe_distance_from_top();
|
||||
|
||||
@@ -69,17 +68,17 @@ float delta_safe_distance_from_top();
|
||||
* settings have been changed (e.g., by M665).
|
||||
*/
|
||||
void recalc_delta_settings() {
|
||||
const float trt[ABC] = DELTA_RADIUS_TRIM_TOWER,
|
||||
drt[ABC] = DELTA_DIAGONAL_ROD_TRIM_TOWER;
|
||||
delta_tower[A_AXIS][X_AXIS] = cos(RADIANS(210 + delta_tower_angle_trim[A_AXIS])) * (delta_radius + trt[A_AXIS]); // front left tower
|
||||
delta_tower[A_AXIS][Y_AXIS] = sin(RADIANS(210 + delta_tower_angle_trim[A_AXIS])) * (delta_radius + trt[A_AXIS]);
|
||||
delta_tower[B_AXIS][X_AXIS] = cos(RADIANS(330 + delta_tower_angle_trim[B_AXIS])) * (delta_radius + trt[B_AXIS]); // front right tower
|
||||
delta_tower[B_AXIS][Y_AXIS] = sin(RADIANS(330 + delta_tower_angle_trim[B_AXIS])) * (delta_radius + trt[B_AXIS]);
|
||||
delta_tower[C_AXIS][X_AXIS] = cos(RADIANS( 90 + delta_tower_angle_trim[C_AXIS])) * (delta_radius + trt[C_AXIS]); // back middle tower
|
||||
delta_tower[C_AXIS][Y_AXIS] = sin(RADIANS( 90 + delta_tower_angle_trim[C_AXIS])) * (delta_radius + trt[C_AXIS]);
|
||||
delta_diagonal_rod_2_tower[A_AXIS] = sq(delta_diagonal_rod + drt[A_AXIS]);
|
||||
delta_diagonal_rod_2_tower[B_AXIS] = sq(delta_diagonal_rod + drt[B_AXIS]);
|
||||
delta_diagonal_rod_2_tower[C_AXIS] = sq(delta_diagonal_rod + drt[C_AXIS]);
|
||||
constexpr abc_float_t trt = DELTA_RADIUS_TRIM_TOWER,
|
||||
drt = DELTA_DIAGONAL_ROD_TRIM_TOWER;
|
||||
delta_tower[A_AXIS].set(cos(RADIANS(210 + delta_tower_angle_trim.a)) * (delta_radius + trt.a), // front left tower
|
||||
sin(RADIANS(210 + delta_tower_angle_trim.a)) * (delta_radius + trt.a));
|
||||
delta_tower[B_AXIS].set(cos(RADIANS(330 + delta_tower_angle_trim.b)) * (delta_radius + trt.b), // front right tower
|
||||
sin(RADIANS(330 + delta_tower_angle_trim.b)) * (delta_radius + trt.b));
|
||||
delta_tower[C_AXIS].set(cos(RADIANS( 90 + delta_tower_angle_trim.c)) * (delta_radius + trt.c), // back middle tower
|
||||
sin(RADIANS( 90 + delta_tower_angle_trim.c)) * (delta_radius + trt.c));
|
||||
delta_diagonal_rod_2_tower.set(sq(delta_diagonal_rod + drt.a),
|
||||
sq(delta_diagonal_rod + drt.b),
|
||||
sq(delta_diagonal_rod + drt.c));
|
||||
update_software_endstops(Z_AXIS);
|
||||
set_all_unhomed();
|
||||
}
|
||||
@@ -101,18 +100,16 @@ void recalc_delta_settings() {
|
||||
*/
|
||||
|
||||
#define DELTA_DEBUG(VAR) do { \
|
||||
SERIAL_ECHOLNPAIR("Cartesian X", VAR[X_AXIS], " Y", VAR[Y_AXIS], " Z", VAR[Z_AXIS]); \
|
||||
SERIAL_ECHOLNPAIR("Delta A", delta[A_AXIS], " B", delta[B_AXIS], " C", delta[C_AXIS]); \
|
||||
SERIAL_ECHOLNPAIR("Cartesian X", VAR.x, " Y", VAR.y, " Z", VAR.z); \
|
||||
SERIAL_ECHOLNPAIR("Delta A", delta.a, " B", delta.b, " C", delta.c); \
|
||||
}while(0)
|
||||
|
||||
void inverse_kinematics(const float (&raw)[XYZ]) {
|
||||
void inverse_kinematics(const xyz_pos_t &raw) {
|
||||
#if HAS_HOTEND_OFFSET
|
||||
// Delta hotend offsets must be applied in Cartesian space with no "spoofing"
|
||||
const float pos[XYZ] = {
|
||||
raw[X_AXIS] - hotend_offset[X_AXIS][active_extruder],
|
||||
raw[Y_AXIS] - hotend_offset[Y_AXIS][active_extruder],
|
||||
raw[Z_AXIS]
|
||||
};
|
||||
xyz_pos_t pos = { raw.x - hotend_offset[active_extruder].x,
|
||||
raw.y - hotend_offset[active_extruder].y,
|
||||
raw.z };
|
||||
DELTA_IK(pos);
|
||||
//DELTA_DEBUG(pos);
|
||||
#else
|
||||
@@ -126,12 +123,12 @@ void inverse_kinematics(const float (&raw)[XYZ]) {
|
||||
* effector has the full range of XY motion.
|
||||
*/
|
||||
float delta_safe_distance_from_top() {
|
||||
float cartesian[XYZ] = { 0, 0, 0 };
|
||||
xyz_pos_t cartesian{0};
|
||||
inverse_kinematics(cartesian);
|
||||
float centered_extent = delta[A_AXIS];
|
||||
cartesian[Y_AXIS] = DELTA_PRINTABLE_RADIUS;
|
||||
const float centered_extent = delta.a;
|
||||
cartesian.y = DELTA_PRINTABLE_RADIUS;
|
||||
inverse_kinematics(cartesian);
|
||||
return ABS(centered_extent - delta[A_AXIS]);
|
||||
return ABS(centered_extent - delta.a);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -161,7 +158,7 @@ float delta_safe_distance_from_top() {
|
||||
*/
|
||||
void forward_kinematics_DELTA(const float &z1, const float &z2, const float &z3) {
|
||||
// Create a vector in old coordinates along x axis of new coordinate
|
||||
const 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 },
|
||||
const float p12[3] = { delta_tower[B_AXIS].x - delta_tower[A_AXIS].x, delta_tower[B_AXIS].y - delta_tower[A_AXIS].y, z2 - z1 },
|
||||
|
||||
// Get the reciprocal of Magnitude of vector.
|
||||
d2 = sq(p12[0]) + sq(p12[1]) + sq(p12[2]), inv_d = RSQRT(d2),
|
||||
@@ -170,7 +167,7 @@ void forward_kinematics_DELTA(const float &z1, const float &z2, const float &z3)
|
||||
ex[3] = { p12[0] * inv_d, p12[1] * inv_d, p12[2] * inv_d },
|
||||
|
||||
// Get the vector from the origin of the new system to the third point.
|
||||
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 },
|
||||
p13[3] = { delta_tower[C_AXIS].x - delta_tower[A_AXIS].x, delta_tower[C_AXIS].y - delta_tower[A_AXIS].y, z3 - z1 },
|
||||
|
||||
// Use the dot product to find the component of this vector on the X axis.
|
||||
i = ex[0] * p13[0] + ex[1] * p13[1] + ex[2] * p13[2],
|
||||
@@ -198,16 +195,16 @@ void forward_kinematics_DELTA(const float &z1, const float &z2, const float &z3)
|
||||
|
||||
// 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
|
||||
Xnew = (delta_diagonal_rod_2_tower[A_AXIS] - delta_diagonal_rod_2_tower[B_AXIS] + d2) * inv_d * 0.5,
|
||||
Ynew = ((delta_diagonal_rod_2_tower[A_AXIS] - delta_diagonal_rod_2_tower[C_AXIS] + sq(i) + j2) * 0.5 - i * Xnew) * inv_j,
|
||||
Znew = SQRT(delta_diagonal_rod_2_tower[A_AXIS] - HYPOT2(Xnew, Ynew));
|
||||
Xnew = (delta_diagonal_rod_2_tower.a - delta_diagonal_rod_2_tower.b + d2) * inv_d * 0.5,
|
||||
Ynew = ((delta_diagonal_rod_2_tower.a - delta_diagonal_rod_2_tower.c + sq(i) + j2) * 0.5 - i * Xnew) * inv_j,
|
||||
Znew = SQRT(delta_diagonal_rod_2_tower.a - HYPOT2(Xnew, Ynew));
|
||||
|
||||
// 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
|
||||
// in the old system.
|
||||
cartes[X_AXIS] = delta_tower[A_AXIS][X_AXIS] + ex[0] * Xnew + ey[0] * Ynew - ez[0] * 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.set(delta_tower[A_AXIS].x + ex[0] * Xnew + ey[0] * Ynew - ez[0] * Znew,
|
||||
delta_tower[A_AXIS].y + ex[1] * Xnew + ey[1] * Ynew - ez[1] * Znew,
|
||||
z1 + ex[2] * Xnew + ey[2] * Ynew - ez[2] * Znew);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -217,8 +214,8 @@ void forward_kinematics_DELTA(const float &z1, const float &z2, const float &z3)
|
||||
void home_delta() {
|
||||
if (DEBUGGING(LEVELING)) DEBUG_POS(">>> home_delta", current_position);
|
||||
// Init the current position of all carriages to 0,0,0
|
||||
ZERO(current_position);
|
||||
ZERO(destination);
|
||||
current_position.reset();
|
||||
destination.reset();
|
||||
sync_plan_position();
|
||||
|
||||
// Disable stealthChop if used. Enable diag1 pin on driver.
|
||||
@@ -231,9 +228,9 @@ void home_delta() {
|
||||
#endif
|
||||
|
||||
// Move all carriages together linearly until an endstop is hit.
|
||||
current_position[Z_AXIS] = (delta_height + 10
|
||||
current_position.z = (delta_height + 10
|
||||
#if HAS_BED_PROBE
|
||||
- probe_offset[Z_AXIS]
|
||||
- probe_offset.z
|
||||
#endif
|
||||
);
|
||||
line_to_current_position(homing_feedrate(X_AXIS));
|
||||
|
Reference in New Issue
Block a user