Firmware proposal: Using Z Probe as external trigger



  • Hi!

    Me and my little startup are building a device that uses a Duet 2 Ethernet (v1.04) to develop a type of object scanner. It looks a lot like a 3D printer, but instead of a nozzle we move a light source, and instead of creating a print there's an existing object (for us: camera lenses) that we're mapping using machine vision.

    We've loved working with the Duet. Frankly, I've been amazed at how well it's adapted to our purpose. One of the best technology choices we've made in our ~8 months so far!

    I'd like to propose a small firmware addition to help with our use case. If you like it I'd be happy to attempt also putting up a GitHub PR.

    In our case, we don't need a Z Probe for bed leveling, but we'd like to use it as a safety switch to ensure our moving light source arm never accidentally touches the object being scanned.

    Specifically, I'd like to be able to select the Z Probe as an input in M581 (Configure external trigger), so that when the trigger value configured in G31 (Set current probe status) is exceeded it can trigger an emergency stop.

    I suggest that M581 could take a new input parameter, e.g. N (meaning Z Probe), in addition to existing X,Y,Z,E selectors. Hopefully intuitively, the S1 modifier could be interpreted as "rose above trigger value", and S0 as "dropped below trigger value".

    (The N is arbitrary; alas the names T (would have matched G31) and P (for Probe) are already taken.)

    For example:

    ; Configure Z Probe to be safety switch; emergency stop if we come too close to object.
    M558 P1 I1                       ; Use analog Z probe, signal falls as object is closer.
    G31 P980                         ; Z probe is triggered when its value is >980.
    M581 N S1 T0 C0                  ; Emergency stop if Z probe ever exceeds trigger value.
    

    In our specific case we plan to use a MaxBotix EZ ultrasonic range finder; using its analog signal I have it successfully hooked it up as a Z Probe.

    Cheers!
    RJ.



  • It would be nice to specify the analog value in the config.g.

    At the same time, you can do this today, with a tiny scrap of circuitry and something like:

    M558 T0 E S1

    T0 = Emergency stop when trigger hits

    E = I'm assuming you are not using an E endstop, yet, in your hardware, and can plug the output of your distance monitor in the E0 endstop connector on the board.

    S1 = Trigger when input rises.

    The circuitry could be as simple as a variable resistor (potentiometer) that you turn to set the distance threshold. This MIGHT be too dependent on other things, such as the exact logic trigger of the E0 endstop input, current flow, etc.

    Therefore, it might be better to use a small comparator like this (assuming your sensor is a variable voltage source, 0 to 5V, on pin 2 of the three pin header shown):

    0_1565196124202_004e9dc9-778d-47e3-8e74-a1548226b0de-image.png

    The pot lets you set the "trigger distance". The LED lets you set it without looking at the Duet web interface.

    Notes:

    1. Take the exact circuit with a grain of salt, I drew it out of my head in a few moments. It is really to get the idea across as much as to be an exact implementation.

    2. Having said that, if you choose to try this circuit first, yes, this shows 5V VCC. The output should be safe for 3.3V Duet, because the LM358 is not a "rail to rail" comparator, and the voltage drop should be just about right... but... CHECK THIS before plugging into a duet!!!


  • administrators

    @rjh Thats very cool to hear! I love seeing how Duets get used for a wide variety of machines, thats for your kind words.

    Have you had a look at RepRapFirmware 3.0 yet? Its sill in early beta/(alpha...). Here is the documentation:
    https://duet3d.dozuki.com/Wiki/RepRapFirmware_3_overview#Section_M581

    That at least allows you to set the trigger pin to the Z probe input.

    Adding a trigger on analog threshold for M581 would be a good feature request (maybe start that topic in the feature request sub forum).



  • Thanks @Danal and @T3P3Tony!

    @Danal: that's good out-of-the-box thinking there, I guess my background as a software engineer shows: I prefer to do as much as possible in software. 🙂 I see how your circuit solves the issue, yet I worry that it's an extra component for me to manufacture and calibrate for every device I want to ship. Hence my eagerness to do this in easy-to-reproduce software instead. 🙂

    @T3P3Tony cool, I had no idea the 3.0 firmware is in the works! I love how pin selection becomes so much more flexible and understandable. Yes, triggering on an analog threshold for M581 would exactly solve my issue, I'll post in the feature request sub forum!


Log in to reply