cncjs icon indicating copy to clipboard operation
cncjs copied to clipboard

Add a Grbl jogCancel command

Open colincross opened this issue 6 years ago • 12 comments

Grbl v1.1 controllers support additional Extended Ascii Realtime Comands: https://github.com/gnea/grbl/wiki/Grbl-v1.1-Commands#extended-ascii-realtime-command-descriptions

The jogCancel command is sent as the character 0x85, and is useful for implementing Grbl v1.1 jogging: https://github.com/gnea/grbl/wiki/Grbl-v1.1-Jogging

The 0x85 character cannot be sent over socket.io as an argument to the gcode command because it does not form a valid UTF8 byte sequence. Add a jogCancel command that causes CNCjs to send the 0x85 character to the Grbl controller.

colincross avatar Aug 23 '19 04:08 colincross

Coverage Status

Coverage remained the same at 84.697% when pulling 274fcf29ff18e783f0f9e345fccca44b2459ad21 on colincross:grbl_jog_cancel into 88cb3636fa333d0dbbf5036c02f02116992e3661 on cncjs:master.

coveralls avatar Aug 23 '19 05:08 coveralls

This is needed- however, I'm finding scenarios where it isn't cancelling. Other things I've found:

  • feeder.reset()- I'm still figuring out the code, but it seems like it's needed. Not sure about workflow.stop() either?
  • \x85 should be added to GRBL_REALTIME_COMMANDS. (see writeln code)
  • It's helpful to send a comment after the jog cancel. I used (jog cancel).

.. still experimenting.

williamkapke avatar Sep 17 '19 16:09 williamkapke

I updated the pull request with a version that makes the jogCancel command reliable by waiting for unacked feeder commands before sending the 0x85 command.

colincross avatar Apr 03 '20 18:04 colincross

The latest version fixes a typo when running the feeder onEmpty callbacks and a bug when calling onEmpty while the feeder queue was empty. I also added a second patch that pretty prints hex characters, so the jog cancel command prints \x85 in the console instead of ).

colincross avatar Apr 06 '20 02:04 colincross

Any chance of getting this merged in? If there's something blocking it, I'm willing to help contribute if @colincross isn't available.

The change to make 0x85 display in the console is worth it in and of itself:

            data = data.replace(/[^\x20-\x7E]/g, (m) => {
                return '\\x' + m.charCodeAt(0).toString(16);
            });

minglecm avatar Mar 24 '21 08:03 minglecm

This looks really useful, I was just about to look into some jogging with a pendant, so a jog cancel is a requirement to get a smooth implementation.

Would like to see this merged.

bensuffolk avatar Apr 06 '21 21:04 bensuffolk

I've been using this extensively since I uploaded it without any issues.

colincross avatar Apr 07 '21 01:04 colincross

The 0x85 character cannot be sent over socket.io as an argument to the gcode command because it does not form a valid UTF8 byte sequence. Add a jogCancel command that causes CNCjs to send the 0x85 character to the Grbl controller.

This is just an FYI that while studying the CNCjs code, I discovered another way to get the jog command to work without the need to patch CNCjs.

It may be true that the "gcode" command sent via socket.io won't handle the special 0x85 character, but CNCjs does have a "write raw bytes" command that can be used to send arbitrary bytes directly to the serial port, bypassing the feeder, sender, etc:

const io = require('socket.io-client')

const JOG_STOP_CMD = '\x85';

let mySocket = io.connect('ws://' + myHost + ':' + myHostPort, {
            'query': 'token=' + myAccessToken
});

function  rawWrite(data, context = {}) {
       mySocket.emit('write', mySerialPort, data, context)
}

function jogStop() {
     // Send an immediate "jog stop"
    rawWrite(JOG_STOP_CMD);
}

It is important to note that the jog stop command byte will be sent to the serial port immediately upon receipt by the CNCjs server. If there is a jog command queued up in the feeder that has not yet been sent, then things will get out of sequence (i.e. you'll cancel the command before it has been issued). For that reason, I'd still recommend using this PR submitted by @colincross if it works for you. It seems to address many of the sequencing issues one might run into. That being said, if your use case does not allow for a patched version of CNCjs and you'd prefer to work with the code that is out in the wild, the above is another approach.

joelkoz avatar Sep 27 '21 22:09 joelkoz

@colincross any chance you could rebase this?

dwery avatar Feb 07 '22 06:02 dwery

Thank you @colincross , works nicely in my setup. What would be the next step to merge this?

dwery avatar Feb 08 '22 02:02 dwery

@cheton @MitchBradley would it be possible to merge this one?

dwery avatar Mar 23 '22 07:03 dwery

I'm also interested in this for a pendant controller using touch hold-to-jog and it'd be great to have merged!

benvanik avatar May 06 '22 19:05 benvanik