219 lines
6.5 KiB
C++
Raw Normal View History

/**
* Marlin 3D Printer Firmware
2020-02-03 08:00:57 -06:00
* Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* Based on Sprinter and grbl.
2019-06-27 23:57:50 -05:00
* Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
*
* 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-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)
#if HAS_L64XX
#include "../../libs/L64XX/L64XX_Marlin.h"
#define DEBUG_OUT ENABLED(L6470_CHITCHAT)
#include "../../core/debug_out.h"
2019-01-23 19:06:54 -06:00
#endif
2021-05-18 22:46:59 -05:00
void report_all_axis_pos(const xyze_pos_t &pos, const uint8_t n=XYZE, const uint8_t precision=3) {
char str[12];
2020-03-13 23:18:16 -05:00
LOOP_L_N(a, n) {
SERIAL_CHAR(' ', axis_codes[a], ':');
2020-05-11 18:28:27 -05:00
if (pos[a] >= 0) SERIAL_CHAR(' ');
SERIAL_ECHO(dtostrf(pos[a], 1, precision, str));
}
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); }
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];
2021-05-18 22:51:19 -05:00
LOOP_LINEAR_AXES(a) {
SERIAL_CHAR(' ', AXIS_CHAR(a), ':');
2019-09-29 04:25:39 -05:00
SERIAL_ECHO(dtostrf(pos[a], 1, precision, str));
}
SERIAL_EOL();
}
void report_current_position_detail() {
// Position as sent by G-code
SERIAL_ECHOPGM("\nLogical:");
2021-05-18 22:46:59 -05:00
report_linear_axis_pos(current_position.asLogical());
// Cartesian position in native machine space
SERIAL_ECHOPGM("Raw: ");
2021-05-18 22:46:59 -05:00
report_linear_axis_pos(current_position);
2019-09-29 04:25:39 -05:00
xyze_pos_t leveled = current_position;
#if HAS_LEVELING
// Current position with leveling applied
SERIAL_ECHOPGM("Leveled:");
planner.apply_leveling(leveled);
2021-05-18 22:46:59 -05:00
report_linear_axis_pos(leveled);
// Test planner un-leveling. This should match the Raw result.
SERIAL_ECHOPGM("UnLevel:");
2019-09-29 04:25:39 -05:00
xyze_pos_t unleveled = leveled;
planner.unapply_leveling(unleveled);
2021-05-18 22:46:59 -05:00
report_linear_axis_pos(unleveled);
#endif
#if IS_KINEMATIC
// Kinematics applied to the leveled position
2020-11-23 23:02:54 -06:00
SERIAL_ECHOPGM(TERN(IS_SCARA, "ScaraK: ", "DeltaK: "));
inverse_kinematics(leveled); // writes delta[]
2021-05-18 22:46:59 -05:00
report_linear_axis_pos(delta);
#endif
planner.synchronize();
2018-05-03 20:51:10 -05:00
#if HAS_L64XX
2019-01-23 19:06:54 -06: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{ \
L64xxManager.say_axis(Q, false); \
2019-01-23 19:06:54 -06: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); \
DEBUG_ECHO(temp_buf); \
2019-01-23 19:06:54 -06:00
}while(0)
DEBUG_ECHOPGM("\nL6470:");
#if AXIS_IS_L64XX(X)
2019-01-23 19:06:54 -06:00
REPORT_ABSOLUTE_POS(X);
#endif
#if AXIS_IS_L64XX(X2)
2019-01-23 19:06:54 -06:00
REPORT_ABSOLUTE_POS(X2);
#endif
#if AXIS_IS_L64XX(Y)
2019-01-23 19:06:54 -06:00
REPORT_ABSOLUTE_POS(Y);
#endif
#if AXIS_IS_L64XX(Y2)
2019-01-23 19:06:54 -06:00
REPORT_ABSOLUTE_POS(Y2);
#endif
#if AXIS_IS_L64XX(Z)
2019-01-23 19:06:54 -06:00
REPORT_ABSOLUTE_POS(Z);
#endif
#if AXIS_IS_L64XX(Z2)
2019-01-23 19:06:54 -06:00
REPORT_ABSOLUTE_POS(Z2);
#endif
#if AXIS_IS_L64XX(Z3)
2019-01-23 19:06:54 -06:00
REPORT_ABSOLUTE_POS(Z3);
#endif
2020-01-20 00:35:07 -05:00
#if AXIS_IS_L64XX(Z4)
REPORT_ABSOLUTE_POS(Z4);
#endif
#if AXIS_IS_L64XX(E0)
2019-01-23 19:06:54 -06:00
REPORT_ABSOLUTE_POS(E0);
#endif
#if AXIS_IS_L64XX(E1)
2019-01-23 19:06:54 -06:00
REPORT_ABSOLUTE_POS(E1);
#endif
#if AXIS_IS_L64XX(E2)
2019-01-23 19:06:54 -06:00
REPORT_ABSOLUTE_POS(E2);
#endif
#if AXIS_IS_L64XX(E3)
2019-01-23 19:06:54 -06:00
REPORT_ABSOLUTE_POS(E3);
#endif
#if AXIS_IS_L64XX(E4)
2019-01-23 19:06:54 -06:00
REPORT_ABSOLUTE_POS(E4);
#endif
#if AXIS_IS_L64XX(E5)
2019-01-23 19:06:54 -06:00
REPORT_ABSOLUTE_POS(E5);
#endif
2020-02-04 12:37:20 -06:00
#if AXIS_IS_L64XX(E6)
REPORT_ABSOLUTE_POS(E6);
#endif
#if AXIS_IS_L64XX(E7)
REPORT_ABSOLUTE_POS(E7);
#endif
2019-01-23 19:06:54 -06:00
SERIAL_EOL();
#endif // HAS_L64XX
2019-01-23 19:06:54 -06:00
SERIAL_ECHOPGM("Stepper:");
2021-05-18 22:51:19 -05:00
LOOP_LOGICAL_AXES(i) {
SERIAL_CHAR(' ', axis_codes[i], ':');
SERIAL_ECHO(stepper.position((AxisEnum)i));
2017-12-10 19:12:00 -06:00
}
SERIAL_EOL();
#if IS_SCARA
2019-09-29 04:25:39 -05:00
const xy_float_t deg = {
planner.get_axis_position_degrees(A_AXIS),
planner.get_axis_position_degrees(B_AXIS)
};
SERIAL_ECHOPGM("Degrees:");
2021-05-18 22:46:59 -05:00
report_all_axis_pos(deg, 2);
#endif
SERIAL_ECHOPGM("FromStp:");
2019-09-29 04:25:39 -05:00
get_cartesian_from_steppers(); // writes 'cartes' (with forward kinematics)
xyze_pos_t from_steppers = LOGICAL_AXIS_ARRAY(planner.get_axis_position_mm(E_AXIS), cartes.x, cartes.y, cartes.z);
2021-05-18 22:46:59 -05:00
report_all_axis_pos(from_steppers);
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);
TERN_(FULL_REPORT_TO_HOST_FEATURE, report_current_grblstate_moving());
}
#endif // M114_DETAIL
/**
* 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-17 00:36:30 -05:00
void GcodeSuite::M114() {
2017-11-14 00:03:17 -06:00
#if ENABLED(M114_DETAIL)
if (parser.seen_test('D')) {
#if DISABLED(M114_LEGACY)
planner.synchronize();
#endif
report_current_position();
report_current_position_detail();
return;
}
if (parser.seen_test('E')) {
SERIAL_ECHOLNPAIR("Count E:", stepper.position(E_AXIS));
return;
}
#endif
#if ENABLED(M114_REALTIME)
if (parser.seen_test('R')) { report_real_position(); return; }
#endif
2020-04-22 16:35:03 -05:00
TERN_(M114_LEGACY, planner.synchronize());
report_current_position_projected();
TERN_(FULL_REPORT_TO_HOST_FEATURE, report_current_grblstate_moving());
}