GC Dev Help Needed - Notification that Move Complete

Is there a mechanism in GC to get notified after a particular move is complete? For example, if I have a routine that sends the following to the queue:

 self.data.gcode_queue.put("G20 ")
 self.data.gcode_queue.put("G90  ")
 self.data.gcode_queue.put("G17  ")
 self.data.gcode_queue.put("G0 X"+str(posX)+" Y"+str(posY)+"  ")

Is there a way to get a callback, or is there something I can monitor, that let’s me know the sled has moved to that position?

There is not within GroundControl, but you can tail the log.txt file and grep for the trigger you want…

1 Like

Soo… perhaps I can modify the Logger class to perform callbacks on triggers??? hmmm…

I think you should watch for the reply from the firmware, rather than the ‘Sending’ line as that’s closer to when the gcode line is acted on.

Does the firmware send a response that it’s finished a particular move or just reply that it’s got the move command?

Don’t remember, I think it sends each code as it begins to execute it. A line with multiple gcodes gets broken into separate executions and responses. “Sending G20 G91” for instance receives G20 as one response, G91 as a separate line. It’s been a while since I was deep in the log.txt file, but I remember seeing the “Sending” line getting several lines ahead of the execution response.

The response from the firmware is sent at the start of execution.

I’ll play around with it tomorrow. I need to send a move command to a certain spot and then do something after it gets there. I think the trigger/callback on the Logger class will be easy to implement, but I’m new to Python so sorta winging it. Unfortunately, I generally code on my desktop in my house and the Maslow is in the shed. Now I have to switch to a laptop with a 13-inch screen and go out there and code there… I need to extend usb over wifi…

Well, worst case scenario is I put in predefined waits… OR I send another “blank” command after the move command and wait until that shows up… aha!

1 Like

Also beware that if the “Home” coordinates have been moved away from 0,0, the gcode line sent and acknowledged will have the XY coordinates translated into the new coordinate system and won’t match the line in the source file.

Would this help? https://github.com/MaslowCNC/GroundControl/issues/648

1 Like

I think it might but from what I can tell its for calling external scripts (I really don’t understand all that’s in the thread, however). I need to incorporate a call back to a GC function. If it can used for that, then great.

Edit: I reread the post and I don’t think it will fit for what I need. It looks like you edit the gcode to add a special command and when GC reaches a certain point, it fires off a script. What I need is something that watches the messages coming back from the arduino and fires off a callback. This could be done in the logger or the serial thread, I believe. I think I have written a way to do it in the logger, but I need to finish loading up a PC to put out in the shed that I can remote desktop into to see if it works. The thought of extensive coding in a shed just gives me chills. I’ve already have a wifi camera out there so I can watch the sled move (no, the router won’t be on during any remote work for those safety hawks :wink: )

I added a trigger routine to the logger and it works well. You can set a triggerMessage and triggerCallback and when the logger message equals the Tigger message, it calls the callback.