More conditional gcode help required - SOLVED
deckingman last edited by deckingman
Can someone tell me how to read the state of an io pin please? Essentially, when the Z axis is a long way away from the nozzle, I want to move it up quickly until it is close (ish) to the nozzle. After that, homing will take place at "normal" speed. I have fitted a micro switch (normally closed) to an arm which pivots against a spring. When the bed gets to about 60 mm of the nozzle, the switch gets triggered and will remain triggered for the remainder of the Z axis travel. So, if I can read the switch state then if it's closed, I can do a fast 50mm move and repeat that move until the switch is triggered.
The switch is connected to expansion board 3, io3 so I'm guessing I'll need to first create an io pin using M950 Jn C"^3.io3.in" or some such yes?
Then something like:
; fast jog while Jn (switch is closed) G1 Z-50 F600 ; move 50mm up at 600mm/sec M400; wait for move to finish
That should bring the nozzle somewhere within 10 to 60 mm of the bed in a series of 50mm moves at 600mm/sec, after which the switch will be triggered. I'm hoping I'll be able to push that speed a lot higher but we'll see what happens.
But it's reading the state of the switch that I'm stuck with. I don't suppose for 1 minute that "while Jn" will work.
CR3D last edited by
In my Thread I postet my solution for the Open Door IO:
Regards Christian (CR-3D)
A Former User last edited by A Former User
the sensor would then be
nis the same
M950 Jn C"^3.io3.in"
so something like
while sensors.gpIn[n].value = 0 G1 Z-50 F600 M400
edit: again, pretty close - just need to start poking the object model with M409 and you'll be unstoppable!
(hm; maybe someone should make an interactive tool to poke the object model and show it in a tree structure nicely formatted)
Actually, since my last feeble attempt, @OwenD sent me details of how to download, set up, and use RJ Text Ed. So I started with that, hoping that I could use the autocomplete feature to find what I was looking for. But I didn't consider that a gpio in would be considered as a sensor. It's kind of obvious when I think about it though.
@CR3D Thanks. Had I seen that thread, the answer to my question would have been obvious.
That all works a treat with one minor addition. Strange things happen if one doesn't first use G91 to set relative movement before attempting a series of G1 moves.
For completeness sake, here are the changes I made.
Added this to config.g - M950 J2 C"^3.io3.in"
and the macro is now this:
; Fast Jog Z M400; wait for any moves to finish G91; Set relative echo "Switch Closed while sensors.gpIn.value=0 G1 Z-50 F900; move Z 50mm @ 900mm/min M400; wait for move to finish echo "Switch open" echo "Fast moves completed"
A Former User last edited by
Strange things happen if one doesn't first use G91
ah, yes, alternatively you'd have to fetch the current z value and add 50 to it. i think dc42 has said something about each macro having its own state with respect to absolute/relative/mm/inch/etc. using G91 is by far the simplest approach
A Former User last edited by
btw did you consider using https://duet3d.dozuki.com/Wiki/Gcode#Section_G38_2_to_G38_5_Straight_Probe and use conditional logic to remap the endtop before/after as needed?