Browse Source

✨ Bed Distance Sensor (#24554)

Mark 1 year ago
parent
commit
83320f1052
No account linked to committer's email address

+ 1
- 0
.github/workflows/test-builds.yml View File

@@ -45,6 +45,7 @@ jobs:
45 45
         - teensy35
46 46
         - teensy41
47 47
         - SAMD51_grandcentral_m4
48
+        - PANDA_PI_V29
48 49
 
49 50
         # Extended AVR Environments
50 51
 

+ 9
- 0
Marlin/Configuration.h View File

@@ -1887,6 +1887,15 @@
1887 1887
 #endif
1888 1888
 
1889 1889
 /**
1890
+ * Bed Distance Sensor
1891
+ *
1892
+ * Measures the distance from bed to nozzle with accuracy of 0.01mm.
1893
+ * For information about this sensor https://github.com/markniu/Bed_Distance_sensor
1894
+ * Uses I2C port, so it requires I2C library markyue/Panda_SoftMasterI2C.
1895
+ */
1896
+//#define BD_SENSOR
1897
+
1898
+/**
1890 1899
  * Enable detailed logging of G28, G29, M48, etc.
1891 1900
  * Turn on with the command 'M111 S32'.
1892 1901
  * NOTE: Requires a lot of PROGMEM!

+ 11
- 0
Marlin/src/MarlinCore.cpp View File

@@ -121,6 +121,10 @@
121 121
   #include "feature/bltouch.h"
122 122
 #endif
123 123
 
124
+#if ENABLED(BD_SENSOR)
125
+  #include "feature/bedlevel/bdl/bdl.h"
126
+#endif
127
+
124 128
 #if ENABLED(POLL_JOG)
125 129
   #include "feature/joystick.h"
126 130
 #endif
@@ -779,6 +783,9 @@ void idle(bool no_stepper_sleep/*=false*/) {
779 783
     if (++idle_depth > 5) SERIAL_ECHOLNPGM("idle() call depth: ", idle_depth);
780 784
   #endif
781 785
 
786
+  // Bed Distance Sensor task
787
+  TERN_(BD_SENSOR, bdl.process());
788
+
782 789
   // Core Marlin activities
783 790
   manage_inactivity(no_stepper_sleep);
784 791
 
@@ -1632,6 +1639,10 @@ void setup() {
1632 1639
     SETUP_RUN(test_tmc_connection());
1633 1640
   #endif
1634 1641
 
1642
+  #if ENABLED(BD_SENSOR)
1643
+    SETUP_RUN(bdl.init(I2C_BD_SDA_PIN, I2C_BD_SCL_PIN, I2C_BD_DELAY));
1644
+  #endif
1645
+
1635 1646
   marlin_state = MF_RUNNING;
1636 1647
 
1637 1648
   SETUP_LOG("setup() completed.");

+ 1
- 0
Marlin/src/core/utility.cpp View File

@@ -70,6 +70,7 @@ void safe_delay(millis_t ms) {
70 70
       TERN_(NOZZLE_AS_PROBE, "NOZZLE_AS_PROBE")
71 71
       TERN_(FIX_MOUNTED_PROBE, "FIX_MOUNTED_PROBE")
72 72
       TERN_(HAS_Z_SERVO_PROBE, TERN(BLTOUCH, "BLTOUCH", "SERVO PROBE"))
73
+      TERN_(BD_SENSOR, "BD_SENSOR")
73 74
       TERN_(TOUCH_MI_PROBE, "TOUCH_MI_PROBE")
74 75
       TERN_(Z_PROBE_SLED, "Z_PROBE_SLED")
75 76
       TERN_(Z_PROBE_ALLEN_KEY, "Z_PROBE_ALLEN_KEY")

+ 12
- 0
Marlin/src/feature/babystep.cpp View File

@@ -54,6 +54,18 @@ void Babystep::add_mm(const AxisEnum axis, const_float_t mm) {
54 54
   add_steps(axis, mm * planner.settings.axis_steps_per_mm[axis]);
55 55
 }
56 56
 
57
+#if ENABLED(BD_SENSOR)
58
+  void Babystep::set_mm(const AxisEnum axis, const_float_t mm) {
59
+    //if (DISABLED(BABYSTEP_WITHOUT_HOMING) && axes_should_home(_BV(axis))) return;
60
+    const int16_t distance = mm * planner.settings.axis_steps_per_mm[axis];
61
+    accum = distance; // Count up babysteps for the UI
62
+    steps[BS_AXIS_IND(axis)] = distance;
63
+    TERN_(BABYSTEP_DISPLAY_TOTAL, axis_total[BS_TOTAL_IND(axis)] = distance);
64
+    TERN_(BABYSTEP_ALWAYS_AVAILABLE, gcode.reset_stepper_timeout());
65
+    TERN_(INTEGRATED_BABYSTEPPING, if (has_steps()) stepper.initiateBabystepping());
66
+  }
67
+#endif
68
+
57 69
 void Babystep::add_steps(const AxisEnum axis, const int16_t distance) {
58 70
   if (DISABLED(BABYSTEP_WITHOUT_HOMING) && axes_should_home(_BV(axis))) return;
59 71
 

+ 4
- 0
Marlin/src/feature/babystep.h View File

@@ -63,6 +63,10 @@ public:
63 63
   static void add_steps(const AxisEnum axis, const int16_t distance);
64 64
   static void add_mm(const AxisEnum axis, const_float_t mm);
65 65
 
66
+  #if ENABLED(BD_SENSOR)
67
+    static void set_mm(const AxisEnum axis, const_float_t mm);
68
+  #endif
69
+
66 70
   static bool has_steps() {
67 71
     return steps[BS_AXIS_IND(X_AXIS)] || steps[BS_AXIS_IND(Y_AXIS)] || steps[BS_AXIS_IND(Z_AXIS)];
68 72
   }

+ 195
- 0
Marlin/src/feature/bedlevel/bdl/bdl.cpp View File

@@ -0,0 +1,195 @@
1
+/**
2
+ * Marlin 3D Printer Firmware
3
+ * Copyright (c) 2022 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 <https://www.gnu.org/licenses/>.
20
+ *
21
+ */
22
+
23
+#include "../../../inc/MarlinConfig.h"
24
+
25
+#if ENABLED(BD_SENSOR)
26
+
27
+#include "../../../MarlinCore.h"
28
+#include "../../../gcode/gcode.h"
29
+#include "../../../module/settings.h"
30
+#include "../../../module/motion.h"
31
+#include "../../../module/planner.h"
32
+#include "../../../module/stepper.h"
33
+#include "../../../module/probe.h"
34
+#include "../../../module/temperature.h"
35
+#include "../../../module/endstops.h"
36
+#include "../../babystep.h"
37
+
38
+// I2C software Master library for segment bed heating and bed distance sensor
39
+#include <Panda_segmentBed_I2C.h>
40
+
41
+#include "bdl.h"
42
+BDS_Leveling bdl;
43
+
44
+//#define DEBUG_OUT_BD
45
+
46
+// M102 S-5   Read raw Calibrate data
47
+// M102 S-6   Start Calibrate
48
+// 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'.)
49
+// M102 S-1   Read sensor information
50
+
51
+#define MAX_BD_HEIGHT                 4.0f
52
+#define CMD_START_READ_CALIBRATE_DATA 1017
53
+#define CMD_END_READ_CALIBRATE_DATA   1018
54
+#define CMD_START_CALIBRATE           1019
55
+#define CMD_END_CALIBRATE             1021
56
+#define CMD_READ_VERSION  1016
57
+
58
+I2C_SegmentBED BD_I2C_SENSOR;
59
+
60
+#define BD_SENSOR_I2C_ADDR            0x3C
61
+
62
+int8_t BDS_Leveling::config_state;
63
+uint8_t BDS_Leveling::homing;
64
+
65
+void BDS_Leveling::echo_name() { SERIAL_ECHOPGM("Bed Distance Leveling"); }
66
+
67
+void BDS_Leveling::init(uint8_t _sda, uint8_t _scl, uint16_t delay_s) {
68
+  int ret = BD_I2C_SENSOR.i2c_init(_sda, _scl, BD_SENSOR_I2C_ADDR, delay_s);
69
+  if (ret != 1) SERIAL_ECHOLNPGM("BD_I2C_SENSOR Init Fail return code:", ret);
70
+  config_state = 0;
71
+}
72
+
73
+float BDS_Leveling::read() {
74
+  const uint16_t tmp = BD_I2C_SENSOR.BD_i2c_read();
75
+  float BD_z = NAN;
76
+  if (BD_I2C_SENSOR.BD_Check_OddEven(tmp) && (tmp & 0x3FF) < 1020)
77
+    BD_z = (tmp & 0x3FF) / 100.0f;
78
+  return BD_z;
79
+}
80
+
81
+void BDS_Leveling::process() {
82
+ //if (config_state == 0) return;
83
+ static millis_t next_check_ms = 0; // starting at T=0
84
+ static float z_pose = 0.0f;
85
+ const millis_t ms = millis();
86
+ if (ELAPSED(ms, next_check_ms)) { // timed out (or first run)
87
+    next_check_ms = ms + (config_state < 0 ? 1000 : 100);   // check at 1Hz or 10Hz
88
+
89
+    unsigned short tmp = 0;
90
+    const float cur_z = planner.get_axis_position_mm(Z_AXIS); //current_position.z
91
+    static float old_cur_z = cur_z,
92
+                 old_buf_z = current_position.z;
93
+
94
+    tmp = BD_I2C_SENSOR.BD_i2c_read();
95
+    if (BD_I2C_SENSOR.BD_Check_OddEven(tmp) && (tmp & 0x3FF) < 1020) {
96
+      const float z_sensor = (tmp & 0x3FF) / 100.0f;
97
+      if (cur_z < 0) config_state = 0;
98
+      //float abs_z = current_position.z > cur_z ? (current_position.z - cur_z) : (cur_z - current_position.z);
99
+      if ( cur_z < config_state * 0.1f
100
+        && config_state > 0
101
+        && old_cur_z == cur_z
102
+        && old_buf_z == current_position.z
103
+        && z_sensor < (MAX_BD_HEIGHT)
104
+      ) {
105
+        babystep.set_mm(Z_AXIS, cur_z - z_sensor);
106
+        #if ENABLED(DEBUG_OUT_BD)
107
+          SERIAL_ECHOLNPGM("BD:", z_sensor, ", Z:", cur_z, "|", current_position.z);
108
+        #endif
109
+      }
110
+      else {
111
+        babystep.set_mm(Z_AXIS, 0);
112
+        //if (old_cur_z <= cur_z) Z_DIR_WRITE(!INVERT_Z_DIR);
113
+        stepper.set_directions();
114
+      }
115
+      old_cur_z = cur_z;
116
+      old_buf_z = current_position.z;
117
+      endstops.bdp_state_update(z_sensor <= 0.01f);
118
+      //endstops.update();
119
+    }
120
+    else
121
+      stepper.set_directions();
122
+
123
+    #if ENABLED(DEBUG_OUT_BD)
124
+      SERIAL_ECHOLNPGM("BD:", tmp & 0x3FF, ", Z:", cur_z, "|", current_position.z);
125
+      if (BD_I2C_SENSOR.BD_Check_OddEven(tmp) == 0) SERIAL_ECHOLNPGM("errorCRC");
126
+    #endif
127
+
128
+    if ((tmp & 0x3FF) > 1020) {
129
+      BD_I2C_SENSOR.BD_i2c_stop();
130
+      safe_delay(10);
131
+    }
132
+
133
+    // read raw calibrate data
134
+    if (config_state == -5) {
135
+      BD_I2C_SENSOR.BD_i2c_write(CMD_START_READ_CALIBRATE_DATA);
136
+      safe_delay(1000);
137
+
138
+      for (int i = 0; i < MAX_BD_HEIGHT * 10; i++) {
139
+        tmp = BD_I2C_SENSOR.BD_i2c_read();
140
+        SERIAL_ECHOLNPGM("Calibrate data:", i, ",", tmp & 0x3FF, ", check:", BD_I2C_SENSOR.BD_Check_OddEven(tmp));
141
+        safe_delay(500);
142
+      }
143
+      config_state = 0;
144
+      BD_I2C_SENSOR.BD_i2c_write(CMD_END_READ_CALIBRATE_DATA);
145
+      safe_delay(500);
146
+    }
147
+    else if (config_state <= -6) {   // Start Calibrate
148
+      safe_delay(100);
149
+      if (config_state == -6) {
150
+        //BD_I2C_SENSOR.BD_i2c_write(1019); // begin calibrate
151
+        //delay(1000);
152
+        gcode.stepper_inactive_time = SEC_TO_MS(60 * 5);
153
+        gcode.process_subcommands_now(F("M17 Z"));
154
+        gcode.process_subcommands_now(F("G1 Z0.0"));
155
+        z_pose = 0;
156
+        safe_delay(1000);
157
+        BD_I2C_SENSOR.BD_i2c_write(CMD_START_CALIBRATE); // Begin calibrate
158
+        SERIAL_ECHOLNPGM("Begin calibrate");
159
+        safe_delay(2000);
160
+        config_state = -7;
161
+      }
162
+      else if (planner.get_axis_position_mm(Z_AXIS) < 10.0f) {
163
+        if (z_pose >= MAX_BD_HEIGHT) {
164
+          BD_I2C_SENSOR.BD_i2c_write(CMD_END_CALIBRATE); // End calibrate
165
+          SERIAL_ECHOLNPGM("End calibrate data");
166
+          z_pose = 7;
167
+          config_state = 0;
168
+          safe_delay(1000);
169
+        }
170
+        else {
171
+          float tmp_k = 0;
172
+          char tmp_1[30];
173
+          sprintf_P(tmp_1, PSTR("G1 Z%d.%d"), int(z_pose), int(int(z_pose * 10) % 10));
174
+          gcode.process_subcommands_now(tmp_1);
175
+
176
+          SERIAL_ECHO(tmp_1);
177
+          SERIAL_ECHOLNPGM(" ,Z:", current_position.z);
178
+
179
+          while (tmp_k < (z_pose - 0.1f)) {
180
+            tmp_k = planner.get_axis_position_mm(Z_AXIS);
181
+            safe_delay(1);
182
+          }
183
+          safe_delay(800);
184
+          tmp = (z_pose + 0.0001f) * 10;
185
+          BD_I2C_SENSOR.BD_i2c_write(tmp);
186
+          SERIAL_ECHOLNPGM("w:", tmp, ",Zpose:", z_pose);
187
+          z_pose += 0.1001f;
188
+          //queue.enqueue_now_P(PSTR("G90"));
189
+        }
190
+      }
191
+    }
192
+  }
193
+}
194
+
195
+#endif // BD_SENSOR

+ 36
- 0
Marlin/src/feature/bedlevel/bdl/bdl.h View File

@@ -0,0 +1,36 @@
1
+/**
2
+ * Marlin 3D Printer Firmware
3
+ * Copyright (c) 2022 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 <https://www.gnu.org/licenses/>.
20
+ *
21
+ */
22
+#pragma once
23
+
24
+#include <stdint.h>
25
+
26
+class BDS_Leveling {
27
+public:
28
+  static int8_t config_state;
29
+  static uint8_t homing;
30
+  static void echo_name();
31
+  static void init(uint8_t _sda, uint8_t _scl, uint16_t delay_s);
32
+  static void process();
33
+  static float read();
34
+};
35
+
36
+extern BDS_Leveling bdl;

+ 7
- 1
Marlin/src/gcode/calibrate/G28.cpp View File

@@ -36,6 +36,10 @@
36 36
   #include "../../feature/bedlevel/bedlevel.h"
37 37
 #endif
38 38
 
39
+#if ENABLED(BD_SENSOR)
40
+  #include "../../feature/bedlevel/bdl/bdl.h"
41
+#endif
42
+
39 43
 #if ENABLED(SENSORLESS_HOMING)
40 44
   #include "../../feature/tmc_util.h"
41 45
 #endif
@@ -202,7 +206,9 @@ void GcodeSuite::G28() {
202 206
   DEBUG_SECTION(log_G28, "G28", DEBUGGING(LEVELING));
203 207
   if (DEBUGGING(LEVELING)) log_machine_info();
204 208
 
205
-  /*
209
+  TERN_(BD_SENSOR, bdl.config_state = 0);
210
+
211
+  /**
206 212
    * Set the laser power to false to stop the planner from processing the current power setting.
207 213
    */
208 214
   #if ENABLED(LASER_FEATURE)

+ 4
- 0
Marlin/src/gcode/gcode.cpp View File

@@ -577,6 +577,10 @@ void GcodeSuite::process_parsed_command(const bool no_ok/*=false*/) {
577 577
         case 100: M100(); break;                                  // M100: Free Memory Report
578 578
       #endif
579 579
 
580
+      #if ENABLED(BD_SENSOR)
581
+        case 102: M102(); break;                                  // M102: Configure Bed Distance Sensor
582
+      #endif
583
+
580 584
       #if HAS_EXTRUDERS
581 585
         case 104: M104(); break;                                  // M104: Set hot end temperature
582 586
         case 109: M109(); break;                                  // M109: Wait for hotend temperature to reach target

+ 7
- 0
Marlin/src/gcode/gcode.h View File

@@ -132,6 +132,8 @@
132 132
  *
133 133
  * M100 - Watch Free Memory (for debugging) (Requires M100_FREE_MEMORY_WATCHER)
134 134
  *
135
+ * M102 - Configure Bed Distance Sensor. (Requires BD_SENSOR)
136
+ *
135 137
  * M104 - Set extruder target temp.
136 138
  * M105 - Report current temperatures.
137 139
  * M106 - Set print fan speed.
@@ -705,6 +707,11 @@ private:
705 707
     static void M100();
706 708
   #endif
707 709
 
710
+  #if ENABLED(BD_SENSOR)
711
+    static void M102();
712
+    static void M102_report(const bool forReplay=true);
713
+  #endif
714
+
708 715
   #if HAS_EXTRUDERS
709 716
     static void M104_M109(const bool isM109);
710 717
     FORCE_INLINE static void M104() { M104_M109(false); }

+ 57
- 0
Marlin/src/gcode/probe/M102.cpp View File

@@ -0,0 +1,57 @@
1
+/**
2
+ * Marlin 3D Printer Firmware
3
+ * Copyright (c) 2022 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 <https://www.gnu.org/licenses/>.
20
+ *
21
+ */
22
+
23
+/**
24
+ * M102.cpp - Configure Bed Distance Sensor
25
+ */
26
+
27
+#include "../../inc/MarlinConfig.h"
28
+
29
+#if ENABLED(BD_SENSOR)
30
+
31
+#include "../gcode.h"
32
+#include "../../feature/bedlevel/bdl/bdl.h"
33
+
34
+/**
35
+ * M102: Configure the Bed Distance Sensor
36
+ *
37
+ *   M102 S<10ths> : Set adjustable Z height in 10ths of a mm (e.g., 'M102 S4' enables adjusting for Z <= 0.4mm.)
38
+ *   M102 S0       : Disable adjustable Z height.
39
+ *
40
+ * Negative S values are commands:
41
+ *   M102 S-1       : Read sensor information
42
+ *   M102 S-5       : Read raw Calibration data
43
+ *   M102 S-6       : Start Calibration
44
+ */
45
+void GcodeSuite::M102() {
46
+  if (parser.seenval('S'))
47
+    bdl.config_state = parser.value_int();
48
+  else
49
+    M102_report();
50
+}
51
+
52
+void GcodeSuite::M102_report(const bool forReplay/*=true*/) {
53
+  report_heading(forReplay, F("Bed Distance Sensor"));
54
+  SERIAL_ECHOLNPGM("  M102 S", bdl.config_state);
55
+}
56
+
57
+#endif // BD_SENSOR

+ 1
- 1
Marlin/src/inc/Conditionals_LCD.h View File

@@ -1103,7 +1103,7 @@
1103 1103
 #if ANY(TOUCH_MI_PROBE, Z_PROBE_ALLEN_KEY, SOLENOID_PROBE, Z_PROBE_SLED, RACK_AND_PINION_PROBE, SENSORLESS_PROBING, MAGLEV4, MAG_MOUNTED_PROBE)
1104 1104
   #define HAS_STOWABLE_PROBE 1
1105 1105
 #endif
1106
-#if ANY(HAS_STOWABLE_PROBE, HAS_Z_SERVO_PROBE, FIX_MOUNTED_PROBE, NOZZLE_AS_PROBE)
1106
+#if ANY(HAS_STOWABLE_PROBE, HAS_Z_SERVO_PROBE, FIX_MOUNTED_PROBE, BD_SENSOR, NOZZLE_AS_PROBE)
1107 1107
   #define HAS_BED_PROBE 1
1108 1108
 #endif
1109 1109
 

+ 2
- 2
Marlin/src/inc/SanityCheck.h View File

@@ -1660,8 +1660,8 @@ static_assert(Y_MAX_LENGTH >= Y_BED_SIZE, "Movement bounds (Y_MIN_POS, Y_MAX_POS
1660 1660
  */
1661 1661
 #if 1 < 0 \
1662 1662
   + (DISABLED(BLTOUCH) && HAS_Z_SERVO_PROBE) \
1663
-  + 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)
1664
-  #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."
1663
+  + 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)
1664
+  #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."
1665 1665
 #endif
1666 1666
 
1667 1667
 #if HAS_BED_PROBE

+ 7
- 0
Marlin/src/inc/Warnings.cpp View File

@@ -773,3 +773,10 @@
773 773
 #if MB(BTT_BTT002_V1_0, EINSY_RAMBO) && DISABLED(NO_MK3_FAN_PINS_WARNING)
774 774
   #warning "Define MK3_FAN_PINS to swap hotend and part cooling fan pins. (Define NO_MK3_FAN_PINS_WARNING to suppress this warning.)"
775 775
 #endif
776
+
777
+/**
778
+ * BD Sensor should always include BABYSTEPPING
779
+ */
780
+#if ENABLED(BD_SENSOR) && DISABLED(BABYSTEPPING)
781
+  #warning "BABYSTEPPING is recommended with BD_SENSOR."
782
+#endif

+ 10
- 3
Marlin/src/module/endstops.cpp View File

@@ -63,6 +63,13 @@ bool Endstops::enabled, Endstops::enabled_globally; // Initialized by settings.l
63 63
 volatile Endstops::endstop_mask_t Endstops::hit_state;
64 64
 Endstops::endstop_mask_t Endstops::live_state = 0;
65 65
 
66
+#if ENABLED(BD_SENSOR)
67
+  bool Endstops::bdp_state; // = false
68
+  #define READ_ENDSTOP(P) ((P == Z_MIN_PIN) ? bdp_state : READ(P))
69
+#else
70
+  #define READ_ENDSTOP(P) READ(P)
71
+#endif
72
+
66 73
 #if ENDSTOP_NOISE_THRESHOLD
67 74
   Endstops::endstop_mask_t Endstops::validated_live_state;
68 75
   uint8_t Endstops::endstop_poll_count;
@@ -566,7 +573,7 @@ static void print_es_state(const bool is_hit, FSTR_P const flabel=nullptr) {
566 573
 void __O2 Endstops::report_states() {
567 574
   TERN_(BLTOUCH, bltouch._set_SW_mode());
568 575
   SERIAL_ECHOLNPGM(STR_M119_REPORT);
569
-  #define ES_REPORT(S) print_es_state(READ(S##_PIN) != S##_ENDSTOP_INVERTING, F(STR_##S))
576
+  #define ES_REPORT(S) print_es_state(READ_ENDSTOP(S##_PIN) != S##_ENDSTOP_INVERTING, F(STR_##S))
570 577
   #if HAS_X_MIN
571 578
     ES_REPORT(X_MIN);
572 579
   #endif
@@ -703,7 +710,7 @@ void Endstops::update() {
703 710
   #endif
704 711
 
705 712
   // Macros to update / copy the live_state
706
-  #define UPDATE_ENDSTOP_BIT(AXIS, MINMAX) SET_BIT_TO(live_state, _ENDSTOP(AXIS, MINMAX), (READ(_ENDSTOP_PIN(AXIS, MINMAX)) != _ENDSTOP_INVERTING(AXIS, MINMAX)))
713
+  #define UPDATE_ENDSTOP_BIT(AXIS, MINMAX) SET_BIT_TO(live_state, _ENDSTOP(AXIS, MINMAX), (READ_ENDSTOP(_ENDSTOP_PIN(AXIS, MINMAX)) != _ENDSTOP_INVERTING(AXIS, MINMAX)))
707 714
   #define COPY_LIVE_STATE(SRC_BIT, DST_BIT) SET_BIT_TO(live_state, DST_BIT, TEST(live_state, SRC_BIT))
708 715
 
709 716
   #if ENABLED(G38_PROBE_TARGET) && NONE(CORE_IS_XY, CORE_IS_XZ, MARKFORGED_XY, MARKFORGED_YX)
@@ -1434,7 +1441,7 @@ void Endstops::update() {
1434 1441
     static uint8_t local_LED_status = 0;
1435 1442
     uint16_t live_state_local = 0;
1436 1443
 
1437
-    #define ES_GET_STATE(S) if (READ(S##_PIN)) SBI(live_state_local, S)
1444
+    #define ES_GET_STATE(S) if (READ_ENDSTOP(S##_PIN)) SBI(live_state_local, S)
1438 1445
 
1439 1446
     #if HAS_X_MIN
1440 1447
       ES_GET_STATE(X_MIN);

+ 5
- 0
Marlin/src/module/endstops.h View File

@@ -166,6 +166,11 @@ class Endstops {
166 166
      */
167 167
     static void update();
168 168
 
169
+    #if ENABLED(BD_SENSOR)
170
+      static bool bdp_state;
171
+      static void bdp_state_update(const bool z_state) { bdp_state = z_state; }
172
+    #endif
173
+
169 174
     /**
170 175
      * Get Endstop hit state.
171 176
      */

+ 6
- 0
Marlin/src/module/probe.cpp View File

@@ -44,6 +44,10 @@
44 44
   #include "../feature/bedlevel/bedlevel.h"
45 45
 #endif
46 46
 
47
+#if ENABLED(BD_SENSOR)
48
+  #include "../feature/bedlevel/bdl/bdl.h"
49
+#endif
50
+
47 51
 #if ENABLED(DELTA)
48 52
   #include "delta.h"
49 53
 #endif
@@ -878,6 +882,8 @@ float Probe::probe_at_point(const_float_t rx, const_float_t ry, const ProbePtRai
878 882
   // Move the probe to the starting XYZ
879 883
   do_blocking_move_to(npos, feedRate_t(XY_PROBE_FEEDRATE_MM_S));
880 884
 
885
+  TERN_(BD_SENSOR, return bdl.read());
886
+
881 887
   float measured_z = NAN;
882 888
   if (!deploy()) {
883 889
     measured_z = run_z_probe(sanity_check) + offset.z;

+ 4
- 0
Marlin/src/module/stepper.cpp View File

@@ -97,6 +97,10 @@ Stepper stepper; // Singleton
97 97
 #include "../MarlinCore.h"
98 98
 #include "../HAL/shared/Delay.h"
99 99
 
100
+#if ENABLED(BD_SENSOR)
101
+  #include "../feature/bedlevel/bdl/bdl.h"
102
+#endif
103
+
100 104
 #if ENABLED(INTEGRATED_BABYSTEPPING)
101 105
   #include "../feature/babystep.h"
102 106
 #endif

+ 1
- 1
Marlin/src/module/stepper/indirection.h View File

@@ -981,7 +981,7 @@ void reset_stepper_drivers();    // Called by settings.load / settings.reset
981 981
 
982 982
 #if HAS_Z_AXIS
983 983
   #define  ENABLE_AXIS_Z() if (SHOULD_ENABLE(z))  {  ENABLE_STEPPER_Z();  ENABLE_STEPPER_Z2();  ENABLE_STEPPER_Z3();  ENABLE_STEPPER_Z4(); AFTER_CHANGE(z, true); }
984
-  #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(); }
984
+  #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); }
985 985
 #else
986 986
   #define  ENABLE_AXIS_Z() NOOP
987 987
   #define DISABLE_AXIS_Z() NOOP

+ 6
- 0
Marlin/src/pins/stm32f1/pins_PANDA_PI_V29.h View File

@@ -38,6 +38,12 @@
38 38
   #define MARLIN_EEPROM_SIZE    EEPROM_PAGE_SIZE  // 2K
39 39
 #endif
40 40
 
41
+#if ENABLED(BD_SENSOR)
42
+  #define I2C_BD_SDA_PIN                    PC6
43
+  #define I2C_BD_SCL_PIN                    PB2
44
+  #define I2C_BD_DELAY 10                         // (seconds)
45
+#endif
46
+
41 47
 //
42 48
 // Servos
43 49
 //

+ 19
- 0
buildroot/tests/PANDA_PI_V29 View File

@@ -0,0 +1,19 @@
1
+#!/usr/bin/env bash
2
+#
3
+# Build tests for PANDA_PI_V29
4
+#
5
+
6
+# exit on first failure
7
+set -e
8
+
9
+#
10
+# Build with the default configurations
11
+#
12
+restore_configs
13
+opt_set MOTHERBOARD BOARD_PANDA_PI_V29 SERIAL_PORT -1 \
14
+        Z_CLEARANCE_DEPLOY_PROBE 0 Z_CLEARANCE_BETWEEN_PROBES 1 Z_CLEARANCE_MULTI_PROBE 1
15
+opt_enable BD_SENSOR AUTO_BED_LEVELING_BILINEAR Z_SAFE_HOMING BABYSTEPPING
16
+exec_test $1 $2 "Panda Pi V29 | BD Sensor | ABL-B" "$3"
17
+
18
+# clean up
19
+restore_configs

+ 2
- 0
ini/features.ini View File

@@ -99,6 +99,8 @@ HAS_MCP3426_ADC                        = src_filter=+<src/feature/adc> +<src/gco
99 99
 AUTO_BED_LEVELING_BILINEAR             = src_filter=+<src/feature/bedlevel/abl>
100 100
 AUTO_BED_LEVELING_(3POINT|(BI)?LINEAR) = src_filter=+<src/gcode/bedlevel/abl>
101 101
 X_AXIS_TWIST_COMPENSATION              = src_filter=+<src/feature/x_twist.cpp> +<src/lcd/menu/menu_x_twist.cpp> +<src/gcode/probe/M423.cpp>
102
+BD_SENSOR                              = markyue/Panda_SoftMasterI2C
103
+                                         src_filter=+<src/feature/bedlevel/bdl> +<src/gcode/probe/M102.cpp>
102 104
 MESH_BED_LEVELING                      = src_filter=+<src/feature/bedlevel/mbl> +<src/gcode/bedlevel/mbl>
103 105
 AUTO_BED_LEVELING_UBL                  = src_filter=+<src/feature/bedlevel/ubl> +<src/gcode/bedlevel/ubl>
104 106
 UBL_HILBERT_CURVE                      = src_filter=+<src/feature/bedlevel/hilbert_curve.cpp>

+ 2
- 1
ini/stm32f1.ini View File

@@ -83,7 +83,8 @@ build_flags                 = ${common_STM32F103RC_variant.build_flags}
83 83
                               -DTIMER_SERVO=TIM1
84 84
 board_build.offset          = 0x5000
85 85
 board_upload.offset_address = 0x08005000
86
-
86
+lib_deps =
87
+  markyue/Panda_SoftMasterI2C@1.0.3
87 88
 #
88 89
 # MKS Robin (STM32F103ZET6)
89 90
 # Uses HAL STM32 to support Marlin UI for TFT screen with optional touch panel

+ 1
- 0
platformio.ini View File

@@ -103,6 +103,7 @@ default_src_filter = +<src/*> -<src/config> -<src/HAL> +<src/HAL/shared> -<src/t
103 103
   -<src/feature/backlash.cpp>
104 104
   -<src/feature/baricuda.cpp> -<src/gcode/feature/baricuda>
105 105
   -<src/feature/bedlevel/abl> -<src/gcode/bedlevel/abl>
106
+  -<src/feature/bedlevel/bdl> -<src/gcode/probe/M102.cpp>
106 107
   -<src/feature/bedlevel/mbl> -<src/gcode/bedlevel/mbl>
107 108
   -<src/feature/bedlevel/ubl> -<src/gcode/bedlevel/ubl>
108 109
   -<src/feature/bedlevel/hilbert_curve.cpp>

Loading…
Cancel
Save