bdring / FluidNC

The next generation of motion control firmware
Other
1.62k stars 386 forks source link

Feature: Get GRBL version printout #1300

Open ColPaulR opened 2 months ago

ColPaulR commented 2 months ago

Machine Context

FluidNC on TinyBee connected to CNCjs

Feature Description

BLUF: Is there a reason or motivation to not send the startup string with the "$SS" command?

The only way I can get CNCjs to initialize is to execute a soft reset. CNCjs is looking for the "GRBL vx.x" or something similar at the start of a line before it resets. The only way I can find to get FluidNC to send that message from function report_init_message, is to execute a soft reset (what CNCjs wants me to do). I get extremely nervous about losing my position registration doing a soft reset just to get the gcode sender initialized. I read in the wiki that FluidNC is not supposed to lose position if there is no motion while soft reseting.

I added the function report_init_message to showStartupLog to get the "GRBL vx.x" string by command without a reset. CNCjs seems happy. Is there a downside to putting the startup message in the $SS command in the next version? If so, what about a command to echo the startup message from the console (maybe "$SV" for show version)?

Happy to make the changes and execute a push request if one of these approaches is consistent with FluidNC's design vision

Other Approaches

Lots of changes within CNCjs to get GRBL version/startup message without a reset

How I Can Help

Happy to make the changes and execute a push request if one of these approaches is consistent with FluidNC's design vision

MitchBradley commented 2 months ago

There is one potential problem that I can think of. Historically, the appearance of a Grbl signon message is an indication that the controller is in the state that exists after a reset. A UI agent that decodes messages could infer something that is not correct when it sees such a message. This could be mitigated to some extent by issuing the response only on the channel that requested it, so it only be seen by UI agents that explicitly ask by using the new command. It would be up to such agents to modify their interpretation of the message according to whether or not they issued the command. In the case of cncjs, I don't see any obvious problems. The code appears to be (in various files in src/server/controllers/Grbl/):

class GrblLineParserResultStartup {
    // Grbl 0.9j ['$' for help]
    // Grbl 1.1d ['$' for help]
    // Grbl 1.1
    // Grbl 1.1h: LongMill build ['$' for help]
    // Grbl 1.1h ['$' for help] LongMill build Feb 25, 2020
    // gCarvin 2.0.0 ['$' for help]
    static parse(line) {
        const r = line.match(pattern);
        if (!r) {
            return null;
        }

        const firmware = r[1];
        const version = r[2];
        const message = _trim(r[3]);

        const payload = {
            firmware,
            version,
            message,
        };

        return {
            type: GrblLineParserResultStartup,
            payload: payload
        };
    }
}
...
        if (type === GrblLineParserResultStartup) {
            const { version } = payload;
            const nextSettings = { // enforce change
                ...this.settings,
                version: version
            };
            if (!_.isEqual(this.settings.version, nextSettings.version)) {
                this.settings = nextSettings; // enforce change
            }
            this.emit('startup', payload);
            return;
        }
...
        this.runner.on('startup', (res) => {
            this.emit('serialport:read', res.raw);

            // The startup message always prints upon startup, after a reset, or at program end.
            // Setting the initial state when Grbl has completed re-initializing all systems.
            this.clearActionValues();

            // Set ready flag to true when a startup message has arrived
            this.ready = true;

            if (!this.initialized) {
                this.initialized = true;

                // Initialize controller
                this.initController();
            }
        });
...
    async initController() {
        // https://github.com/cncjs/cncjs/issues/206
        // $13=0 (report in mm)
        // $13=1 (report in inches)
        this.writeln('$$');

        await delay(50);
        this.event.trigger('controller:ready');
    }

I think a good name would be $Grbl/Show AKA $GS