2017-09-06 06:28:31 -05:00
|
|
|
/**
|
|
|
|
* Marlin 3D Printer Firmware
|
2020-02-03 08:00:57 -06:00
|
|
|
* Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
|
2017-09-06 06:28:31 -05:00
|
|
|
*
|
|
|
|
* Based on Sprinter and grbl.
|
2019-06-27 23:57:50 -05:00
|
|
|
* Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
|
2017-09-06 06:28:31 -05: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 05:20:14 +02:00
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
2017-09-06 06:28:31 -05:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2017-09-17 00:36:30 -05:00
|
|
|
#include "../../inc/MarlinConfig.h"
|
|
|
|
|
|
|
|
#include "../gcode.h"
|
|
|
|
#include "../../module/motion.h"
|
|
|
|
#include "../../module/stepper.h"
|
|
|
|
|
2017-11-14 00:03:17 -06:00
|
|
|
#if ENABLED(M114_DETAIL)
|
2017-09-06 06:28:31 -05:00
|
|
|
|
2022-04-29 15:21:15 -05:00
|
|
|
void report_all_axis_pos(const xyze_pos_t &pos, const uint8_t n=LOGICAL_AXES, const uint8_t precision=3) {
|
2017-09-06 06:28:31 -05:00
|
|
|
char str[12];
|
2020-03-13 23:18:16 -05:00
|
|
|
LOOP_L_N(a, n) {
|
2022-04-03 20:13:11 -05:00
|
|
|
SERIAL_ECHOPGM_P((PGM_P)pgm_read_ptr(&SP_AXIS_LBL[a]));
|
2020-05-11 18:28:27 -05:00
|
|
|
if (pos[a] >= 0) SERIAL_CHAR(' ');
|
2019-09-14 03:05:10 -05:00
|
|
|
SERIAL_ECHO(dtostrf(pos[a], 1, precision, str));
|
2017-09-06 06:28:31 -05:00
|
|
|
}
|
|
|
|
SERIAL_EOL();
|
|
|
|
}
|
2021-05-18 22:46:59 -05:00
|
|
|
inline void report_linear_axis_pos(const xyze_pos_t &pos) { report_all_axis_pos(pos, XYZ); }
|
2017-09-06 06:28:31 -05:00
|
|
|
|
2021-05-18 22:46:59 -05:00
|
|
|
void report_linear_axis_pos(const xyz_pos_t &pos, const uint8_t precision=3) {
|
2019-09-29 04:25:39 -05:00
|
|
|
char str[12];
|
2022-04-03 20:13:11 -05:00
|
|
|
LOOP_NUM_AXES(a) SERIAL_ECHOPGM_P((PGM_P)pgm_read_ptr(&SP_AXIS_LBL[a]), dtostrf(pos[a], 1, precision, str));
|
2019-09-29 04:25:39 -05:00
|
|
|
SERIAL_EOL();
|
|
|
|
}
|
2017-09-06 06:28:31 -05:00
|
|
|
|
|
|
|
void report_current_position_detail() {
|
2020-03-02 21:52:53 -06:00
|
|
|
// Position as sent by G-code
|
2018-11-29 16:58:58 -06:00
|
|
|
SERIAL_ECHOPGM("\nLogical:");
|
2021-05-18 22:46:59 -05:00
|
|
|
report_linear_axis_pos(current_position.asLogical());
|
2017-09-06 06:28:31 -05:00
|
|
|
|
2020-03-02 21:52:53 -06:00
|
|
|
// Cartesian position in native machine space
|
2018-11-29 16:58:58 -06:00
|
|
|
SERIAL_ECHOPGM("Raw: ");
|
2021-05-18 22:46:59 -05:00
|
|
|
report_linear_axis_pos(current_position);
|
2017-09-06 06:28:31 -05:00
|
|
|
|
2019-09-29 04:25:39 -05:00
|
|
|
xyze_pos_t leveled = current_position;
|
2017-11-14 02:13:38 -06:00
|
|
|
|
2018-09-16 22:24:15 -04:00
|
|
|
#if HAS_LEVELING
|
2020-03-02 21:52:53 -06:00
|
|
|
// Current position with leveling applied
|
2018-11-29 16:58:58 -06:00
|
|
|
SERIAL_ECHOPGM("Leveled:");
|
2017-11-12 23:03:38 -06:00
|
|
|
planner.apply_leveling(leveled);
|
2021-05-18 22:46:59 -05:00
|
|
|
report_linear_axis_pos(leveled);
|
2017-09-06 06:28:31 -05:00
|
|
|
|
2020-03-02 21:52:53 -06:00
|
|
|
// Test planner un-leveling. This should match the Raw result.
|
2018-11-29 16:58:58 -06:00
|
|
|
SERIAL_ECHOPGM("UnLevel:");
|
2019-09-29 04:25:39 -05:00
|
|
|
xyze_pos_t unleveled = leveled;
|
2017-11-12 23:03:38 -06:00
|
|
|
planner.unapply_leveling(unleveled);
|
2021-05-18 22:46:59 -05:00
|
|
|
report_linear_axis_pos(unleveled);
|
2017-11-12 23:03:38 -06:00
|
|
|
#endif
|
2017-09-06 06:28:31 -05:00
|
|
|
|
|
|
|
#if IS_KINEMATIC
|
2020-03-02 21:52:53 -06:00
|
|
|
// Kinematics applied to the leveled position
|
2020-11-23 23:02:54 -06:00
|
|
|
SERIAL_ECHOPGM(TERN(IS_SCARA, "ScaraK: ", "DeltaK: "));
|
2017-09-06 06:28:31 -05:00
|
|
|
inverse_kinematics(leveled); // writes delta[]
|
2021-05-18 22:46:59 -05:00
|
|
|
report_linear_axis_pos(delta);
|
2017-09-06 06:28:31 -05:00
|
|
|
#endif
|
|
|
|
|
2018-05-12 01:38:02 -05:00
|
|
|
planner.synchronize();
|
2018-05-03 20:51:10 -05:00
|
|
|
|
2018-11-29 16:58:58 -06:00
|
|
|
SERIAL_ECHOPGM("Stepper:");
|
2021-05-18 22:51:19 -05:00
|
|
|
LOOP_LOGICAL_AXES(i) {
|
2022-04-03 20:13:11 -05:00
|
|
|
SERIAL_ECHOPGM_P((PGM_P)pgm_read_ptr(&SP_AXIS_LBL[i]), stepper.position((AxisEnum)i));
|
2017-12-10 19:12:00 -06:00
|
|
|
}
|
|
|
|
SERIAL_EOL();
|
2017-09-06 06:28:31 -05:00
|
|
|
|
|
|
|
#if IS_SCARA
|
2019-09-29 04:25:39 -05:00
|
|
|
const xy_float_t deg = {
|
2018-05-12 09:59:11 -05:00
|
|
|
planner.get_axis_position_degrees(A_AXIS),
|
|
|
|
planner.get_axis_position_degrees(B_AXIS)
|
2017-09-06 06:28:31 -05:00
|
|
|
};
|
2018-11-29 16:58:58 -06:00
|
|
|
SERIAL_ECHOPGM("Degrees:");
|
2021-05-18 22:46:59 -05:00
|
|
|
report_all_axis_pos(deg, 2);
|
2017-09-06 06:28:31 -05:00
|
|
|
#endif
|
|
|
|
|
2018-11-29 16:58:58 -06:00
|
|
|
SERIAL_ECHOPGM("FromStp:");
|
2019-09-29 04:25:39 -05:00
|
|
|
get_cartesian_from_steppers(); // writes 'cartes' (with forward kinematics)
|
2021-06-05 09:18:47 +02:00
|
|
|
xyze_pos_t from_steppers = LOGICAL_AXIS_ARRAY(
|
|
|
|
planner.get_axis_position_mm(E_AXIS),
|
|
|
|
cartes.x, cartes.y, cartes.z,
|
|
|
|
planner.get_axis_position_mm(I_AXIS),
|
|
|
|
planner.get_axis_position_mm(J_AXIS),
|
2022-04-29 15:21:15 -05:00
|
|
|
planner.get_axis_position_mm(K_AXIS),
|
|
|
|
planner.get_axis_position_mm(U_AXIS),
|
|
|
|
planner.get_axis_position_mm(V_AXIS),
|
|
|
|
planner.get_axis_position_mm(W_AXIS)
|
2021-06-05 09:18:47 +02:00
|
|
|
);
|
2021-05-18 22:46:59 -05:00
|
|
|
report_all_axis_pos(from_steppers);
|
2017-09-06 06:28:31 -05:00
|
|
|
|
2019-09-29 04:25:39 -05:00
|
|
|
const xyze_float_t diff = from_steppers - leveled;
|
2020-05-16 19:49:02 -05:00
|
|
|
SERIAL_ECHOPGM("Diff: ");
|
2021-05-18 22:46:59 -05:00
|
|
|
report_all_axis_pos(diff);
|
2021-04-16 08:59:28 +02:00
|
|
|
|
|
|
|
TERN_(FULL_REPORT_TO_HOST_FEATURE, report_current_grblstate_moving());
|
2017-09-06 06:28:31 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif // M114_DETAIL
|
|
|
|
|
|
|
|
/**
|
2020-03-02 21:52:53 -06: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 06:28:31 -05:00
|
|
|
*/
|
2017-09-17 00:36:30 -05:00
|
|
|
void GcodeSuite::M114() {
|
2017-09-06 06:28:31 -05:00
|
|
|
|
2017-11-14 00:03:17 -06:00
|
|
|
#if ENABLED(M114_DETAIL)
|
2021-05-09 03:50:51 -05:00
|
|
|
if (parser.seen_test('D')) {
|
2020-03-02 21:52:53 -06:00
|
|
|
#if DISABLED(M114_LEGACY)
|
|
|
|
planner.synchronize();
|
|
|
|
#endif
|
|
|
|
report_current_position();
|
2017-09-06 06:28:31 -05:00
|
|
|
report_current_position_detail();
|
|
|
|
return;
|
|
|
|
}
|
2021-06-21 13:36:06 -07:00
|
|
|
#if HAS_EXTRUDERS
|
|
|
|
if (parser.seen_test('E')) {
|
2021-09-09 04:57:05 -05:00
|
|
|
SERIAL_ECHOLNPGM("Count E:", stepper.position(E_AXIS));
|
2021-06-21 13:36:06 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
#endif
|
2017-09-06 06:28:31 -05:00
|
|
|
#endif
|
|
|
|
|
2020-03-02 21:52:53 -06:00
|
|
|
#if ENABLED(M114_REALTIME)
|
2021-05-09 03:50:51 -05:00
|
|
|
if (parser.seen_test('R')) { report_real_position(); return; }
|
2020-03-02 21:52:53 -06:00
|
|
|
#endif
|
|
|
|
|
2020-04-22 16:35:03 -05:00
|
|
|
TERN_(M114_LEGACY, planner.synchronize());
|
2020-03-02 21:52:53 -06:00
|
|
|
report_current_position_projected();
|
2021-04-16 08:59:28 +02:00
|
|
|
|
|
|
|
TERN_(FULL_REPORT_TO_HOST_FEATURE, report_current_grblstate_moving());
|
2017-09-06 06:28:31 -05:00
|
|
|
}
|