2017-09-06 11:28:31 +00:00
|
|
|
/**
|
|
|
|
* Marlin 3D Printer Firmware
|
2020-02-03 14:00:57 +00:00
|
|
|
* Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
|
2017-09-06 11:28:31 +00:00
|
|
|
*
|
|
|
|
* Based on Sprinter and grbl.
|
2019-06-28 04:57:50 +00:00
|
|
|
* Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
|
2017-09-06 11:28:31 +00:00
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
2020-07-23 03:20:14 +00:00
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
2017-09-06 11:28:31 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2017-09-17 05:36:30 +00:00
|
|
|
#include "../../inc/MarlinConfig.h"
|
|
|
|
|
|
|
|
#include "../gcode.h"
|
|
|
|
#include "../../module/motion.h"
|
|
|
|
#include "../../module/stepper.h"
|
|
|
|
|
2017-11-14 06:03:17 +00:00
|
|
|
#if ENABLED(M114_DETAIL)
|
2017-09-06 11:28:31 +00:00
|
|
|
|
2020-01-14 00:47:30 +00:00
|
|
|
#if HAS_L64XX
|
|
|
|
#include "../../libs/L64XX/L64XX_Marlin.h"
|
2019-03-14 07:25:42 +00:00
|
|
|
#define DEBUG_OUT ENABLED(L6470_CHITCHAT)
|
|
|
|
#include "../../core/debug_out.h"
|
2019-01-24 01:06:54 +00:00
|
|
|
#endif
|
|
|
|
|
2020-03-03 03:52:53 +00:00
|
|
|
void report_xyze(const xyze_pos_t &pos, const uint8_t n=XYZE, const uint8_t precision=3) {
|
2017-09-06 11:28:31 +00:00
|
|
|
char str[12];
|
2020-03-14 04:18:16 +00:00
|
|
|
LOOP_L_N(a, n) {
|
2020-01-09 00:31:57 +00:00
|
|
|
SERIAL_CHAR(' ', axis_codes[a], ':');
|
2020-05-11 23:28:27 +00:00
|
|
|
if (pos[a] >= 0) SERIAL_CHAR(' ');
|
2019-09-14 08:05:10 +00:00
|
|
|
SERIAL_ECHO(dtostrf(pos[a], 1, precision, str));
|
2017-09-06 11:28:31 +00:00
|
|
|
}
|
|
|
|
SERIAL_EOL();
|
|
|
|
}
|
2020-05-11 23:28:27 +00:00
|
|
|
inline void report_xyz(const xyze_pos_t &pos) { report_xyze(pos, XYZ); }
|
2017-09-06 11:28:31 +00:00
|
|
|
|
2019-09-29 09:25:39 +00:00
|
|
|
void report_xyz(const xyz_pos_t &pos, const uint8_t precision=3) {
|
|
|
|
char str[12];
|
2020-03-01 16:36:15 +00:00
|
|
|
LOOP_XYZ(a) {
|
|
|
|
SERIAL_CHAR(' ', XYZ_CHAR(a), ':');
|
2019-09-29 09:25:39 +00:00
|
|
|
SERIAL_ECHO(dtostrf(pos[a], 1, precision, str));
|
|
|
|
}
|
|
|
|
SERIAL_EOL();
|
|
|
|
}
|
2017-09-06 11:28:31 +00:00
|
|
|
|
|
|
|
void report_current_position_detail() {
|
2020-03-03 03:52:53 +00:00
|
|
|
// Position as sent by G-code
|
2018-11-29 22:58:58 +00:00
|
|
|
SERIAL_ECHOPGM("\nLogical:");
|
2019-09-29 09:25:39 +00:00
|
|
|
report_xyz(current_position.asLogical());
|
2017-09-06 11:28:31 +00:00
|
|
|
|
2020-03-03 03:52:53 +00:00
|
|
|
// Cartesian position in native machine space
|
2018-11-29 22:58:58 +00:00
|
|
|
SERIAL_ECHOPGM("Raw: ");
|
2017-11-03 04:59:42 +00:00
|
|
|
report_xyz(current_position);
|
2017-09-06 11:28:31 +00:00
|
|
|
|
2019-09-29 09:25:39 +00:00
|
|
|
xyze_pos_t leveled = current_position;
|
2017-11-14 08:13:38 +00:00
|
|
|
|
2018-09-17 02:24:15 +00:00
|
|
|
#if HAS_LEVELING
|
2020-03-03 03:52:53 +00:00
|
|
|
// Current position with leveling applied
|
2018-11-29 22:58:58 +00:00
|
|
|
SERIAL_ECHOPGM("Leveled:");
|
2017-11-13 05:03:38 +00:00
|
|
|
planner.apply_leveling(leveled);
|
|
|
|
report_xyz(leveled);
|
2017-09-06 11:28:31 +00:00
|
|
|
|
2020-03-03 03:52:53 +00:00
|
|
|
// Test planner un-leveling. This should match the Raw result.
|
2018-11-29 22:58:58 +00:00
|
|
|
SERIAL_ECHOPGM("UnLevel:");
|
2019-09-29 09:25:39 +00:00
|
|
|
xyze_pos_t unleveled = leveled;
|
2017-11-13 05:03:38 +00:00
|
|
|
planner.unapply_leveling(unleveled);
|
|
|
|
report_xyz(unleveled);
|
|
|
|
#endif
|
2017-09-06 11:28:31 +00:00
|
|
|
|
|
|
|
#if IS_KINEMATIC
|
2020-03-03 03:52:53 +00:00
|
|
|
// Kinematics applied to the leveled position
|
2020-11-24 05:02:54 +00:00
|
|
|
SERIAL_ECHOPGM(TERN(IS_SCARA, "ScaraK: ", "DeltaK: "));
|
2017-09-06 11:28:31 +00:00
|
|
|
inverse_kinematics(leveled); // writes delta[]
|
|
|
|
report_xyz(delta);
|
|
|
|
#endif
|
|
|
|
|
2018-05-12 06:38:02 +00:00
|
|
|
planner.synchronize();
|
2018-05-04 01:51:10 +00:00
|
|
|
|
2020-01-14 00:47:30 +00:00
|
|
|
#if HAS_L64XX
|
2019-01-24 01:06:54 +00:00
|
|
|
char temp_buf[80];
|
|
|
|
int32_t temp;
|
|
|
|
//#define ABS_POS_SIGN_MASK 0b1111 1111 1110 0000 0000 0000 0000 0000
|
|
|
|
#define ABS_POS_SIGN_MASK 0b11111111111000000000000000000000
|
|
|
|
#define REPORT_ABSOLUTE_POS(Q) do{ \
|
2020-01-14 00:47:30 +00:00
|
|
|
L64xxManager.say_axis(Q, false); \
|
2019-01-24 01:06:54 +00:00
|
|
|
temp = L6470_GETPARAM(L6470_ABS_POS,Q); \
|
|
|
|
if (temp & ABS_POS_SIGN_MASK) temp |= ABS_POS_SIGN_MASK; \
|
|
|
|
sprintf_P(temp_buf, PSTR(":%8ld "), temp); \
|
2019-03-14 07:25:42 +00:00
|
|
|
DEBUG_ECHO(temp_buf); \
|
2019-01-24 01:06:54 +00:00
|
|
|
}while(0)
|
|
|
|
|
2019-03-14 07:25:42 +00:00
|
|
|
DEBUG_ECHOPGM("\nL6470:");
|
2020-01-14 00:47:30 +00:00
|
|
|
#if AXIS_IS_L64XX(X)
|
2019-01-24 01:06:54 +00:00
|
|
|
REPORT_ABSOLUTE_POS(X);
|
|
|
|
#endif
|
2020-01-14 00:47:30 +00:00
|
|
|
#if AXIS_IS_L64XX(X2)
|
2019-01-24 01:06:54 +00:00
|
|
|
REPORT_ABSOLUTE_POS(X2);
|
|
|
|
#endif
|
2020-01-14 00:47:30 +00:00
|
|
|
#if AXIS_IS_L64XX(Y)
|
2019-01-24 01:06:54 +00:00
|
|
|
REPORT_ABSOLUTE_POS(Y);
|
|
|
|
#endif
|
2020-01-14 00:47:30 +00:00
|
|
|
#if AXIS_IS_L64XX(Y2)
|
2019-01-24 01:06:54 +00:00
|
|
|
REPORT_ABSOLUTE_POS(Y2);
|
|
|
|
#endif
|
2020-01-14 00:47:30 +00:00
|
|
|
#if AXIS_IS_L64XX(Z)
|
2019-01-24 01:06:54 +00:00
|
|
|
REPORT_ABSOLUTE_POS(Z);
|
|
|
|
#endif
|
2020-01-14 00:47:30 +00:00
|
|
|
#if AXIS_IS_L64XX(Z2)
|
2019-01-24 01:06:54 +00:00
|
|
|
REPORT_ABSOLUTE_POS(Z2);
|
|
|
|
#endif
|
2020-01-14 00:47:30 +00:00
|
|
|
#if AXIS_IS_L64XX(Z3)
|
2019-01-24 01:06:54 +00:00
|
|
|
REPORT_ABSOLUTE_POS(Z3);
|
|
|
|
#endif
|
2020-01-20 05:35:07 +00:00
|
|
|
#if AXIS_IS_L64XX(Z4)
|
|
|
|
REPORT_ABSOLUTE_POS(Z4);
|
|
|
|
#endif
|
2020-01-14 00:47:30 +00:00
|
|
|
#if AXIS_IS_L64XX(E0)
|
2019-01-24 01:06:54 +00:00
|
|
|
REPORT_ABSOLUTE_POS(E0);
|
|
|
|
#endif
|
2020-01-14 00:47:30 +00:00
|
|
|
#if AXIS_IS_L64XX(E1)
|
2019-01-24 01:06:54 +00:00
|
|
|
REPORT_ABSOLUTE_POS(E1);
|
|
|
|
#endif
|
2020-01-14 00:47:30 +00:00
|
|
|
#if AXIS_IS_L64XX(E2)
|
2019-01-24 01:06:54 +00:00
|
|
|
REPORT_ABSOLUTE_POS(E2);
|
|
|
|
#endif
|
2020-01-14 00:47:30 +00:00
|
|
|
#if AXIS_IS_L64XX(E3)
|
2019-01-24 01:06:54 +00:00
|
|
|
REPORT_ABSOLUTE_POS(E3);
|
|
|
|
#endif
|
2020-01-14 00:47:30 +00:00
|
|
|
#if AXIS_IS_L64XX(E4)
|
2019-01-24 01:06:54 +00:00
|
|
|
REPORT_ABSOLUTE_POS(E4);
|
|
|
|
#endif
|
2020-01-14 00:47:30 +00:00
|
|
|
#if AXIS_IS_L64XX(E5)
|
2019-01-24 01:06:54 +00:00
|
|
|
REPORT_ABSOLUTE_POS(E5);
|
|
|
|
#endif
|
2020-02-04 18:37:20 +00:00
|
|
|
#if AXIS_IS_L64XX(E6)
|
|
|
|
REPORT_ABSOLUTE_POS(E6);
|
|
|
|
#endif
|
|
|
|
#if AXIS_IS_L64XX(E7)
|
|
|
|
REPORT_ABSOLUTE_POS(E7);
|
|
|
|
#endif
|
2019-01-24 01:06:54 +00:00
|
|
|
SERIAL_EOL();
|
2020-01-14 00:47:30 +00:00
|
|
|
#endif // HAS_L64XX
|
2019-01-24 01:06:54 +00:00
|
|
|
|
2018-11-29 22:58:58 +00:00
|
|
|
SERIAL_ECHOPGM("Stepper:");
|
2017-12-11 01:12:00 +00:00
|
|
|
LOOP_XYZE(i) {
|
2020-01-09 00:31:57 +00:00
|
|
|
SERIAL_CHAR(' ', axis_codes[i], ':');
|
2018-11-29 22:58:58 +00:00
|
|
|
SERIAL_ECHO(stepper.position((AxisEnum)i));
|
2017-12-11 01:12:00 +00:00
|
|
|
}
|
|
|
|
SERIAL_EOL();
|
2017-09-06 11:28:31 +00:00
|
|
|
|
|
|
|
#if IS_SCARA
|
2019-09-29 09:25:39 +00:00
|
|
|
const xy_float_t deg = {
|
2018-05-12 14:59:11 +00:00
|
|
|
planner.get_axis_position_degrees(A_AXIS),
|
|
|
|
planner.get_axis_position_degrees(B_AXIS)
|
2017-09-06 11:28:31 +00:00
|
|
|
};
|
2018-11-29 22:58:58 +00:00
|
|
|
SERIAL_ECHOPGM("Degrees:");
|
2017-09-06 11:28:31 +00:00
|
|
|
report_xyze(deg, 2);
|
|
|
|
#endif
|
|
|
|
|
2018-11-29 22:58:58 +00:00
|
|
|
SERIAL_ECHOPGM("FromStp:");
|
2019-09-29 09:25:39 +00:00
|
|
|
get_cartesian_from_steppers(); // writes 'cartes' (with forward kinematics)
|
|
|
|
xyze_pos_t from_steppers = { cartes.x, cartes.y, cartes.z, planner.get_axis_position_mm(E_AXIS) };
|
2017-09-06 11:28:31 +00:00
|
|
|
report_xyze(from_steppers);
|
|
|
|
|
2019-09-29 09:25:39 +00:00
|
|
|
const xyze_float_t diff = from_steppers - leveled;
|
2020-05-17 00:49:02 +00:00
|
|
|
SERIAL_ECHOPGM("Diff: ");
|
2017-09-06 11:28:31 +00:00
|
|
|
report_xyze(diff);
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // M114_DETAIL
|
|
|
|
|
|
|
|
/**
|
2020-03-03 03:52:53 +00:00
|
|
|
* M114: Report the current position to host.
|
|
|
|
* Since steppers are moving, the count positions are
|
|
|
|
* projected by using planner calculations.
|
|
|
|
* D - Report more detail. This syncs the planner. (Requires M114_DETAIL)
|
|
|
|
* E - Report E stepper position (Requires M114_DETAIL)
|
|
|
|
* R - Report the realtime position instead of projected.
|
2017-09-06 11:28:31 +00:00
|
|
|
*/
|
2017-09-17 05:36:30 +00:00
|
|
|
void GcodeSuite::M114() {
|
2017-09-06 11:28:31 +00:00
|
|
|
|
2017-11-14 06:03:17 +00:00
|
|
|
#if ENABLED(M114_DETAIL)
|
2017-09-06 11:28:31 +00:00
|
|
|
if (parser.seen('D')) {
|
2020-03-03 03:52:53 +00:00
|
|
|
#if DISABLED(M114_LEGACY)
|
|
|
|
planner.synchronize();
|
|
|
|
#endif
|
|
|
|
report_current_position();
|
2017-09-06 11:28:31 +00:00
|
|
|
report_current_position_detail();
|
|
|
|
return;
|
|
|
|
}
|
2019-11-29 12:53:32 +00:00
|
|
|
if (parser.seen('E')) {
|
|
|
|
SERIAL_ECHOLNPAIR("Count E:", stepper.position(E_AXIS));
|
|
|
|
return;
|
|
|
|
}
|
2017-09-06 11:28:31 +00:00
|
|
|
#endif
|
|
|
|
|
2020-03-03 03:52:53 +00:00
|
|
|
#if ENABLED(M114_REALTIME)
|
|
|
|
if (parser.seen('R')) { report_real_position(); return; }
|
|
|
|
#endif
|
|
|
|
|
2020-04-22 21:35:03 +00:00
|
|
|
TERN_(M114_LEGACY, planner.synchronize());
|
2020-03-03 03:52:53 +00:00
|
|
|
report_current_position_projected();
|
2017-09-06 11:28:31 +00:00
|
|
|
}
|