calling globals within macros, bad Idea?
-
@wayneosdias
Is it possible that you're changing the value of the global while there are still unfinished moves queued?
Can you share the macro that is setting the global value? -
@OwenD heres the macro, this works w the globals changed out for consts. I initiate the global in config and modify them via a dedicated calibration macro that is only called once after homing the machine and never when running a job/routine.
;USB_H2_Dispense ;Get head out of way G54 G0 U46 V46 ;Set offset to H2 for the Case G58 M280 P1 S70;{global.Servo2_90} ;1st Point of USB G0 X3.8 Y13.5 G0 V1 ;trigger on G4 P200 G1 V5 F200 ;trigger off G0 X10.5 Y20.7 G0 V1 ;Trigger on G4 P200 G1 X3.8 Y13.5 F600 G1 X10.5 Y20.7 V1.5 G1 X3.8 Y13.5 V2.5 G1 X10.5 Y20.7 V3.5 G1 X3.8 Y13.5 V4.5 G1 X10.5 Y20.7 V5 ;Trigger off G0 V10 M280 P1 S130;{global.Servo2_180} G0 X50 Y14 G0 V1 ;trigger on G4 P200 G1 V5 F200 ;trigger off G0 X44.3 Y22 G0 V1.5 ;trigger on G1 X50 Y14 F600 G1 X43.3 Y22 V1.5 G1 X50 Y14 V2.5 G1 X43.3 Y22 V3.5 G1 X50 Y14 V4.5 G1 X43.3 Y22 V5 ;trigger off G0 V10 M280 P1 S100;{global.Servo2_135} G0 X35.5 Y11.5 G0 V2 ;trigger on G1 X18.5 Y11.5 F600 G1 X35.5 Y11.5 V2.5 G1 X18.5 Y11.5 V3.5 G1 X35.5 Y11.5 V4.5 G1 X18.5 Y11.5 V5 ;trigger off G54 G0 U46 V46
-
@wayneosdias
Nothing jumps out at me.
What happens if you enable debug level logging?
M929
I'm not sure if the result will be the command after the global is calculated or not, but it might offer something. -
@OwenD
Thanks Owen, looks like I have a renegade var lurking somewhere. I renamed several globals accross different macros. I try and find it and correct.2023-01-25 14:32:13 [info] Event logging started at level warn 2023-01-25 14:32:13 [info] Running: Duet 3 Mini5plus WiFi: 3.4.5 (2022-11-30 19:41:16) 2023-01-25 14:40:23 [warn] Error: in file macro line 36 column 15: meta command: variable 'Servo1' already exists 2023-01-25 14:41:05 [info] Event logging stopped
-
You're probably trying to use
global xyz = 123
When it should be
set global.xyz = 123For safety you can use
if !exists(global.xyz) global xyz = 123 else set global.xyz = 123
-
@OwenD
No thats not it, whenever I write to a global I always use 'set'. I scrubbed the bad variable, but Im still having the issue when using the global var. Heres how Im setting the vars, again in only one place and only during the homeing process;if param.A=0 if global.Servo1Cnts>global.Servo1CntsCal set global.Servo1Offsets=global.Servo1Cnts-global.Servo1CntsCal set global.Servo1_180=120+global.Servo1Offsets set global.Servo1_135=90+global.Servo1Offsets set global.Servo1_90=60+global.Servo1Offsets else set global.Servo1Offsets=global.Servo1CntsCal-global.Servo1Cnts set global.Servo1_180=120-global.Servo1Offsets set global.Servo1_135=90-global.Servo1Offsets set global.Servo1_90=60-global.Servo1Offsets else if global.Servo2Cnts>global.Servo2CntsCal set global.Servo2Offsets=global.Servo2Cnts-global.Servo2CntsCal set global.Servo2_180=120+global.Servo2Offsets set global.Servo2_135=90+global.Servo2Offsets set global.Servo2_90=60+global.Servo2Offsets else set global.Servo2Offsets =global.Servo2CntsCal-global.Servo2Cnts set global.Servo2_180=120-global.Servo2Offsets set global.Servo2_135=90-global.Servo2Offsets set global.Servo2_90=60-global.Servo2Offsets
Later in macros I use the global as
M280 P1 S{global.Servo2_180} ;
Whats more is the issue isnt aberrant like I thought at first. When I use a global for M280 it executes M280 3-4 steps early. The move/postion the servo moves to isnt erratic, it moves the next position, everytime. It's like the motion planner executes the command as it prefetches and sticks it into the queue. Again only with the globals, not w a constant.
Its weird.
-
@wayneosdias
On your previous post it appeared you used "warn" level debugging
What doesM929 P"myLog.txt" S3 ; ; do your thing M929 S0
Reveal?
I'd expect to see the commands in order of processing
-
@OwenD
M929 P"eventlogGlobal.txt" S3 ;
Here the response using constants2023-01-25 17:22:07 [info] Event logging started at level debug 2023-01-25 17:22:07 [info] Running: Duet 3 Mini5plus WiFi: 3.4.5 (2022-11-30 19:41:16)
Here the response using after changing to globals globals
2023-01-25 17:22:07 [info] Running: Duet 3 Mini5plus WiFi: 3.4.5 (2022-11-30 19:41:16) 2023-01-25 17:26:53 [info] Event logging stopped 2023-01-25 17:26:53 [info] Event logging started at level debug 2023-01-25 17:26:53 [info] Running: Duet 3 Mini5plus WiFi: 3.4.5 (2022-11-30 19:41:16)```
-
@wayneosdias
sorry let me redo w the commands inline w the macro and not in the console
this is all I see in the eventlog2023-01-25 14:41:05 [info] Event logging started at level warn 2023-01-25 14:41:05 [info] Running: Duet 3 Mini5plus WiFi: 3.4.5 (2022-11-30 19:41:16) 2023-01-25 15:00:51 [info] Event logging stopped 2023-01-25 17:22:07 [info] Event logging started at level debug 2023-01-25 17:22:07 [info] Running: Duet 3 Mini5plus WiFi: 3.4.5 (2022-11-30 19:41:16) 2023-01-25 17:26:53 [info] Event logging stopped 2023-01-25 17:26:53 [info] Event logging started at level debug 2023-01-25 17:26:53 [info] Running: Duet 3 Mini5plus WiFi: 3.4.5 (2022-11-30 19:41:16) 2023-01-25 17:32:11 [info] Event logging stopped 2023-01-25 17:32:11 [info] Event logging started at level debug 2023-01-25 17:32:11 [info] Running: Duet 3 Mini5plus WiFi: 3.4.5 (2022-11-30 19:41:16) 2023-01-25 17:32:40 [info] Event logging stopped
-
@wayneosdias
Are you running just the macro that sets the globals, or the movement one as well?
I was expecting to see G1 commands ETS in the log, but I could be wrong. Haven't tried logging for a while. -
@OwenD Heres what Im running is exactly what Im running
M929 P"eventlogGlobal.txt" S3 ; ;USB_H2_Dispense ;Get head out of way G54 G0 U46 V46 ;Set offset to H2 for the Case G58 M280 P1 S{global.Servo2_90};70; ;1st Point of USB G0 X3.8 Y13.5 G0 V1 ;trigger on G4 P200 G1 V5 F200 ;trigger off G0 X10.5 Y20.7 G0 V1 ;Trigger on G4 P200 G1 X3.8 Y13.5 F600 G1 X10.5 Y20.7 V1.5 G1 X3.8 Y13.5 V2.5 G1 X10.5 Y20.7 V3.5 G1 X3.8 Y13.5 V4.5 G1 X10.5 Y20.7 V5 ;Trigger off G0 V10 M280 P1 S{global.Servo2_180};130; G0 X50 Y14 G0 V1 ;trigger on G4 P200 G1 V5 F200 ;trigger off G0 X44.3 Y22 G0 V1.5 ;trigger on G1 X50 Y14 F600 G1 X43.3 Y22 V1.5 G1 X50 Y14 V2.5 G1 X43.3 Y22 V3.5 G1 X50 Y14 V4.5 G1 X43.3 Y22 V5 ;trigger off G0 V10 M280 P1 S{global.Servo2_135};100; G0 X35.5 Y11.5 G0 V2 ;trigger on G1 X18.5 Y11.5 F600 G1 X35.5 Y11.5 V2.5 G1 X18.5 Y11.5 V3.5 G1 X35.5 Y11.5 V4.5 G1 X18.5 Y11.5 V5 ;trigger off G54 G0 U46 V46 M929 S0 ;
Im executing it via
M98 P"/macros/USB_H2_Dispense"
In the console
-
@wayneosdias
Ok.
I thought debug level gave more than that.
I wasted your time on that one sorry.
The only time I've had the codes appear to execute out of order was when there were errors
Have you got the latest firmware build for the mini 5?
There was an error with an incorrect file a little while back if you didn't use the zip bundleOutside that I'm a bit stumped.
-
@wayneosdias
Heres what Im doing https://youtu.be/FzovkhonvkI
In the vid is correct movment using constants, changing the constants to globals as the above posted macro the 2nd and 3rd rotation trigger 3 movements early. I can take another video, but it wont have tray loaded because it crashes... -
@OwenD
No I think youre right. I have and HC6 in a pick and place machine and debug reports everything... Im not sure why the mini 5 is not... -
@wayneosdias said in calling globals within macros, bad Idea?:
When I use a global for M280 it executes M280 3-4 steps early.
When you don't use a global in the M280 command, the command is put in the deferred command queue and executed after all previous movement commands have completed. When you use a global in the M280 command, it isn't put in the deferred command queue, because the variables you refer to may not be available in that context, and in any case they might change before the command is executed. So the M280 command is executed immediately.
If you put a M400 command before the M280 command, it will wait for motion to complete before the M280 command is executed.
-
@dc42 Yes, M400 resolves the issue. Thank you
-
-
-
@dc42 said in calling globals within macros, bad Idea?:
@wayneosdias said in calling globals within macros, bad Idea?:
When I use a global for M280 it executes M280 3-4 steps early.
When you use a global in the M280 command, it isn't put in the deferred command queue, because the variables you refer to may not be available in that context, and in any case they might change before the command is executed. So the M280 command is executed immediately.
@dc42
That's very interesting.
Are there other command in particular that would behave this way if a global variable was used as one of the parameters? -
@OwenD yes some other commands such as M106 M42 M300 and M150 will behave in this way.
-
@dc42 Hmm, So what is best pratice for the following end use;
I have 2 Servos and 4 selonoid(2ch pos/vac pneumatic control);
;Servos M950 S0 C"io1.out" ;"Servo1" M950 S1 C"io3.out" ;"Servo2" M950 P2 C"out1" ;"Valve_Mstr" M950 P3 C"out2" ;"Valve_Ch_Slct" M950 P3 C"out3" ;"Valve_Ch1_Vac" M950 P3 C"out4" ;"Valve_Ch2_Vac"
Im empirically generating my own tool paths and attempting to trigger timed valve sequences and things gets very confusing/later unreadable using the following syntax;
G1 Xmove Ymove M280 P0 S100; Spin servo1 90deg M42 P2 S1; +Pressurize Ch1. G4 P200 ; Dwell stabilize. G1 Xmove Ymove M42 P4 S1; Retract G4 P200 ; Dwell stabilize. M42 P2 S0; Depressurize.
Since I cant find a way to use/call tool names in gcode created via M563 Im creating globals for literals to replace tool indexes and using in a const manner.
global Servo1=0 global Servo2=1 global Valve_Mstr=2 global Valve_Ch_Slct=3 global Valve_Ch1_Vac=4 global Valve_Ch2_Vac=5
Which is much make macro more readable as;
G1 Xmove Ymove M280 P{global.Servo1} S{global.Servo1_90}; Spin servo1 90deg M42 P{global.Valve_Mstr} S1; +Pressurize. G4 P200 ; Dwell stabilize. G1 Xmove Ymove M42 P{global.Valve_Ch_Slct} S1; Retract G4 P200 ; Dwell stabilize. M42 P{global.Valve_Ch1_Vac} S; Depressurize.
But doing the above every M280 or M42 will require a M400 command preceeding it? Am I going about this completely wrong? What is best practice to accomplish this?
-
@wayneosdias ideally RRF would evaluate all expressions in the command, then put the command in the deferred command queue with those expressions replaced by values. I'll add this to the RRF work list.