synthetos / TinyG

Affordable Industrial Grade Motion Control
https://github.com/synthetos/TinyG/wiki
893 stars 293 forks source link

Feature / New G-code commands M114, M115 and M400 added #257

Closed markmaker closed 3 years ago

markmaker commented 3 years ago

grafik WARNING: better use the master branch based #258. The edge-0.98 branch is buggy.

Description

This Pull Request implements the common RS274/NGC/G-code commands M114, M115 and M400.

As a "bonus", a little bug was removed: TinyG should not hang when the P word dwell time is zero.

G4 P0

Justification

TinyG is quite common in OpenPnP usage, mostly because it is the stock controller for the Liteplacer and users often adopt OpenPnP.

M115 Get Firmware Version and Capabilities

OpenPnP is being extended to assist users with more automatism when setting up the Gcode. The first step is automatically identifying the controller/firmware and for many controllers this is done with the M115 code. Discovery is a chicken-and-egg problem: No controller specific commands can be used, before the controller model is known. TinyG having alternative means of identifying itself does not help in this case.

Example:

M115

FIRMWARE_NAME:TinyG, FIRMWARE_URL:https%3A//github.com/synthetos/TinyG, FIRMWARE_VERSION:444.23

M400 Wait for current moves to finish

OpenPnP often needs to interact with the machine. One example: The camera is moved to a location, then Computer Vision is used. Obviously, OpenPnP need to know when the camera is there, before it can take a picture.

In TinyG, there is currently no (known) means to block until moves have finished. OpenPnP is instead polling for status reports, in order to know when a move is done. This only works when status reports are enabled, which generates unsolicited reports in the response stream, which in turn makes it hard to clearly associate responses with commands (race conditions cannot be strictly excluded).

M400 now blocks all further command processing, until the move buffers have drained. This is done with the existing flow-control mechanism: Instead of waiting for the command buffers to not be full, it is waiting for them to be empty.

Example:

G1 X100

M400 ; wait for the move to complete

{sr:n} ; only then execute the status report

It is important to note that the command only affects processing when it is used.

M114 Get current position

To further unify the Gcode setup, the M114 code is also implemented. It reports the current target position in the common format.

Example:

M114

X:100.0000 Y:0.0000 Z:0.0000 A:0.0000 B:0.0000 C:0.0000

Testing

The changes have been tested on a TinyG v8.

markmaker commented 3 years ago

I just found that edge-0.98 does not seem to work. Steps to reproduce:

G91 ; relative mode
G1 X10 F10000
G1 X10
G90

Acceleration seem to be missing on the second move. Tested without my modifications!

I will resubmit this PR based on master.

_Mark

markmaker commented 3 years ago

Please use #258 instead.