✨ Bed Distance Sensor (#24554)
This commit is contained in:
parent
a0462eb017
commit
b02c3258b5
@ -1886,6 +1886,15 @@
|
|||||||
#define LEVELING_BED_TEMP 50
|
#define LEVELING_BED_TEMP 50
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Bed Distance Sensor
|
||||||
|
*
|
||||||
|
* Measures the distance from bed to nozzle with accuracy of 0.01mm.
|
||||||
|
* For information about this sensor https://github.com/markniu/Bed_Distance_sensor
|
||||||
|
* Uses I2C port, so it requires I2C library markyue/Panda_SoftMasterI2C.
|
||||||
|
*/
|
||||||
|
//#define BD_SENSOR
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enable detailed logging of G28, G29, M48, etc.
|
* Enable detailed logging of G28, G29, M48, etc.
|
||||||
* Turn on with the command 'M111 S32'.
|
* Turn on with the command 'M111 S32'.
|
||||||
|
@ -121,6 +121,10 @@
|
|||||||
#include "feature/bltouch.h"
|
#include "feature/bltouch.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if ENABLED(BD_SENSOR)
|
||||||
|
#include "feature/bedlevel/bdl/bdl.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
#if ENABLED(POLL_JOG)
|
#if ENABLED(POLL_JOG)
|
||||||
#include "feature/joystick.h"
|
#include "feature/joystick.h"
|
||||||
#endif
|
#endif
|
||||||
@ -779,6 +783,9 @@ void idle(bool no_stepper_sleep/*=false*/) {
|
|||||||
if (++idle_depth > 5) SERIAL_ECHOLNPGM("idle() call depth: ", idle_depth);
|
if (++idle_depth > 5) SERIAL_ECHOLNPGM("idle() call depth: ", idle_depth);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
// Bed Distance Sensor task
|
||||||
|
TERN_(BD_SENSOR, bdl.process());
|
||||||
|
|
||||||
// Core Marlin activities
|
// Core Marlin activities
|
||||||
manage_inactivity(no_stepper_sleep);
|
manage_inactivity(no_stepper_sleep);
|
||||||
|
|
||||||
@ -1632,6 +1639,10 @@ void setup() {
|
|||||||
SETUP_RUN(test_tmc_connection());
|
SETUP_RUN(test_tmc_connection());
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if ENABLED(BD_SENSOR)
|
||||||
|
SETUP_RUN(bdl.init(I2C_BD_SDA_PIN, I2C_BD_SCL_PIN, I2C_BD_DELAY));
|
||||||
|
#endif
|
||||||
|
|
||||||
marlin_state = MF_RUNNING;
|
marlin_state = MF_RUNNING;
|
||||||
|
|
||||||
SETUP_LOG("setup() completed.");
|
SETUP_LOG("setup() completed.");
|
||||||
|
@ -70,6 +70,7 @@ void safe_delay(millis_t ms) {
|
|||||||
TERN_(NOZZLE_AS_PROBE, "NOZZLE_AS_PROBE")
|
TERN_(NOZZLE_AS_PROBE, "NOZZLE_AS_PROBE")
|
||||||
TERN_(FIX_MOUNTED_PROBE, "FIX_MOUNTED_PROBE")
|
TERN_(FIX_MOUNTED_PROBE, "FIX_MOUNTED_PROBE")
|
||||||
TERN_(HAS_Z_SERVO_PROBE, TERN(BLTOUCH, "BLTOUCH", "SERVO PROBE"))
|
TERN_(HAS_Z_SERVO_PROBE, TERN(BLTOUCH, "BLTOUCH", "SERVO PROBE"))
|
||||||
|
TERN_(BD_SENSOR, "BD_SENSOR")
|
||||||
TERN_(TOUCH_MI_PROBE, "TOUCH_MI_PROBE")
|
TERN_(TOUCH_MI_PROBE, "TOUCH_MI_PROBE")
|
||||||
TERN_(Z_PROBE_SLED, "Z_PROBE_SLED")
|
TERN_(Z_PROBE_SLED, "Z_PROBE_SLED")
|
||||||
TERN_(Z_PROBE_ALLEN_KEY, "Z_PROBE_ALLEN_KEY")
|
TERN_(Z_PROBE_ALLEN_KEY, "Z_PROBE_ALLEN_KEY")
|
||||||
|
@ -54,6 +54,18 @@ void Babystep::add_mm(const AxisEnum axis, const_float_t mm) {
|
|||||||
add_steps(axis, mm * planner.settings.axis_steps_per_mm[axis]);
|
add_steps(axis, mm * planner.settings.axis_steps_per_mm[axis]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if ENABLED(BD_SENSOR)
|
||||||
|
void Babystep::set_mm(const AxisEnum axis, const_float_t mm) {
|
||||||
|
//if (DISABLED(BABYSTEP_WITHOUT_HOMING) && axes_should_home(_BV(axis))) return;
|
||||||
|
const int16_t distance = mm * planner.settings.axis_steps_per_mm[axis];
|
||||||
|
accum = distance; // Count up babysteps for the UI
|
||||||
|
steps[BS_AXIS_IND(axis)] = distance;
|
||||||
|
TERN_(BABYSTEP_DISPLAY_TOTAL, axis_total[BS_TOTAL_IND(axis)] = distance);
|
||||||
|
TERN_(BABYSTEP_ALWAYS_AVAILABLE, gcode.reset_stepper_timeout());
|
||||||
|
TERN_(INTEGRATED_BABYSTEPPING, if (has_steps()) stepper.initiateBabystepping());
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
void Babystep::add_steps(const AxisEnum axis, const int16_t distance) {
|
void Babystep::add_steps(const AxisEnum axis, const int16_t distance) {
|
||||||
if (DISABLED(BABYSTEP_WITHOUT_HOMING) && axes_should_home(_BV(axis))) return;
|
if (DISABLED(BABYSTEP_WITHOUT_HOMING) && axes_should_home(_BV(axis))) return;
|
||||||
|
|
||||||
|
@ -63,6 +63,10 @@ public:
|
|||||||
static void add_steps(const AxisEnum axis, const int16_t distance);
|
static void add_steps(const AxisEnum axis, const int16_t distance);
|
||||||
static void add_mm(const AxisEnum axis, const_float_t mm);
|
static void add_mm(const AxisEnum axis, const_float_t mm);
|
||||||
|
|
||||||
|
#if ENABLED(BD_SENSOR)
|
||||||
|
static void set_mm(const AxisEnum axis, const_float_t mm);
|
||||||
|
#endif
|
||||||
|
|
||||||
static bool has_steps() {
|
static bool has_steps() {
|
||||||
return steps[BS_AXIS_IND(X_AXIS)] || steps[BS_AXIS_IND(Y_AXIS)] || steps[BS_AXIS_IND(Z_AXIS)];
|
return steps[BS_AXIS_IND(X_AXIS)] || steps[BS_AXIS_IND(Y_AXIS)] || steps[BS_AXIS_IND(Z_AXIS)];
|
||||||
}
|
}
|
||||||
|
195
Marlin/src/feature/bedlevel/bdl/bdl.cpp
Normal file
195
Marlin/src/feature/bedlevel/bdl/bdl.cpp
Normal file
@ -0,0 +1,195 @@
|
|||||||
|
/**
|
||||||
|
* Marlin 3D Printer Firmware
|
||||||
|
* Copyright (c) 2022 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
|
||||||
|
*
|
||||||
|
* Based on Sprinter and grbl.
|
||||||
|
* 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
|
||||||
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "../../../inc/MarlinConfig.h"
|
||||||
|
|
||||||
|
#if ENABLED(BD_SENSOR)
|
||||||
|
|
||||||
|
#include "../../../MarlinCore.h"
|
||||||
|
#include "../../../gcode/gcode.h"
|
||||||
|
#include "../../../module/settings.h"
|
||||||
|
#include "../../../module/motion.h"
|
||||||
|
#include "../../../module/planner.h"
|
||||||
|
#include "../../../module/stepper.h"
|
||||||
|
#include "../../../module/probe.h"
|
||||||
|
#include "../../../module/temperature.h"
|
||||||
|
#include "../../../module/endstops.h"
|
||||||
|
#include "../../babystep.h"
|
||||||
|
|
||||||
|
// I2C software Master library for segment bed heating and bed distance sensor
|
||||||
|
#include <Panda_segmentBed_I2C.h>
|
||||||
|
|
||||||
|
#include "bdl.h"
|
||||||
|
BDS_Leveling bdl;
|
||||||
|
|
||||||
|
//#define DEBUG_OUT_BD
|
||||||
|
|
||||||
|
// M102 S-5 Read raw Calibrate data
|
||||||
|
// M102 S-6 Start Calibrate
|
||||||
|
// M102 S4 Set the adjustable Z height value (e.g., 'M102 S4' means it will do adjusting while the Z height <= 0.4mm , disable with 'M102 S0'.)
|
||||||
|
// M102 S-1 Read sensor information
|
||||||
|
|
||||||
|
#define MAX_BD_HEIGHT 4.0f
|
||||||
|
#define CMD_START_READ_CALIBRATE_DATA 1017
|
||||||
|
#define CMD_END_READ_CALIBRATE_DATA 1018
|
||||||
|
#define CMD_START_CALIBRATE 1019
|
||||||
|
#define CMD_END_CALIBRATE 1021
|
||||||
|
#define CMD_READ_VERSION 1016
|
||||||
|
|
||||||
|
I2C_SegmentBED BD_I2C_SENSOR;
|
||||||
|
|
||||||
|
#define BD_SENSOR_I2C_ADDR 0x3C
|
||||||
|
|
||||||
|
int8_t BDS_Leveling::config_state;
|
||||||
|
uint8_t BDS_Leveling::homing;
|
||||||
|
|
||||||
|
void BDS_Leveling::echo_name() { SERIAL_ECHOPGM("Bed Distance Leveling"); }
|
||||||
|
|
||||||
|
void BDS_Leveling::init(uint8_t _sda, uint8_t _scl, uint16_t delay_s) {
|
||||||
|
int ret = BD_I2C_SENSOR.i2c_init(_sda, _scl, BD_SENSOR_I2C_ADDR, delay_s);
|
||||||
|
if (ret != 1) SERIAL_ECHOLNPGM("BD_I2C_SENSOR Init Fail return code:", ret);
|
||||||
|
config_state = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
float BDS_Leveling::read() {
|
||||||
|
const uint16_t tmp = BD_I2C_SENSOR.BD_i2c_read();
|
||||||
|
float BD_z = NAN;
|
||||||
|
if (BD_I2C_SENSOR.BD_Check_OddEven(tmp) && (tmp & 0x3FF) < 1020)
|
||||||
|
BD_z = (tmp & 0x3FF) / 100.0f;
|
||||||
|
return BD_z;
|
||||||
|
}
|
||||||
|
|
||||||
|
void BDS_Leveling::process() {
|
||||||
|
//if (config_state == 0) return;
|
||||||
|
static millis_t next_check_ms = 0; // starting at T=0
|
||||||
|
static float z_pose = 0.0f;
|
||||||
|
const millis_t ms = millis();
|
||||||
|
if (ELAPSED(ms, next_check_ms)) { // timed out (or first run)
|
||||||
|
next_check_ms = ms + (config_state < 0 ? 1000 : 100); // check at 1Hz or 10Hz
|
||||||
|
|
||||||
|
unsigned short tmp = 0;
|
||||||
|
const float cur_z = planner.get_axis_position_mm(Z_AXIS); //current_position.z
|
||||||
|
static float old_cur_z = cur_z,
|
||||||
|
old_buf_z = current_position.z;
|
||||||
|
|
||||||
|
tmp = BD_I2C_SENSOR.BD_i2c_read();
|
||||||
|
if (BD_I2C_SENSOR.BD_Check_OddEven(tmp) && (tmp & 0x3FF) < 1020) {
|
||||||
|
const float z_sensor = (tmp & 0x3FF) / 100.0f;
|
||||||
|
if (cur_z < 0) config_state = 0;
|
||||||
|
//float abs_z = current_position.z > cur_z ? (current_position.z - cur_z) : (cur_z - current_position.z);
|
||||||
|
if ( cur_z < config_state * 0.1f
|
||||||
|
&& config_state > 0
|
||||||
|
&& old_cur_z == cur_z
|
||||||
|
&& old_buf_z == current_position.z
|
||||||
|
&& z_sensor < (MAX_BD_HEIGHT)
|
||||||
|
) {
|
||||||
|
babystep.set_mm(Z_AXIS, cur_z - z_sensor);
|
||||||
|
#if ENABLED(DEBUG_OUT_BD)
|
||||||
|
SERIAL_ECHOLNPGM("BD:", z_sensor, ", Z:", cur_z, "|", current_position.z);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
babystep.set_mm(Z_AXIS, 0);
|
||||||
|
//if (old_cur_z <= cur_z) Z_DIR_WRITE(!INVERT_Z_DIR);
|
||||||
|
stepper.set_directions();
|
||||||
|
}
|
||||||
|
old_cur_z = cur_z;
|
||||||
|
old_buf_z = current_position.z;
|
||||||
|
endstops.bdp_state_update(z_sensor <= 0.01f);
|
||||||
|
//endstops.update();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
stepper.set_directions();
|
||||||
|
|
||||||
|
#if ENABLED(DEBUG_OUT_BD)
|
||||||
|
SERIAL_ECHOLNPGM("BD:", tmp & 0x3FF, ", Z:", cur_z, "|", current_position.z);
|
||||||
|
if (BD_I2C_SENSOR.BD_Check_OddEven(tmp) == 0) SERIAL_ECHOLNPGM("errorCRC");
|
||||||
|
#endif
|
||||||
|
|
||||||
|
if ((tmp & 0x3FF) > 1020) {
|
||||||
|
BD_I2C_SENSOR.BD_i2c_stop();
|
||||||
|
safe_delay(10);
|
||||||
|
}
|
||||||
|
|
||||||
|
// read raw calibrate data
|
||||||
|
if (config_state == -5) {
|
||||||
|
BD_I2C_SENSOR.BD_i2c_write(CMD_START_READ_CALIBRATE_DATA);
|
||||||
|
safe_delay(1000);
|
||||||
|
|
||||||
|
for (int i = 0; i < MAX_BD_HEIGHT * 10; i++) {
|
||||||
|
tmp = BD_I2C_SENSOR.BD_i2c_read();
|
||||||
|
SERIAL_ECHOLNPGM("Calibrate data:", i, ",", tmp & 0x3FF, ", check:", BD_I2C_SENSOR.BD_Check_OddEven(tmp));
|
||||||
|
safe_delay(500);
|
||||||
|
}
|
||||||
|
config_state = 0;
|
||||||
|
BD_I2C_SENSOR.BD_i2c_write(CMD_END_READ_CALIBRATE_DATA);
|
||||||
|
safe_delay(500);
|
||||||
|
}
|
||||||
|
else if (config_state <= -6) { // Start Calibrate
|
||||||
|
safe_delay(100);
|
||||||
|
if (config_state == -6) {
|
||||||
|
//BD_I2C_SENSOR.BD_i2c_write(1019); // begin calibrate
|
||||||
|
//delay(1000);
|
||||||
|
gcode.stepper_inactive_time = SEC_TO_MS(60 * 5);
|
||||||
|
gcode.process_subcommands_now(F("M17 Z"));
|
||||||
|
gcode.process_subcommands_now(F("G1 Z0.0"));
|
||||||
|
z_pose = 0;
|
||||||
|
safe_delay(1000);
|
||||||
|
BD_I2C_SENSOR.BD_i2c_write(CMD_START_CALIBRATE); // Begin calibrate
|
||||||
|
SERIAL_ECHOLNPGM("Begin calibrate");
|
||||||
|
safe_delay(2000);
|
||||||
|
config_state = -7;
|
||||||
|
}
|
||||||
|
else if (planner.get_axis_position_mm(Z_AXIS) < 10.0f) {
|
||||||
|
if (z_pose >= MAX_BD_HEIGHT) {
|
||||||
|
BD_I2C_SENSOR.BD_i2c_write(CMD_END_CALIBRATE); // End calibrate
|
||||||
|
SERIAL_ECHOLNPGM("End calibrate data");
|
||||||
|
z_pose = 7;
|
||||||
|
config_state = 0;
|
||||||
|
safe_delay(1000);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
float tmp_k = 0;
|
||||||
|
char tmp_1[30];
|
||||||
|
sprintf_P(tmp_1, PSTR("G1 Z%d.%d"), int(z_pose), int(int(z_pose * 10) % 10));
|
||||||
|
gcode.process_subcommands_now(tmp_1);
|
||||||
|
|
||||||
|
SERIAL_ECHO(tmp_1);
|
||||||
|
SERIAL_ECHOLNPGM(" ,Z:", current_position.z);
|
||||||
|
|
||||||
|
while (tmp_k < (z_pose - 0.1f)) {
|
||||||
|
tmp_k = planner.get_axis_position_mm(Z_AXIS);
|
||||||
|
safe_delay(1);
|
||||||
|
}
|
||||||
|
safe_delay(800);
|
||||||
|
tmp = (z_pose + 0.0001f) * 10;
|
||||||
|
BD_I2C_SENSOR.BD_i2c_write(tmp);
|
||||||
|
SERIAL_ECHOLNPGM("w:", tmp, ",Zpose:", z_pose);
|
||||||
|
z_pose += 0.1001f;
|
||||||
|
//queue.enqueue_now_P(PSTR("G90"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // BD_SENSOR
|
36
Marlin/src/feature/bedlevel/bdl/bdl.h
Normal file
36
Marlin/src/feature/bedlevel/bdl/bdl.h
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
/**
|
||||||
|
* Marlin 3D Printer Firmware
|
||||||
|
* Copyright (c) 2022 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
|
||||||
|
*
|
||||||
|
* Based on Sprinter and grbl.
|
||||||
|
* 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
|
||||||
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
class BDS_Leveling {
|
||||||
|
public:
|
||||||
|
static int8_t config_state;
|
||||||
|
static uint8_t homing;
|
||||||
|
static void echo_name();
|
||||||
|
static void init(uint8_t _sda, uint8_t _scl, uint16_t delay_s);
|
||||||
|
static void process();
|
||||||
|
static float read();
|
||||||
|
};
|
||||||
|
|
||||||
|
extern BDS_Leveling bdl;
|
@ -36,6 +36,10 @@
|
|||||||
#include "../../feature/bedlevel/bedlevel.h"
|
#include "../../feature/bedlevel/bedlevel.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if ENABLED(BD_SENSOR)
|
||||||
|
#include "../../feature/bedlevel/bdl/bdl.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
#if ENABLED(SENSORLESS_HOMING)
|
#if ENABLED(SENSORLESS_HOMING)
|
||||||
#include "../../feature/tmc_util.h"
|
#include "../../feature/tmc_util.h"
|
||||||
#endif
|
#endif
|
||||||
@ -202,7 +206,9 @@ void GcodeSuite::G28() {
|
|||||||
DEBUG_SECTION(log_G28, "G28", DEBUGGING(LEVELING));
|
DEBUG_SECTION(log_G28, "G28", DEBUGGING(LEVELING));
|
||||||
if (DEBUGGING(LEVELING)) log_machine_info();
|
if (DEBUGGING(LEVELING)) log_machine_info();
|
||||||
|
|
||||||
/*
|
TERN_(BD_SENSOR, bdl.config_state = 0);
|
||||||
|
|
||||||
|
/**
|
||||||
* Set the laser power to false to stop the planner from processing the current power setting.
|
* Set the laser power to false to stop the planner from processing the current power setting.
|
||||||
*/
|
*/
|
||||||
#if ENABLED(LASER_FEATURE)
|
#if ENABLED(LASER_FEATURE)
|
||||||
|
@ -577,6 +577,10 @@ void GcodeSuite::process_parsed_command(const bool no_ok/*=false*/) {
|
|||||||
case 100: M100(); break; // M100: Free Memory Report
|
case 100: M100(); break; // M100: Free Memory Report
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if ENABLED(BD_SENSOR)
|
||||||
|
case 102: M102(); break; // M102: Configure Bed Distance Sensor
|
||||||
|
#endif
|
||||||
|
|
||||||
#if HAS_EXTRUDERS
|
#if HAS_EXTRUDERS
|
||||||
case 104: M104(); break; // M104: Set hot end temperature
|
case 104: M104(); break; // M104: Set hot end temperature
|
||||||
case 109: M109(); break; // M109: Wait for hotend temperature to reach target
|
case 109: M109(); break; // M109: Wait for hotend temperature to reach target
|
||||||
|
@ -132,6 +132,8 @@
|
|||||||
*
|
*
|
||||||
* M100 - Watch Free Memory (for debugging) (Requires M100_FREE_MEMORY_WATCHER)
|
* M100 - Watch Free Memory (for debugging) (Requires M100_FREE_MEMORY_WATCHER)
|
||||||
*
|
*
|
||||||
|
* M102 - Configure Bed Distance Sensor. (Requires BD_SENSOR)
|
||||||
|
*
|
||||||
* M104 - Set extruder target temp.
|
* M104 - Set extruder target temp.
|
||||||
* M105 - Report current temperatures.
|
* M105 - Report current temperatures.
|
||||||
* M106 - Set print fan speed.
|
* M106 - Set print fan speed.
|
||||||
@ -705,6 +707,11 @@ private:
|
|||||||
static void M100();
|
static void M100();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if ENABLED(BD_SENSOR)
|
||||||
|
static void M102();
|
||||||
|
static void M102_report(const bool forReplay=true);
|
||||||
|
#endif
|
||||||
|
|
||||||
#if HAS_EXTRUDERS
|
#if HAS_EXTRUDERS
|
||||||
static void M104_M109(const bool isM109);
|
static void M104_M109(const bool isM109);
|
||||||
FORCE_INLINE static void M104() { M104_M109(false); }
|
FORCE_INLINE static void M104() { M104_M109(false); }
|
||||||
|
57
Marlin/src/gcode/probe/M102.cpp
Normal file
57
Marlin/src/gcode/probe/M102.cpp
Normal file
@ -0,0 +1,57 @@
|
|||||||
|
/**
|
||||||
|
* Marlin 3D Printer Firmware
|
||||||
|
* Copyright (c) 2022 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
|
||||||
|
*
|
||||||
|
* Based on Sprinter and grbl.
|
||||||
|
* 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
|
||||||
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* M102.cpp - Configure Bed Distance Sensor
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "../../inc/MarlinConfig.h"
|
||||||
|
|
||||||
|
#if ENABLED(BD_SENSOR)
|
||||||
|
|
||||||
|
#include "../gcode.h"
|
||||||
|
#include "../../feature/bedlevel/bdl/bdl.h"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* M102: Configure the Bed Distance Sensor
|
||||||
|
*
|
||||||
|
* M102 S<10ths> : Set adjustable Z height in 10ths of a mm (e.g., 'M102 S4' enables adjusting for Z <= 0.4mm.)
|
||||||
|
* M102 S0 : Disable adjustable Z height.
|
||||||
|
*
|
||||||
|
* Negative S values are commands:
|
||||||
|
* M102 S-1 : Read sensor information
|
||||||
|
* M102 S-5 : Read raw Calibration data
|
||||||
|
* M102 S-6 : Start Calibration
|
||||||
|
*/
|
||||||
|
void GcodeSuite::M102() {
|
||||||
|
if (parser.seenval('S'))
|
||||||
|
bdl.config_state = parser.value_int();
|
||||||
|
else
|
||||||
|
M102_report();
|
||||||
|
}
|
||||||
|
|
||||||
|
void GcodeSuite::M102_report(const bool forReplay/*=true*/) {
|
||||||
|
report_heading(forReplay, F("Bed Distance Sensor"));
|
||||||
|
SERIAL_ECHOLNPGM(" M102 S", bdl.config_state);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // BD_SENSOR
|
@ -1103,7 +1103,7 @@
|
|||||||
#if ANY(TOUCH_MI_PROBE, Z_PROBE_ALLEN_KEY, SOLENOID_PROBE, Z_PROBE_SLED, RACK_AND_PINION_PROBE, SENSORLESS_PROBING, MAGLEV4, MAG_MOUNTED_PROBE)
|
#if ANY(TOUCH_MI_PROBE, Z_PROBE_ALLEN_KEY, SOLENOID_PROBE, Z_PROBE_SLED, RACK_AND_PINION_PROBE, SENSORLESS_PROBING, MAGLEV4, MAG_MOUNTED_PROBE)
|
||||||
#define HAS_STOWABLE_PROBE 1
|
#define HAS_STOWABLE_PROBE 1
|
||||||
#endif
|
#endif
|
||||||
#if ANY(HAS_STOWABLE_PROBE, HAS_Z_SERVO_PROBE, FIX_MOUNTED_PROBE, NOZZLE_AS_PROBE)
|
#if ANY(HAS_STOWABLE_PROBE, HAS_Z_SERVO_PROBE, FIX_MOUNTED_PROBE, BD_SENSOR, NOZZLE_AS_PROBE)
|
||||||
#define HAS_BED_PROBE 1
|
#define HAS_BED_PROBE 1
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -1660,8 +1660,8 @@ static_assert(Y_MAX_LENGTH >= Y_BED_SIZE, "Movement bounds (Y_MIN_POS, Y_MAX_POS
|
|||||||
*/
|
*/
|
||||||
#if 1 < 0 \
|
#if 1 < 0 \
|
||||||
+ (DISABLED(BLTOUCH) && HAS_Z_SERVO_PROBE) \
|
+ (DISABLED(BLTOUCH) && HAS_Z_SERVO_PROBE) \
|
||||||
+ COUNT_ENABLED(PROBE_MANUALLY, BLTOUCH, FIX_MOUNTED_PROBE, NOZZLE_AS_PROBE, TOUCH_MI_PROBE, SOLENOID_PROBE, Z_PROBE_ALLEN_KEY, Z_PROBE_SLED, RACK_AND_PINION_PROBE, SENSORLESS_PROBING, MAGLEV4, MAG_MOUNTED_PROBE)
|
+ COUNT_ENABLED(PROBE_MANUALLY, BLTOUCH, BD_SENSOR, FIX_MOUNTED_PROBE, NOZZLE_AS_PROBE, TOUCH_MI_PROBE, SOLENOID_PROBE, Z_PROBE_ALLEN_KEY, Z_PROBE_SLED, RACK_AND_PINION_PROBE, SENSORLESS_PROBING, MAGLEV4, MAG_MOUNTED_PROBE)
|
||||||
#error "Please enable only one probe option: PROBE_MANUALLY, SENSORLESS_PROBING, BLTOUCH, FIX_MOUNTED_PROBE, NOZZLE_AS_PROBE, TOUCH_MI_PROBE, SOLENOID_PROBE, Z_PROBE_ALLEN_KEY, Z_PROBE_SLED, MAGLEV4, MAG_MOUNTED_PROBE or Z Servo."
|
#error "Please enable only one probe option: PROBE_MANUALLY, SENSORLESS_PROBING, BLTOUCH, BD_SENSOR, FIX_MOUNTED_PROBE, NOZZLE_AS_PROBE, TOUCH_MI_PROBE, SOLENOID_PROBE, Z_PROBE_ALLEN_KEY, Z_PROBE_SLED, MAGLEV4, MAG_MOUNTED_PROBE or Z Servo."
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if HAS_BED_PROBE
|
#if HAS_BED_PROBE
|
||||||
|
@ -773,3 +773,10 @@
|
|||||||
#if MB(BTT_BTT002_V1_0, EINSY_RAMBO) && DISABLED(NO_MK3_FAN_PINS_WARNING)
|
#if MB(BTT_BTT002_V1_0, EINSY_RAMBO) && DISABLED(NO_MK3_FAN_PINS_WARNING)
|
||||||
#warning "Define MK3_FAN_PINS to swap hotend and part cooling fan pins. (Define NO_MK3_FAN_PINS_WARNING to suppress this warning.)"
|
#warning "Define MK3_FAN_PINS to swap hotend and part cooling fan pins. (Define NO_MK3_FAN_PINS_WARNING to suppress this warning.)"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/**
|
||||||
|
* BD Sensor should always include BABYSTEPPING
|
||||||
|
*/
|
||||||
|
#if ENABLED(BD_SENSOR) && DISABLED(BABYSTEPPING)
|
||||||
|
#warning "BABYSTEPPING is recommended with BD_SENSOR."
|
||||||
|
#endif
|
||||||
|
@ -63,6 +63,13 @@ bool Endstops::enabled, Endstops::enabled_globally; // Initialized by settings.l
|
|||||||
volatile Endstops::endstop_mask_t Endstops::hit_state;
|
volatile Endstops::endstop_mask_t Endstops::hit_state;
|
||||||
Endstops::endstop_mask_t Endstops::live_state = 0;
|
Endstops::endstop_mask_t Endstops::live_state = 0;
|
||||||
|
|
||||||
|
#if ENABLED(BD_SENSOR)
|
||||||
|
bool Endstops::bdp_state; // = false
|
||||||
|
#define READ_ENDSTOP(P) ((P == Z_MIN_PIN) ? bdp_state : READ(P))
|
||||||
|
#else
|
||||||
|
#define READ_ENDSTOP(P) READ(P)
|
||||||
|
#endif
|
||||||
|
|
||||||
#if ENDSTOP_NOISE_THRESHOLD
|
#if ENDSTOP_NOISE_THRESHOLD
|
||||||
Endstops::endstop_mask_t Endstops::validated_live_state;
|
Endstops::endstop_mask_t Endstops::validated_live_state;
|
||||||
uint8_t Endstops::endstop_poll_count;
|
uint8_t Endstops::endstop_poll_count;
|
||||||
@ -566,7 +573,7 @@ static void print_es_state(const bool is_hit, FSTR_P const flabel=nullptr) {
|
|||||||
void __O2 Endstops::report_states() {
|
void __O2 Endstops::report_states() {
|
||||||
TERN_(BLTOUCH, bltouch._set_SW_mode());
|
TERN_(BLTOUCH, bltouch._set_SW_mode());
|
||||||
SERIAL_ECHOLNPGM(STR_M119_REPORT);
|
SERIAL_ECHOLNPGM(STR_M119_REPORT);
|
||||||
#define ES_REPORT(S) print_es_state(READ(S##_PIN) != S##_ENDSTOP_INVERTING, F(STR_##S))
|
#define ES_REPORT(S) print_es_state(READ_ENDSTOP(S##_PIN) != S##_ENDSTOP_INVERTING, F(STR_##S))
|
||||||
#if HAS_X_MIN
|
#if HAS_X_MIN
|
||||||
ES_REPORT(X_MIN);
|
ES_REPORT(X_MIN);
|
||||||
#endif
|
#endif
|
||||||
@ -703,7 +710,7 @@ void Endstops::update() {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Macros to update / copy the live_state
|
// Macros to update / copy the live_state
|
||||||
#define UPDATE_ENDSTOP_BIT(AXIS, MINMAX) SET_BIT_TO(live_state, _ENDSTOP(AXIS, MINMAX), (READ(_ENDSTOP_PIN(AXIS, MINMAX)) != _ENDSTOP_INVERTING(AXIS, MINMAX)))
|
#define UPDATE_ENDSTOP_BIT(AXIS, MINMAX) SET_BIT_TO(live_state, _ENDSTOP(AXIS, MINMAX), (READ_ENDSTOP(_ENDSTOP_PIN(AXIS, MINMAX)) != _ENDSTOP_INVERTING(AXIS, MINMAX)))
|
||||||
#define COPY_LIVE_STATE(SRC_BIT, DST_BIT) SET_BIT_TO(live_state, DST_BIT, TEST(live_state, SRC_BIT))
|
#define COPY_LIVE_STATE(SRC_BIT, DST_BIT) SET_BIT_TO(live_state, DST_BIT, TEST(live_state, SRC_BIT))
|
||||||
|
|
||||||
#if ENABLED(G38_PROBE_TARGET) && NONE(CORE_IS_XY, CORE_IS_XZ, MARKFORGED_XY, MARKFORGED_YX)
|
#if ENABLED(G38_PROBE_TARGET) && NONE(CORE_IS_XY, CORE_IS_XZ, MARKFORGED_XY, MARKFORGED_YX)
|
||||||
@ -1434,7 +1441,7 @@ void Endstops::update() {
|
|||||||
static uint8_t local_LED_status = 0;
|
static uint8_t local_LED_status = 0;
|
||||||
uint16_t live_state_local = 0;
|
uint16_t live_state_local = 0;
|
||||||
|
|
||||||
#define ES_GET_STATE(S) if (READ(S##_PIN)) SBI(live_state_local, S)
|
#define ES_GET_STATE(S) if (READ_ENDSTOP(S##_PIN)) SBI(live_state_local, S)
|
||||||
|
|
||||||
#if HAS_X_MIN
|
#if HAS_X_MIN
|
||||||
ES_GET_STATE(X_MIN);
|
ES_GET_STATE(X_MIN);
|
||||||
|
@ -166,6 +166,11 @@ class Endstops {
|
|||||||
*/
|
*/
|
||||||
static void update();
|
static void update();
|
||||||
|
|
||||||
|
#if ENABLED(BD_SENSOR)
|
||||||
|
static bool bdp_state;
|
||||||
|
static void bdp_state_update(const bool z_state) { bdp_state = z_state; }
|
||||||
|
#endif
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get Endstop hit state.
|
* Get Endstop hit state.
|
||||||
*/
|
*/
|
||||||
|
@ -44,6 +44,10 @@
|
|||||||
#include "../feature/bedlevel/bedlevel.h"
|
#include "../feature/bedlevel/bedlevel.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if ENABLED(BD_SENSOR)
|
||||||
|
#include "../feature/bedlevel/bdl/bdl.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
#if ENABLED(DELTA)
|
#if ENABLED(DELTA)
|
||||||
#include "delta.h"
|
#include "delta.h"
|
||||||
#endif
|
#endif
|
||||||
@ -878,6 +882,8 @@ float Probe::probe_at_point(const_float_t rx, const_float_t ry, const ProbePtRai
|
|||||||
// Move the probe to the starting XYZ
|
// Move the probe to the starting XYZ
|
||||||
do_blocking_move_to(npos, feedRate_t(XY_PROBE_FEEDRATE_MM_S));
|
do_blocking_move_to(npos, feedRate_t(XY_PROBE_FEEDRATE_MM_S));
|
||||||
|
|
||||||
|
TERN_(BD_SENSOR, return bdl.read());
|
||||||
|
|
||||||
float measured_z = NAN;
|
float measured_z = NAN;
|
||||||
if (!deploy()) {
|
if (!deploy()) {
|
||||||
measured_z = run_z_probe(sanity_check) + offset.z;
|
measured_z = run_z_probe(sanity_check) + offset.z;
|
||||||
|
@ -97,6 +97,10 @@ Stepper stepper; // Singleton
|
|||||||
#include "../MarlinCore.h"
|
#include "../MarlinCore.h"
|
||||||
#include "../HAL/shared/Delay.h"
|
#include "../HAL/shared/Delay.h"
|
||||||
|
|
||||||
|
#if ENABLED(BD_SENSOR)
|
||||||
|
#include "../feature/bedlevel/bdl/bdl.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
#if ENABLED(INTEGRATED_BABYSTEPPING)
|
#if ENABLED(INTEGRATED_BABYSTEPPING)
|
||||||
#include "../feature/babystep.h"
|
#include "../feature/babystep.h"
|
||||||
#endif
|
#endif
|
||||||
|
@ -981,7 +981,7 @@ void reset_stepper_drivers(); // Called by settings.load / settings.reset
|
|||||||
|
|
||||||
#if HAS_Z_AXIS
|
#if HAS_Z_AXIS
|
||||||
#define ENABLE_AXIS_Z() if (SHOULD_ENABLE(z)) { ENABLE_STEPPER_Z(); ENABLE_STEPPER_Z2(); ENABLE_STEPPER_Z3(); ENABLE_STEPPER_Z4(); AFTER_CHANGE(z, true); }
|
#define ENABLE_AXIS_Z() if (SHOULD_ENABLE(z)) { ENABLE_STEPPER_Z(); ENABLE_STEPPER_Z2(); ENABLE_STEPPER_Z3(); ENABLE_STEPPER_Z4(); AFTER_CHANGE(z, true); }
|
||||||
#define DISABLE_AXIS_Z() if (SHOULD_DISABLE(z)) { DISABLE_STEPPER_Z(); DISABLE_STEPPER_Z2(); DISABLE_STEPPER_Z3(); DISABLE_STEPPER_Z4(); AFTER_CHANGE(z, false); set_axis_untrusted(Z_AXIS); Z_RESET(); }
|
#define DISABLE_AXIS_Z() if (SHOULD_DISABLE(z)) { DISABLE_STEPPER_Z(); DISABLE_STEPPER_Z2(); DISABLE_STEPPER_Z3(); DISABLE_STEPPER_Z4(); AFTER_CHANGE(z, false); set_axis_untrusted(Z_AXIS); Z_RESET(); TERN_(BD_SENSOR, bdl.config_state = 0); }
|
||||||
#else
|
#else
|
||||||
#define ENABLE_AXIS_Z() NOOP
|
#define ENABLE_AXIS_Z() NOOP
|
||||||
#define DISABLE_AXIS_Z() NOOP
|
#define DISABLE_AXIS_Z() NOOP
|
||||||
|
@ -38,6 +38,12 @@
|
|||||||
#define MARLIN_EEPROM_SIZE EEPROM_PAGE_SIZE // 2K
|
#define MARLIN_EEPROM_SIZE EEPROM_PAGE_SIZE // 2K
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if ENABLED(BD_SENSOR)
|
||||||
|
#define I2C_BD_SDA_PIN PC6
|
||||||
|
#define I2C_BD_SCL_PIN PB2
|
||||||
|
#define I2C_BD_DELAY 10 // (seconds)
|
||||||
|
#endif
|
||||||
|
|
||||||
//
|
//
|
||||||
// Servos
|
// Servos
|
||||||
//
|
//
|
||||||
|
19
buildroot/tests/PANDA_PI_V29
Executable file
19
buildroot/tests/PANDA_PI_V29
Executable file
@ -0,0 +1,19 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
#
|
||||||
|
# Build tests for PANDA_PI_V29
|
||||||
|
#
|
||||||
|
|
||||||
|
# exit on first failure
|
||||||
|
set -e
|
||||||
|
|
||||||
|
#
|
||||||
|
# Build with the default configurations
|
||||||
|
#
|
||||||
|
restore_configs
|
||||||
|
opt_set MOTHERBOARD BOARD_PANDA_PI_V29 SERIAL_PORT -1 \
|
||||||
|
Z_CLEARANCE_DEPLOY_PROBE 0 Z_CLEARANCE_BETWEEN_PROBES 1 Z_CLEARANCE_MULTI_PROBE 1
|
||||||
|
opt_enable BD_SENSOR AUTO_BED_LEVELING_BILINEAR Z_SAFE_HOMING BABYSTEPPING
|
||||||
|
exec_test $1 $2 "Panda Pi V29 | BD Sensor | ABL-B" "$3"
|
||||||
|
|
||||||
|
# clean up
|
||||||
|
restore_configs
|
@ -99,6 +99,8 @@ HAS_MCP3426_ADC = src_filter=+<src/feature/adc> +<src/gco
|
|||||||
AUTO_BED_LEVELING_BILINEAR = src_filter=+<src/feature/bedlevel/abl>
|
AUTO_BED_LEVELING_BILINEAR = src_filter=+<src/feature/bedlevel/abl>
|
||||||
AUTO_BED_LEVELING_(3POINT|(BI)?LINEAR) = src_filter=+<src/gcode/bedlevel/abl>
|
AUTO_BED_LEVELING_(3POINT|(BI)?LINEAR) = src_filter=+<src/gcode/bedlevel/abl>
|
||||||
X_AXIS_TWIST_COMPENSATION = src_filter=+<src/feature/x_twist.cpp> +<src/lcd/menu/menu_x_twist.cpp> +<src/gcode/probe/M423.cpp>
|
X_AXIS_TWIST_COMPENSATION = src_filter=+<src/feature/x_twist.cpp> +<src/lcd/menu/menu_x_twist.cpp> +<src/gcode/probe/M423.cpp>
|
||||||
|
BD_SENSOR = markyue/Panda_SoftMasterI2C
|
||||||
|
src_filter=+<src/feature/bedlevel/bdl> +<src/gcode/probe/M102.cpp>
|
||||||
MESH_BED_LEVELING = src_filter=+<src/feature/bedlevel/mbl> +<src/gcode/bedlevel/mbl>
|
MESH_BED_LEVELING = src_filter=+<src/feature/bedlevel/mbl> +<src/gcode/bedlevel/mbl>
|
||||||
AUTO_BED_LEVELING_UBL = src_filter=+<src/feature/bedlevel/ubl> +<src/gcode/bedlevel/ubl>
|
AUTO_BED_LEVELING_UBL = src_filter=+<src/feature/bedlevel/ubl> +<src/gcode/bedlevel/ubl>
|
||||||
UBL_HILBERT_CURVE = src_filter=+<src/feature/bedlevel/hilbert_curve.cpp>
|
UBL_HILBERT_CURVE = src_filter=+<src/feature/bedlevel/hilbert_curve.cpp>
|
||||||
|
@ -83,7 +83,8 @@ build_flags = ${common_STM32F103RC_variant.build_flags}
|
|||||||
-DTIMER_SERVO=TIM1
|
-DTIMER_SERVO=TIM1
|
||||||
board_build.offset = 0x5000
|
board_build.offset = 0x5000
|
||||||
board_upload.offset_address = 0x08005000
|
board_upload.offset_address = 0x08005000
|
||||||
|
lib_deps =
|
||||||
|
markyue/Panda_SoftMasterI2C@1.0.3
|
||||||
#
|
#
|
||||||
# MKS Robin (STM32F103ZET6)
|
# MKS Robin (STM32F103ZET6)
|
||||||
# Uses HAL STM32 to support Marlin UI for TFT screen with optional touch panel
|
# Uses HAL STM32 to support Marlin UI for TFT screen with optional touch panel
|
||||||
|
@ -103,6 +103,7 @@ default_src_filter = +<src/*> -<src/config> -<src/HAL> +<src/HAL/shared> -<src/t
|
|||||||
-<src/feature/backlash.cpp>
|
-<src/feature/backlash.cpp>
|
||||||
-<src/feature/baricuda.cpp> -<src/gcode/feature/baricuda>
|
-<src/feature/baricuda.cpp> -<src/gcode/feature/baricuda>
|
||||||
-<src/feature/bedlevel/abl> -<src/gcode/bedlevel/abl>
|
-<src/feature/bedlevel/abl> -<src/gcode/bedlevel/abl>
|
||||||
|
-<src/feature/bedlevel/bdl> -<src/gcode/probe/M102.cpp>
|
||||||
-<src/feature/bedlevel/mbl> -<src/gcode/bedlevel/mbl>
|
-<src/feature/bedlevel/mbl> -<src/gcode/bedlevel/mbl>
|
||||||
-<src/feature/bedlevel/ubl> -<src/gcode/bedlevel/ubl>
|
-<src/feature/bedlevel/ubl> -<src/gcode/bedlevel/ubl>
|
||||||
-<src/feature/bedlevel/hilbert_curve.cpp>
|
-<src/feature/bedlevel/hilbert_curve.cpp>
|
||||||
|
Loading…
Reference in New Issue
Block a user