My Marlin configs for Fabrikator Mini and CTC i3 Pro B
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. /**
  2. * Marlin 3D Printer Firmware
  3. * Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
  4. *
  5. * Based on Sprinter and grbl.
  6. * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
  7. *
  8. * This program 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. * This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
  20. *
  21. */
  22. /**
  23. * scara.cpp
  24. */
  25. #include "../inc/MarlinConfig.h"
  26. #if IS_SCARA
  27. #include "scara.h"
  28. #include "motion.h"
  29. #include "planner.h"
  30. float delta_segments_per_second = SCARA_SEGMENTS_PER_SECOND;
  31. void scara_set_axis_is_at_home(const AxisEnum axis) {
  32. if (axis == Z_AXIS)
  33. current_position[Z_AXIS] = Z_HOME_POS;
  34. else {
  35. /**
  36. * SCARA homes XY at the same time
  37. */
  38. float homeposition[XYZ];
  39. LOOP_XYZ(i) homeposition[i] = base_home_pos((AxisEnum)i);
  40. // SERIAL_ECHOLNPAIR("homeposition X:", homeposition[X_AXIS], " Y:", homeposition[Y_AXIS]);
  41. /**
  42. * Get Home position SCARA arm angles using inverse kinematics,
  43. * and calculate homing offset using forward kinematics
  44. */
  45. inverse_kinematics(homeposition);
  46. forward_kinematics_SCARA(delta[A_AXIS], delta[B_AXIS]);
  47. // SERIAL_ECHOLNPAIR("Cartesian X:", cartes[X_AXIS], " Y:", cartes[Y_AXIS]);
  48. current_position[axis] = cartes[axis];
  49. update_software_endstops(axis);
  50. }
  51. }
  52. /**
  53. * Morgan SCARA Forward Kinematics. Results in cartes[].
  54. * Maths and first version by QHARLEY.
  55. * Integrated into Marlin and slightly restructured by Joachim Cerny.
  56. */
  57. void forward_kinematics_SCARA(const float &a, const float &b) {
  58. const float a_sin = sin(RADIANS(a)) * L1,
  59. a_cos = cos(RADIANS(a)) * L1,
  60. b_sin = sin(RADIANS(b)) * L2,
  61. b_cos = cos(RADIANS(b)) * L2;
  62. cartes[X_AXIS] = a_cos + b_cos + SCARA_OFFSET_X; //theta
  63. cartes[Y_AXIS] = a_sin + b_sin + SCARA_OFFSET_Y; //theta+phi
  64. /*
  65. SERIAL_ECHOLNPAIR(
  66. "SCARA FK Angle a=", a,
  67. " b=", b,
  68. " a_sin=", a_sin,
  69. " a_cos=", a_cos,
  70. " b_sin=", b_sin,
  71. " b_cos=", b_cos
  72. );
  73. SERIAL_ECHOLNPAIR(" cartes (X,Y) = "(cartes[X_AXIS], ", ", cartes[Y_AXIS], ")");
  74. //*/
  75. }
  76. /**
  77. * Morgan SCARA Inverse Kinematics. Results in delta[].
  78. *
  79. * See http://forums.reprap.org/read.php?185,283327
  80. *
  81. * Maths and first version by QHARLEY.
  82. * Integrated into Marlin and slightly restructured by Joachim Cerny.
  83. */
  84. void inverse_kinematics(const float (&raw)[XYZ]) {
  85. static float C2, S2, SK1, SK2, THETA, PSI;
  86. float sx = raw[X_AXIS] - SCARA_OFFSET_X, // Translate SCARA to standard X Y
  87. sy = raw[Y_AXIS] - SCARA_OFFSET_Y; // With scaling factor.
  88. if (L1 == L2)
  89. C2 = HYPOT2(sx, sy) / L1_2_2 - 1;
  90. else
  91. C2 = (HYPOT2(sx, sy) - (L1_2 + L2_2)) / (2.0 * L1 * L2);
  92. S2 = SQRT(1 - sq(C2));
  93. // Unrotated Arm1 plus rotated Arm2 gives the distance from Center to End
  94. SK1 = L1 + L2 * C2;
  95. // Rotated Arm2 gives the distance from Arm1 to Arm2
  96. SK2 = L2 * S2;
  97. // Angle of Arm1 is the difference between Center-to-End angle and the Center-to-Elbow
  98. THETA = ATAN2(SK1, SK2) - ATAN2(sx, sy);
  99. // Angle of Arm2
  100. PSI = ATAN2(S2, C2);
  101. delta[A_AXIS] = DEGREES(THETA); // theta is support arm angle
  102. delta[B_AXIS] = DEGREES(THETA + PSI); // equal to sub arm angle (inverted motor)
  103. delta[C_AXIS] = raw[Z_AXIS];
  104. /*
  105. DEBUG_POS("SCARA IK", raw);
  106. DEBUG_POS("SCARA IK", delta);
  107. SERIAL_ECHOLNPAIR(" SCARA (x,y) ", sx, ",", sy, " C2=", C2, " S2=", S2, " Theta=", THETA, " Phi=", PHI);
  108. //*/
  109. }
  110. void scara_report_positions() {
  111. SERIAL_ECHOLNPAIR("SCARA Theta:", planner.get_axis_position_degrees(A_AXIS), " Psi+Theta:", planner.get_axis_position_degrees(B_AXIS));
  112. SERIAL_EOL();
  113. }
  114. #endif // IS_SCARA