Browse Source

Merge pull request #6219 from Bob-the-Kuhn/Servo-probe-and-toggle-pins

M43 - add Toggle utility and Z servo utility (replaces PR #5864)
pull/1/head
Bob-the-Kuhn 8 years ago
committed by GitHub
parent
commit
a5abc61fb9
  1. 2
      Marlin/Configuration_adv.h
  2. 181
      Marlin/Marlin_main.cpp
  3. 2
      Marlin/example_configurations/Cartesio/Configuration_adv.h
  4. 2
      Marlin/example_configurations/Felix/Configuration_adv.h
  5. 2
      Marlin/example_configurations/Hephestos/Configuration_adv.h
  6. 2
      Marlin/example_configurations/Hephestos_2/Configuration_adv.h
  7. 2
      Marlin/example_configurations/K8200/Configuration_adv.h
  8. 2
      Marlin/example_configurations/K8400/Configuration_adv.h
  9. 2
      Marlin/example_configurations/RigidBot/Configuration_adv.h
  10. 2
      Marlin/example_configurations/SCARA/Configuration_adv.h
  11. 2
      Marlin/example_configurations/TAZ4/Configuration_adv.h
  12. 2
      Marlin/example_configurations/TinyBoy2/Configuration_adv.h
  13. 2
      Marlin/example_configurations/WITBOX/Configuration_adv.h
  14. 2
      Marlin/example_configurations/delta/flsun_kossel_mini/Configuration_adv.h
  15. 2
      Marlin/example_configurations/delta/generic/Configuration_adv.h
  16. 2
      Marlin/example_configurations/delta/kossel_mini/Configuration_adv.h
  17. 2
      Marlin/example_configurations/delta/kossel_pro/Configuration_adv.h
  18. 2
      Marlin/example_configurations/delta/kossel_xl/Configuration_adv.h
  19. 2
      Marlin/example_configurations/makibox/Configuration_adv.h
  20. 2
      Marlin/example_configurations/tvrrug/Round2/Configuration_adv.h

2
Marlin/Configuration_adv.h

@ -1046,7 +1046,7 @@
#define I2C_SLAVE_ADDRESS 0 // Set a value from 8 to 127 to act as a slave #define I2C_SLAVE_ADDRESS 0 // Set a value from 8 to 127 to act as a slave
/** /**
* Add M43, M44 and M45 commands for pins info and testing * M43 - display pin status, watch pins for changes, watch endstops & toggle LED, Z servo probe test, toggle pins
*/ */
//#define PINS_DEBUGGING //#define PINS_DEBUGGING

181
Marlin/Marlin_main.cpp

@ -90,7 +90,7 @@
* M33 - Get the longname version of a path. (Requires LONG_FILENAME_HOST_SUPPORT) * M33 - Get the longname version of a path. (Requires LONG_FILENAME_HOST_SUPPORT)
* M34 - Set SD Card sorting options. (Requires SDCARD_SORT_ALPHA) * M34 - Set SD Card sorting options. (Requires SDCARD_SORT_ALPHA)
* M42 - Change pin status via gcode: M42 P<pin> S<value>. LED pin assumed if P is omitted. * M42 - Change pin status via gcode: M42 P<pin> S<value>. LED pin assumed if P is omitted.
* M43 - Monitor pins & report changes - report active pins * M43 - Display pin status, watch pins for changes, watch endstops & toggle LED, Z servo probe test, toggle pins
* M48 - Measure Z Probe repeatability: M48 P<points> X<pos> Y<pos> V<level> E<engage> L<legs>. (Requires Z_MIN_PROBE_REPEATABILITY_TEST) * M48 - Measure Z Probe repeatability: M48 P<points> X<pos> Y<pos> V<level> E<engage> L<legs>. (Requires Z_MIN_PROBE_REPEATABILITY_TEST)
* M75 - Start the print job timer. * M75 - Start the print job timer.
* M76 - Pause the print job timer. * M76 - Pause the print job timer.
@ -5308,23 +5308,176 @@ inline void gcode_M42() {
#include "pinsDebug.h" #include "pinsDebug.h"
inline void toggle_pins() {
int pin, j, start = 0, I_flag = 0, end = NUM_DIGITAL_PINS - 1, wait = 500, repeat = 1;
if (code_seen('R'))
repeat = code_value_int();
if (code_seen('S'))
start = code_value_int();
if (code_seen('E'))
end = code_value_int();
if (code_seen('I') )
I_flag++;
if (code_seen('W'))
wait = code_value_int();
for(pin = start; pin <= end; pin++) {
if ( I_flag == 0 && pin_is_protected(pin)) {
SERIAL_ECHOPAIR("Sensitive Pin: ", pin);
SERIAL_ECHOPGM(" untouched.\n");
}
else {
SERIAL_ECHOPAIR("Pulsing Pin: ", pin);
pinMode(pin, OUTPUT);
for(j = 0; j < repeat; j++) {
digitalWrite(pin, 0);
idle();
delay(wait);
digitalWrite(pin, 1);
idle();
delay(wait);
digitalWrite(pin, 0);
idle();
delay(wait);
}
}
SERIAL_ECHOPGM("\n");
}
SERIAL_ECHOPGM("Done\n");
return;
} // toggle pin(s)
inline void servo_probe_test(){
#if !(NUM_SERVOS >= 1 && HAS_SERVO_0)
SERIAL_ERROR_START;
SERIAL_ERRORLNPGM("SERVO not setup");
#else
#if !defined(z_servo_angle)
const int z_servo_angle[2] = Z_SERVO_ANGLES;
#endif
uint8_t probe_index = code_seen('P') ? code_value_byte() : 0;
SERIAL_PROTOCOLLNPGM("Servo probe test");
SERIAL_PROTOCOLLNPAIR(". using index: ", probe_index);
SERIAL_PROTOCOLLNPAIR(". deploy angle: ", z_servo_angle[0]);
SERIAL_PROTOCOLLNPAIR(". stow angle: ", z_servo_angle[1]);
bool probe_inverting;
#if ENABLED(Z_MIN_PROBE_USES_Z_MIN_ENDSTOP_PIN)
#define PROBE_TEST_PIN Z_MIN_PIN
SERIAL_PROTOCOLLNPAIR(". probe uses Z_MIN pin: ", PROBE_TEST_PIN);
SERIAL_PROTOCOLLNPGM(". uses Z_MIN_ENDSTOP_INVERTING (ignores Z_MIN_PROBE_ENDSTOP_INVERTING)");
SERIAL_PROTOCOLPGM(". Z_MIN_ENDSTOP_INVERTING: ");
if (Z_MIN_ENDSTOP_INVERTING) SERIAL_PROTOCOLLNPGM("true");
else SERIAL_PROTOCOLLNPGM("false");
probe_inverting = Z_MIN_ENDSTOP_INVERTING;
#elif ENABLED(Z_MIN_PROBE_ENDSTOP)
#define PROBE_TEST_PIN Z_MIN_PROBE_PIN
SERIAL_PROTOCOLLNPAIR(". probe uses Z_MIN_PROBE_PIN: ", PROBE_TEST_PIN);
SERIAL_PROTOCOLLNPGM(". uses Z_MIN_PROBE_ENDSTOP_INVERTING (ignores Z_MIN_ENDSTOP_INVERTING)");
SERIAL_PROTOCOLPGM(". Z_MIN_PROBE_ENDSTOP_INVERTING: ");
if (Z_MIN_PROBE_ENDSTOP_INVERTING) SERIAL_PROTOCOLLNPGM("true");
else SERIAL_PROTOCOLLNPGM("false");
probe_inverting = Z_MIN_PROBE_ENDSTOP_INVERTING;
#else
#error "ERROR - probe pin not defined - strange, SANITY_CHECK should have caught this"
#endif
SERIAL_PROTOCOLLNPGM(". deploy & stow 4 times");
pinMode(PROBE_TEST_PIN, INPUT_PULLUP);
bool deploy_state;
bool stow_state;
for (uint8_t i = 0; i < 4; i++) {
servo[probe_index].move(z_servo_angle[0]); //deploy
safe_delay(500);
deploy_state = digitalRead(PROBE_TEST_PIN);
servo[probe_index].move(z_servo_angle[1]); //stow
safe_delay(500);
stow_state = digitalRead(PROBE_TEST_PIN);
}
if (probe_inverting != deploy_state) SERIAL_PROTOCOLLNPGM("WARNING - INVERTING setting probably backwards");
refresh_cmd_timeout();
if (deploy_state != stow_state) {
SERIAL_PROTOCOLLNPGM("TLTouch detected"); // BLTouch clone?
if (deploy_state) {
SERIAL_PROTOCOLLNPGM(". DEPLOYED state: HIGH (logic 1)");
SERIAL_PROTOCOLLNPGM(". STOWED (triggered) state: LOW (logic 0)");
}
else {
SERIAL_PROTOCOLLNPGM(". DEPLOYED state: LOW (logic 0)");
SERIAL_PROTOCOLLNPGM(". STOWED (triggered) state: HIGH (logic 1)");
}
}
else { // measure active signal length
servo[probe_index].move(z_servo_angle[0]); //deploy
safe_delay(500);
SERIAL_PROTOCOLLNPGM("please trigger probe");
uint16_t probe_counter = 0;
for (uint16_t j = 0; j < 500*30 && probe_counter == 0 ; j++) { // allow 30 seconds max for operator to trigger probe
safe_delay(2);
if ( 0 == j%(500*1)) {refresh_cmd_timeout(); watchdog_reset();} // beat the dog every 45 seconds
if (deploy_state != digitalRead(PROBE_TEST_PIN)) { // probe triggered
for (probe_counter = 1; probe_counter < 50 && (deploy_state != digitalRead(PROBE_TEST_PIN)); probe_counter ++) {
safe_delay(2);
}
if (probe_counter == 50) {
SERIAL_PROTOCOLLNPGM("Z Servo Probe detected"); // >= 100mS active time
}
else if (probe_counter >= 2 ) {
SERIAL_PROTOCOLLNPAIR("BLTouch compatible probe detected - pulse width (+/- 4mS): ", probe_counter * 2 ); // allow 4 - 100mS pulse
}
else {
SERIAL_PROTOCOLLNPGM("noise detected - please re-run test"); // less than 2mS pulse
}
servo[probe_index].move(z_servo_angle[1]); //stow
} // pulse detected
} // for loop waiting for trigger
if (probe_counter == 0) SERIAL_PROTOCOLLNPGM("trigger not detected");
} // measure active signal length
#endif
} // servo_probe_test
/** /**
* M43: Pin report and debug * M43: Pin debug - report pin state, watch pins, toggle pins and servo probe test/report
*
* M43 - report name and state of pin(s)
* P<pin> Pin to read or watch. If omitted, reads all pins.
* I Flag to ignore Marlin's pin protection.
* *
* E<bool> Enable / disable background endstop monitoring * M43 W - Watch pins -reporting changes- until reset, click, or M108.
* P<pin> Pin to read or watch. If omitted, read/watch all pins.
* I Flag to ignore Marlin's pin protection.
*
* M43 E<bool> - Enable / disable background endstop monitoring
* - Machine continues to operate * - Machine continues to operate
* - Reports changes to endstops * - Reports changes to endstops
* - Toggles LED when an endstop changes * - Toggles LED when an endstop changes
* - Can not reliably catch the 5mS pulse from BLTouch type probes
* *
* or * M43 T - Toggle pin(s) and report which pin is being toggled
* * S<pin> - Start Pin number. If not given, will default to 0
* P<pin> Pin to read or watch. If omitted, read/watch all pins. * L<pin> - End Pin number. If not given, will default to last pin defined for this board
* W<bool> Watch pins -reporting changes- until reset, click, or M108. * I - Flag to ignore Marlin's pin protection. Use with caution!!!!
* I<bool> Flag to ignore Marlin's pin protection. * R - Repeat pulses on each pin this number of times before continueing to next pin
* W - Wait time (in miliseconds) between pulses. If not given will default to 500
* *
* M43 S - Servo probe test
* P<index> - Probe index (optional - defaults to 0
*/ */
inline void gcode_M43() { inline void gcode_M43() {
if (code_seen('T')) { // must be first ot else it's "S" and "E" parameters will execute endstop or servo test
toggle_pins();
return;
}
// Enable or disable endstop monitoring // Enable or disable endstop monitoring
if (code_seen('E')) { if (code_seen('E')) {
endstop_monitor_flag = code_value_bool(); endstop_monitor_flag = code_value_bool();
@ -5334,6 +5487,12 @@ inline void gcode_M42() {
return; return;
} }
if (code_seen('S')) {
servo_probe_test();
return;
}
// Get the range of pins to test or watch // Get the range of pins to test or watch
int first_pin = 0, last_pin = NUM_DIGITAL_PINS - 1; int first_pin = 0, last_pin = NUM_DIGITAL_PINS - 1;
if (code_seen('P')) { if (code_seen('P')) {
@ -5341,10 +5500,11 @@ inline void gcode_M42() {
if (first_pin > NUM_DIGITAL_PINS - 1) return; if (first_pin > NUM_DIGITAL_PINS - 1) return;
} }
const bool ignore_protection = code_seen('I') ? code_value_bool() : false; bool ignore_protection = code_seen('I');
// Watch until click, M108, or reset // Watch until click, M108, or reset
if (code_seen('W') && code_value_bool()) { // watch digital pins if (code_seen('W')) { // watch digital pins
SERIAL_PROTOCOLLNPGM("Watching pins");
byte pin_state[last_pin - first_pin + 1]; byte pin_state[last_pin - first_pin + 1];
for (int8_t pin = first_pin; pin <= last_pin; pin++) { for (int8_t pin = first_pin; pin <= last_pin; pin++) {
if (pin_is_protected(pin) && !ignore_protection) continue; if (pin_is_protected(pin) && !ignore_protection) continue;
@ -5387,6 +5547,7 @@ inline void gcode_M42() {
report_pin_state_extended(pin, ignore_protection); report_pin_state_extended(pin, ignore_protection);
} }
#endif // PINS_DEBUGGING #endif // PINS_DEBUGGING
#if ENABLED(Z_MIN_PROBE_REPEATABILITY_TEST) #if ENABLED(Z_MIN_PROBE_REPEATABILITY_TEST)

2
Marlin/example_configurations/Cartesio/Configuration_adv.h

@ -1036,7 +1036,7 @@
#define I2C_SLAVE_ADDRESS 0 // Set a value from 8 to 127 to act as a slave #define I2C_SLAVE_ADDRESS 0 // Set a value from 8 to 127 to act as a slave
/** /**
* Add M43, M44 and M45 commands for pins info and testing * M43 - display pin status, watch pins for changes, watch endstops & toggle LED, Z servo probe test, toggle pins
*/ */
//#define PINS_DEBUGGING //#define PINS_DEBUGGING

2
Marlin/example_configurations/Felix/Configuration_adv.h

@ -1036,7 +1036,7 @@
#define I2C_SLAVE_ADDRESS 0 // Set a value from 8 to 127 to act as a slave #define I2C_SLAVE_ADDRESS 0 // Set a value from 8 to 127 to act as a slave
/** /**
* Add M43, M44 and M45 commands for pins info and testing * M43 - display pin status, watch pins for changes, watch endstops & toggle LED, Z servo probe test, toggle pins
*/ */
//#define PINS_DEBUGGING //#define PINS_DEBUGGING

2
Marlin/example_configurations/Hephestos/Configuration_adv.h

@ -1036,7 +1036,7 @@
#define I2C_SLAVE_ADDRESS 0 // Set a value from 8 to 127 to act as a slave #define I2C_SLAVE_ADDRESS 0 // Set a value from 8 to 127 to act as a slave
/** /**
* Add M43, M44 and M45 commands for pins info and testing * M43 - display pin status, watch pins for changes, watch endstops & toggle LED, Z servo probe test, toggle pins
*/ */
//#define PINS_DEBUGGING //#define PINS_DEBUGGING

2
Marlin/example_configurations/Hephestos_2/Configuration_adv.h

@ -1019,7 +1019,7 @@
#define I2C_SLAVE_ADDRESS 0 // Set a value from 8 to 127 to act as a slave #define I2C_SLAVE_ADDRESS 0 // Set a value from 8 to 127 to act as a slave
/** /**
* Add M43, M44 and M45 commands for pins info and testing * M43 - display pin status, watch pins for changes, watch endstops & toggle LED, Z servo probe test, toggle pins
*/ */
//#define PINS_DEBUGGING //#define PINS_DEBUGGING

2
Marlin/example_configurations/K8200/Configuration_adv.h

@ -1049,7 +1049,7 @@
#define I2C_SLAVE_ADDRESS 0 // Set a value from 8 to 127 to act as a slave #define I2C_SLAVE_ADDRESS 0 // Set a value from 8 to 127 to act as a slave
/** /**
* Add M43, M44 and M45 commands for pins info and testing * M43 - display pin status, watch pins for changes, watch endstops & toggle LED, Z servo probe test, toggle pins
*/ */
//#define PINS_DEBUGGING //#define PINS_DEBUGGING

2
Marlin/example_configurations/K8400/Configuration_adv.h

@ -1036,7 +1036,7 @@
#define I2C_SLAVE_ADDRESS 0 // Set a value from 8 to 127 to act as a slave #define I2C_SLAVE_ADDRESS 0 // Set a value from 8 to 127 to act as a slave
/** /**
* Add M43, M44 and M45 commands for pins info and testing * M43 - display pin status, watch pins for changes, watch endstops & toggle LED, Z servo probe test, toggle pins
*/ */
//#define PINS_DEBUGGING //#define PINS_DEBUGGING

2
Marlin/example_configurations/RigidBot/Configuration_adv.h

@ -1036,7 +1036,7 @@
#define I2C_SLAVE_ADDRESS 0 // Set a value from 8 to 127 to act as a slave #define I2C_SLAVE_ADDRESS 0 // Set a value from 8 to 127 to act as a slave
/** /**
* Add M43, M44 and M45 commands for pins info and testing * M43 - display pin status, watch pins for changes, watch endstops & toggle LED, Z servo probe test, toggle pins
*/ */
//#define PINS_DEBUGGING //#define PINS_DEBUGGING

2
Marlin/example_configurations/SCARA/Configuration_adv.h

@ -1036,7 +1036,7 @@
#define I2C_SLAVE_ADDRESS 0 // Set a value from 8 to 127 to act as a slave #define I2C_SLAVE_ADDRESS 0 // Set a value from 8 to 127 to act as a slave
/** /**
* Add M43, M44 and M45 commands for pins info and testing * M43 - display pin status, watch pins for changes, watch endstops & toggle LED, Z servo probe test, toggle pins
*/ */
//#define PINS_DEBUGGING //#define PINS_DEBUGGING

2
Marlin/example_configurations/TAZ4/Configuration_adv.h

@ -1044,7 +1044,7 @@
#define I2C_SLAVE_ADDRESS 0 // Set a value from 8 to 127 to act as a slave #define I2C_SLAVE_ADDRESS 0 // Set a value from 8 to 127 to act as a slave
/** /**
* Add M43, M44 and M45 commands for pins info and testing * M43 - display pin status, watch pins for changes, watch endstops & toggle LED, Z servo probe test, toggle pins
*/ */
//#define PINS_DEBUGGING //#define PINS_DEBUGGING

2
Marlin/example_configurations/TinyBoy2/Configuration_adv.h

@ -1044,7 +1044,7 @@
#define I2C_SLAVE_ADDRESS 0 // Set a value from 8 to 127 to act as a slave #define I2C_SLAVE_ADDRESS 0 // Set a value from 8 to 127 to act as a slave
/** /**
* Add M43, M44 and M45 commands for pins info and testing * M43 - display pin status, watch pins for changes, watch endstops & toggle LED, Z servo probe test, toggle pins
*/ */
//#define PINS_DEBUGGING //#define PINS_DEBUGGING

2
Marlin/example_configurations/WITBOX/Configuration_adv.h

@ -1036,7 +1036,7 @@
#define I2C_SLAVE_ADDRESS 0 // Set a value from 8 to 127 to act as a slave #define I2C_SLAVE_ADDRESS 0 // Set a value from 8 to 127 to act as a slave
/** /**
* Add M43, M44 and M45 commands for pins info and testing * M43 - display pin status, watch pins for changes, watch endstops & toggle LED, Z servo probe test, toggle pins
*/ */
//#define PINS_DEBUGGING //#define PINS_DEBUGGING

2
Marlin/example_configurations/delta/flsun_kossel_mini/Configuration_adv.h

@ -1040,7 +1040,7 @@
#define I2C_SLAVE_ADDRESS 0 // Set a value from 8 to 127 to act as a slave #define I2C_SLAVE_ADDRESS 0 // Set a value from 8 to 127 to act as a slave
/** /**
* Add M43, M44 and M45 commands for pins info and testing * M43 - display pin status, watch pins for changes, watch endstops & toggle LED, Z servo probe test, toggle pins
*/ */
//#define PINS_DEBUGGING //#define PINS_DEBUGGING

2
Marlin/example_configurations/delta/generic/Configuration_adv.h

@ -1038,7 +1038,7 @@
#define I2C_SLAVE_ADDRESS 0 // Set a value from 8 to 127 to act as a slave #define I2C_SLAVE_ADDRESS 0 // Set a value from 8 to 127 to act as a slave
/** /**
* Add M43, M44 and M45 commands for pins info and testing * M43 - display pin status, watch pins for changes, watch endstops & toggle LED, Z servo probe test, toggle pins
*/ */
//#define PINS_DEBUGGING //#define PINS_DEBUGGING

2
Marlin/example_configurations/delta/kossel_mini/Configuration_adv.h

@ -1038,7 +1038,7 @@
#define I2C_SLAVE_ADDRESS 0 // Set a value from 8 to 127 to act as a slave #define I2C_SLAVE_ADDRESS 0 // Set a value from 8 to 127 to act as a slave
/** /**
* Add M43, M44 and M45 commands for pins info and testing * M43 - display pin status, watch pins for changes, watch endstops & toggle LED, Z servo probe test, toggle pins
*/ */
//#define PINS_DEBUGGING //#define PINS_DEBUGGING

2
Marlin/example_configurations/delta/kossel_pro/Configuration_adv.h

@ -1043,7 +1043,7 @@
#define I2C_SLAVE_ADDRESS 0 // Set a value from 8 to 127 to act as a slave #define I2C_SLAVE_ADDRESS 0 // Set a value from 8 to 127 to act as a slave
/** /**
* Add M43, M44 and M45 commands for pins info and testing * M43 - display pin status, watch pins for changes, watch endstops & toggle LED, Z servo probe test, toggle pins
*/ */
//#define PINS_DEBUGGING //#define PINS_DEBUGGING

2
Marlin/example_configurations/delta/kossel_xl/Configuration_adv.h

@ -1038,7 +1038,7 @@
#define I2C_SLAVE_ADDRESS 0 // Set a value from 8 to 127 to act as a slave #define I2C_SLAVE_ADDRESS 0 // Set a value from 8 to 127 to act as a slave
/** /**
* Add M43, M44 and M45 commands for pins info and testing * M43 - display pin status, watch pins for changes, watch endstops & toggle LED, Z servo probe test, toggle pins
*/ */
//#define PINS_DEBUGGING //#define PINS_DEBUGGING

2
Marlin/example_configurations/makibox/Configuration_adv.h

@ -1036,7 +1036,7 @@
#define I2C_SLAVE_ADDRESS 0 // Set a value from 8 to 127 to act as a slave #define I2C_SLAVE_ADDRESS 0 // Set a value from 8 to 127 to act as a slave
/** /**
* Add M43, M44 and M45 commands for pins info and testing * M43 - display pin status, watch pins for changes, watch endstops & toggle LED, Z servo probe test, toggle pins
*/ */
//#define PINS_DEBUGGING //#define PINS_DEBUGGING

2
Marlin/example_configurations/tvrrug/Round2/Configuration_adv.h

@ -1036,7 +1036,7 @@
#define I2C_SLAVE_ADDRESS 0 // Set a value from 8 to 127 to act as a slave #define I2C_SLAVE_ADDRESS 0 // Set a value from 8 to 127 to act as a slave
/** /**
* Add M43, M44 and M45 commands for pins info and testing * M43 - display pin status, watch pins for changes, watch endstops & toggle LED, Z servo probe test, toggle pins
*/ */
//#define PINS_DEBUGGING //#define PINS_DEBUGGING

Loading…
Cancel
Save