Yet more conditional gcode help required
-
@dc42 said in Yet more conditional gcode help required:
That's the right approach, however the if..elif statements are not right. Try something like this:
You could also add an "else break" at the end, then you wouldn't need to test all the buttons in the while-part.
If he removes the while test of all pins, wouldn't the macro only trigger once (when a switch signal rose/fell)
Or do you just mean use "while true" instead (hence the break statement )
I'm always reluctant to use potentially infinite loops. -
Yes I meant use "while true". Or if you don't like infinite loops, "while iterations < 1000" or similar.
-
@dc42 Thanks for clarification.
I might have locked up a few machines over the years with my clumsy work when using loops.
I realise it's a valid method for those that think things through more than me before they press "executive" edit: "execute" (Stupid iPhone!!!) -
Err, in view of the above and as a further sanity check on my understanding, here is the full macro that I intend to start with ........
G91; Set relative M400; wait for any moves to finish G1 F6000 ; set feedrate to 100mm/sec while sensors.gpIn[5].value=0 | sensors.gpIn[6].value=0 | sensors.gpIn[7].value=0 | sensors.gpIn[8].value=0 if sensors.gpIn[5].value=0; joystick left if sensors.gpIn[7].value=0 ; joystick left and forwards M400 G1 X-1 U-1 A-1 Y-1 V-1 B-1 elif sensors.gpIn[8]; joystick left and backwards M400 G1 X-1 U-1 A-1 Y1 V1 B1 else ; joystick left only M400 G1 X-1 U-1 A-1 elif sensors.gpIn[6].value=0; joystick right if sensors.gpIn[7].value=0 ; joystick right and forwards M400 G1 X1 U1 A1 Y-1 V-1 B-1 elif sensors.gpIn[8]; joystick right and backward M400 G1 X1 U1 A1 Y1 V1 B1 else ; joystick right only M400 G1 X1 U1 A1 elif sensors.gpIn[7].value=0 ; joystick forwards only M400 G1 Y-1 V-1 B-1 elif sensors.gpIn[8].value=0 ; joystick backward only M400 G1 Y1 V1 B1 else break
Is that about right?
-
To clarify my comments.
A "while" statement will loop if the condition test is true.
In your case by testing all those inputs.If you put
while true G1 X1
Then you have an endless loop as true always equals true, so you're going to crash.
Therefore you must ensure that you put a test in somewhere the calls "break" to get you out of the loop.In the suggested code above that test is satisfied when none of the IF statements resolve to true, so break is called.
-
OK, so that's all wired up and working. It does what I hoped it would and it respects the axis limits too (of course it does - I never doubted it would ).
But I'd like to add an embellishment if possible. I've used 1mm as a movement length which is great for reasonably precise positioning but naturally, it's a bit slow if I want to travel the full 400mm or so of axis travel. Increasing the step size to (say) 5mm is about right but then I lose precision. So what I'd like to do is a bit like how one sets the time on some digital clocks. That is to say, the longer one holds the button, the faster the time changes.
So I'd like to alter the code so that if I hold the joystick in one position, it will move in 1mm increments but after (say) 5 iterations, the move length will increase to (say) 5mm). Ideally I'd like to do something a bit more sophisticated still, like keep increasing the move length the longer the joystick is held in one position but I'll settle for just a binary change after say 5 iterations of the same move.
Here is the code that I have now (without the errors that I had in some of the elif commands when I last posted it )
G91; Set relative M400; wait for any moves to finish G1 F6000 ; set feedrate to 100mm/sec M118 S"Trigger 5 - Joystick" while sensors.gpIn[5].value=0 | sensors.gpIn[6].value=0 | sensors.gpIn[7].value=0 | sensors.gpIn[8].value=0 if sensors.gpIn[5].value=0; joystick left if sensors.gpIn[7].value=0 ; joystick left and forwards M400 G1 X-1 U-1 A-1 Y-1 V-1 B-1 echo "Left and forward" elif sensors.gpIn[8].value=0; joystick left and backwards M400 G1 X-1 U-1 A-1 Y1 V1 B1 echo "Left and backwards" else ; joystick left only M400 G1 X-1 U-1 A-1 echo "Left" elif sensors.gpIn[6].value=0; joystick right if sensors.gpIn[7].value=0 ; joystick right and forwards M400 G1 X1 U1 A1 Y-1 V-1 B-1 echo "Right and forward" elif sensors.gpIn[8].value=0; joystick right and backward M400 G1 X1 U1 A1 Y1 V1 B1 echo "Right and backwards" else ; joystick right only M400 G1 X1 U1 A1 echo "Right" elif sensors.gpIn[7].value=0 ; joystick forwards only M400 G1 Y-1 V-1 B-1 echo "Forward" elif sensors.gpIn[8].value=0 ; joystick backward only M400 G1 Y1 V1 B1 echo "Backwards" else break
-
You could use the built-in 'iterations' variable to adjust the movement amount and/or speed.
-
@dc42 said in Yet more conditional gcode help required:
You could use the built-in 'iterations' variable to adjust the movement amount and/or speed.
Thanks.
Would I be right in assuming the "iterations" is a counter which increments by 1 every time the while loop runs?Scratch that - found it.
-
That's all working now although the code is a bit "clunky".
I'm guessing that once variables are introduced, I ought to be able to do something like ....
MoveAmount= 0.5+(iterations/5) G1 X MoveAmount..............
.......or some such. Anyway, this is what I've ended up with which may not be elegant but works.
G91; Set relative M400; wait for any moves to finish G1 F3000 ; set feedrate to 100mm/sec M118 S"Trigger 5 - Joystick" while sensors.gpIn[5].value=0 | sensors.gpIn[6].value=0 | sensors.gpIn[7].value=0 | sensors.gpIn[8].value=0 if sensors.gpIn[5].value=0; joystick left if sensors.gpIn[7].value=0 ; joystick left and forwards M400 if iterations<3 G1 X-0.5 U-0.5 A-0.5 Y-0.5 V-0.5 B-0.5 elif iterations<5 G1 X-1 U-1 A-1 Y-1 V-1 B-1 elif iterations<7 G1 X-2 U-2 A-2 Y-2 V-2 B-2 elif iterations<9 G1 X-5 U-5 A-5 Y-5 V-5 B-5 elif iterations<11 G1 X-10 U-10 A-10 Y-10 V-10 B-10 else G1 X-20 U-20 A-20 Y-20 V-20 B-20 elif sensors.gpIn[8].value=0; joystick left and backwards M400 if iterations<3 G1 X-0.5 U-0.5 A-0.5 Y0.5 V0.5 B0.5 elif iterations<5 G1 X-1 U-1 A-1 Y1 V1 B1 elif iterations<7 G1 X-2 U-2 A-2 Y2 V2 B2 elif iterations<9 G1 X-5 U-5 A-5 Y5 V5 B5 elif iterations<11 G1 X-10 U-10 A-10 Y10 V10 B10 else G1 X-20 U-20 A-20 Y20 V20 B20 else ; joystick left only M400 if iterations<3 G1 X-0.5 U-0.5 A-0.5 elif iterations<5 G1 X-1 U-1 A-1 elif iterations<7 G1 X-2 U-2 A-2 elif iterations<9 G1 X-5 U-5 A-5 elif iterations<11 G1 X-10 U-10 A-10 else G1 X-20 U-20 A-20 elif sensors.gpIn[6].value=0; joystick right if sensors.gpIn[7].value=0 ; joystick right and forwards M400 if iterations<3 G1 X0.5 U0.5 A0.5 Y-0.5 V-0.5 B-0.5 elif iterations<5 G1 X1 U1 A1 Y-1 V-1 B-1 elif iterations<7 G1 X2 U2 A2 Y-2 V-2 B-2 elif iterations<9 G1 X5 U5 A5 Y-5 V-5 B-5 elif iterations<11 G1 X10 U10 A10 Y-10 V-10 B-10 else G1 X20 U20 A20 Y-20 V-20 B-20 elif sensors.gpIn[8].value=0; joystick right and backward M400 if iterations<3 G1 X0.5 U0.5 A0.5 Y0.5 V0.5 B0.5 elif iterations<5 G1 X1 U1 A1 Y1 V1 B1 elif iterations<7 G1 X2 U2 A2 Y2 V2 B2 elif iterations<9 G1 X5 U5 A5 Y5 V5 B5 elif iterations<11 G1 X10 U10 A10 Y10 V10 B10 else G1 X20 U20 A20 Y20 V20 B20 else ; joystick right only M400 if iterations<3 G1 X0.5 U0.5 A0.5 elif iterations<5 G1 X1 U1 A1 elif iterations<7 G1 X2 U2 A2 elif iterations<9 G1 X5 U5 A5 elif iterations<11 G1 X10 U10 A10 else G1 X20 U20 A20 elif sensors.gpIn[7].value=0 ; joystick forwards only M400 if iterations<3 G1 Y-0.5 V-0.5 B-0.5 elif iterations<5 G1 Y-1 V-1 B-1 elif iterations<7 G1 Y-2 V-2 B-2 elif iterations<9 G1 Y-5 V-5 B-5 elif iterations<11 G1 Y-10 V-10 B-10 else G1 Y-20 V-20 B-20 elif sensors.gpIn[8].value=0 ; joystick backward only M400 if iterations<3 G1 Y0.5 V0.5 B0.5 elif iterations<5 G1 Y1 V1 B1 elif iterations<7 G1 Y2 V2 B2 elif iterations<9 G1 Y5 V5 B5 elif iterations<11 G1 Y10 V10 B10 else G1 Y20 V20 B20 else break
-
Another way is to use your original code but replace all the XYUVABC coordinates in the G1 commands by calculated values, something like this:
G1 X{0.5+0.1 * iterations} Y{-(0.5+0.1 * iterations)} ...
-
@dc42 said in Yet more conditional gcode help required:
Another way is to use your original code but replace all the XYUVABC coordinates in the G1 commands by calculated values, something like this:
G1 X{0.5+0.1 * iterations} Y{-(0.5+0.1 * iterations)} ...
Ahhh - that looks good! I tried something similar but it didn't work - because I used plain braces rather than curly ones. I'll give that a go..............
-
For the sake of completeness, here is the final code that I ended up using. After playing around with it, I ended up using just G1 X{0.5+interations}........etc, rather than using fraction's of "iterations".
G91; Set relative M400; wait for any moves to finish G1 F6000 ; set feedrate to 100mm/sec M118 S"Trigger 5 - Joystick" while sensors.gpIn[5].value=0 | sensors.gpIn[6].value=0 | sensors.gpIn[7].value=0 | sensors.gpIn[8].value=0 if sensors.gpIn[5].value=0; joystick left if sensors.gpIn[7].value=0 ; joystick left and forwards M400 G1 X{-(0.5+iterations)} U{-(0.5+iterations)} A{-(0.5+iterations)} Y{-(0.5+iterations)} V{-(0.5+iterations)} B{-(0.5+iterations)} echo "Left and forward" elif sensors.gpIn[8].value=0; joystick left and backwards M400 G1 X{-(0.5+iterations)} U{-(0.5+iterations)} A{-(0.5+iterations)} Y{0.5+iterations} V{0.5+iterations} B{0.5+iterations} echo "Left and backwards" else ; joystick left only M400 G1 X{-(0.5+iterations)} U{-(0.5+iterations)} A{-(0.5+iterations)} echo "Left" elif sensors.gpIn[6].value=0; joystick right if sensors.gpIn[7].value=0 ; joystick right and forwards M400 G1 X{0.5+iterations} U{0.5+iterations} A{0.5+iterations} Y{-(0.5+iterations)} V{-(0.5+iterations)} B{-(0.5+iterations)} echo "Right and forward" elif sensors.gpIn[8].value=0; joystick right and backward M400 G1 X{0.5+iterations} U{0.5+iterations} A{0.5+iterations} Y{0.5+iterations} V{0.5+iterations} B{0.5+iterations} echo "Right and backwards" else ; joystick right only M400 G1 X{0.5+iterations} U{0.5+iterations} A{0.5+iterations} echo "Right" elif sensors.gpIn[7].value=0 ; joystick forwards only M400 G1 Y{-(0.5+iterations)} V{-(0.5+iterations)} B{-(0.5+iterations)} echo "Forward" elif sensors.gpIn[8].value=0 ; joystick backward only M400 G1 Y{0.5+iterations} V{0.5+iterations} B{0.5+iterations} echo "Backwards" else break
Thanks for all the help guys.
-
For further completeness, I've added a "turbo button". So instead of increasing the distance using "iterations", I simply press the button in conjunction with moving the joystick. What that does is move the gantries 20mm if the button is pressed or 0.5mm if it isn't. I prefer this method but either one works.
I've also wrapped the entire thing in a "if state.status != "processing"" statement (thanks for the suggestion @T3P3Tony). What that does is checks to make sure that a print is NOT in progress which will do what the M581 R2 parameter will do in the next firmware. Here is that version of the code
if state.status != "processing" ; make sure that a print is NOT running G91; Set relative M400; wait for any moves to finish G1 F3000 ; set feedrate to 100mm/sec M118 S"Trigger 5 - Joystick" while sensors.gpIn[5].value=0 | sensors.gpIn[6].value=0 | sensors.gpIn[7].value=0 | sensors.gpIn[8].value=0 if sensors.gpIn[5].value=0; joystick left if sensors.gpIn[7].value=0 ; joystick left and forwards M400 echo "Left and forward" if sensors.gpIn[4].value=0 ; check for long move button press G1 X-20 U-20 A-20 Y-20 V-20 B-20 else G1 X-0.5 U-0.5 A-0.5 Y-0.5 V-0.5 B-0.5 elif sensors.gpIn[8].value=0; joystick left and backwards M400 echo "Left and backwards" if sensors.gpIn[4].value=0 ; check for long move button press G1 X-20 U-20 A-20 Y20 V20 B20 else G1 X-0.5 U-0.5 A-0.5 Y0.5 V0.5 B0.5 else ; joystick left only M400 echo "Left" if sensors.gpIn[4].value=0 ; check for long move button press G1 X-20 U-20 A-20 else G1 X-0.5 U-0.5 A0.5 elif sensors.gpIn[6].value=0; joystick right if sensors.gpIn[7].value=0 ; joystick right and forwards M400 echo "Right and forward" if sensors.gpIn[4].value=0 ; check for long move button press G1 X20 U20 A20 Y-20 V-20 B-20 else G1 X0.5 U0.5 A0.5 Y-0.5 V-0.5 B-0.5 elif sensors.gpIn[8].value=0; joystick right and backward M400 echo "Right and backwards" if sensors.gpIn[4].value=0 ; check for long move button press G1 X20 U20 A20 Y20 V20 B20 else G1 X0.5 U0.5 A0.5 Y0.5 V0.5 B0.5 else ; joystick right only M400 echo "Right" if sensors.gpIn[4].value=0 ; check for long move button press G1 X20 U20 A20 else G1 X0.5 U0.5 A0.5 elif sensors.gpIn[7].value=0 ; joystick forwards only M400 echo "Forward" if sensors.gpIn[4].value=0 ; check for long move button press G1 Y-20 V-20 B-20 else G1 Y-0.5 V-0.5 B-0.5 elif sensors.gpIn[8].value=0 ; joystick backward only M400 echo "Backwards" if sensors.gpIn[4].value=0 ; check for long move button press G1 Y20 V20 B20 else G1 Y0.5 V0.5 B0.5 else break else break
-
@deckingman I have followed this with interest but then I thought what was the actual problem? When I use the XY buttons in DWC my main XY and UV carriages move together and in sync. Have I not understood the problem?
-
@appjaws said in Yet more conditional gcode help required:
@deckingman I have followed this with interest but then I thought what was the actual problem? When I use the XY buttons in DWC my main XY and UV carriages move together and in sync. Have I not understood the problem?
Hiya. I've changed things around a bit so that I no longer combine the axes after homing. So the DWC buttons only work for individual axes. i.e. XY moves will only move the hot end - not the hot end and extruder gantry (as they used to do when the axes were combined)
The reason being that I've exploited the fact that, because the extruders are connected to the hot end via short Bowden tubes, that extruder gantry doesn't have to exactly follow the hot end gantry. It doesn't have to replicate every tiny move that the hot end does - it only has to follow it within an allowable tolerance. So if there are small features (say a hole or a cylinder) then I can "park" the extruder gantry in the centre of that feature and let it sit there while the hot end does all those short moves which make that feature. The same applies to other short zig-zag type moves where the extruder gantry sits still while the hot end does the short zig-zags.
I made a couple of YouTube videos which explain it in a bit more detail
https://www.youtube.com/watch?v=rOP9QYAlhZU
and
https://www.youtube.com/watch?v=mTPV3Ss1D-4So that's the reason why the axis button on DWC are no longer much use to me. A fuller explanation of what I wanted the joystick to do, and how that works in practice is here
https://www.youtube.com/watch?v=wCR5Ao0iH-c -
Hi again,
Very impressive videos @deckingman . Is it possible to have a copy of your python script that generates the movement please.
My machine really vibrates during short movements so your solution should solve it for me. -
@appjaws Sure. It's been a few years since we last communicated. Is your email address still the one ending ......ve.co.uk? If not, pm me with the address to use.
Be aware, that it's quite a lot of work to run the machine in "true" CoreXYUV mode. You need to change all you homing files so that they do not re-combine the axes, and change the "P" parameter in M581 so that the 5 axes are visible. Also any macros or gcode start and end scripts that have XY moves will need to be changed to incorporate XYUV moves.
Also be aware that, although the python code gets the job done, I'm not a writer of code, so it ain't pretty.
-
@deckingman Yes same email address.
I was wondering if I could just change the XYUV to be individual just during a print similar to the way homeall.g works.
M584 X0 U3 Y1 V4 Z7:8:9 E2:5:6 P5 ; temporarily separate and map drives to U and V axescomplete the modified gcode part file using separate XYUV axes
M584 X0:3 Y1:4 Z7:8:9 U10 V11 E2:5:6 P3 ; put motor mapping back to normal so that X uses drives 0 and 3 Y uses 1 and 4
then once the printed part is removed from the bed run homeall.g
can you see any problems with this?
Thanks for your help
-
@appjaws said in Yet more conditional gcode help required:
@deckingman Yes same email address.
I was wondering if I could just change the XYUV to be individual just during a print similar to the way homeall.g works.
M584 X0 U3 Y1 V4 Z7:8:9 E2:5:6 P5 ; temporarily separate and map drives to U and V axescomplete the modified gcode part file using separate XYUV axes
M584 X0:3 Y1:4 Z7:8:9 U10 V11 E2:5:6 P3 ; put motor mapping back to normal so that X uses drives 0 and 3 Y uses 1 and 4
then once the printed part is removed from the bed run homeall.g
can you see any problems with this?
Thanks for your help
I can't think of a reason why that wouldn't work. That is to say, it'll allow you to use the DWC buttons to jog all the axes in sync before and after a print, and also run any macros that aren't run during a print.
What I mean by that, is that I use macros to wipe and purge the nozzle, and these macros are called by the slicer gcode as part of the start and end scripts. As the axes are separated before the print starts, then these particular macros have to be modified. But of course, if you don't call any macros from the slicer gcode file that have G1 moves, then you won't need to worry about it.
-
@appjaws Email sent....