MarlinFirmware / Marlin

Marlin is an optimized firmware for RepRap 3D printers based on the Arduino platform. Many commercial 3D printers come with Marlin installed. Check with your vendor if you need source code for your specific machine.
https://marlinfw.org
GNU General Public License v3.0
16.18k stars 19.21k forks source link

[FR] Check movement is done #26496

Open veyselolgun opened 9 months ago

veyselolgun commented 9 months ago

Hello,

Nema17 Step motor fast but M400 command give me a longer time

I move step motor 1 micrometer (with microstepping) and I am checking complete of my movement with M400 command, it give 0.1 second. I command motor to move 1 micrometer without using M400 then it is fast, i see it, but if i don't use M400 command, weird things happening

Here is simple timing script:

device.serial.write("G91\n".encode())
while 1:
    data = device.serial.readline()
    if data == b"ok\n":
        break

s=time.perf_counter()
for i in range(25):
    device.serial.write(b"G1 Z0.001\n") # move up 1 micrometer (0.001 mm)
    device.serial.write(b"M400\n")      # wait for current move finish
    c = 0
    while 1:
        data = device.serial.readline()
        print(data)
        if data== b'ok\n':
            c += 1
        if c == 2:  # "ok" message will return after "G1 Z0.001" and "M400" command
            break
print(time.perf_counter()-s)

This code give me 2.5 seconds for moving 25 micrometer 1 micrometer by 1micrometer. If I do not use M400 to check finishing the moves, my movement operation is very fast but some time later, position lost, and some time later it quickly move to X/Y home direction if I give X or Y axis command

I have opened an issues in discussion forums also discord but no luck, here is the relevant links, https://reprap.org/forum/read.php?415,893427 https://reprap.org/forum/read.php?415,891827,891829#msg-891829

Are you looking for hardware support?

My control card is MKS Robin Nano v3.0, my step motor driver TMC2209

Describe the feature you want

I just want to know how M400 work and why 1 micrometer moving operation take 0.1 second

Additional context

Please see these videos

1) This video shows autofocus and scan operation with M400 command link

2) This video shows autofocus and scan operation without M400 command link

3) This video shows only 5 times autofocus operation with M400 command link

4) This video shows only 5 times autofocus operation without M400 command link

As you see in the second video, Z axis position lost and some later time it moves to Y home. (After when I send G1 Y0.7 F1000 command) this happens at random time

ellensp commented 9 months ago

standard gcode is received decoded and moves are enqueued into the planner queue. The ok response is given. before the move is executed.

M400 waits for entire planer queue to be emptied

veyselolgun commented 9 months ago

First of all, thank you for fast reply @ellensp

Then how can I check moves finished ? Did I use different G-code ? I believe step motor complete 1 micrometer movement under 10ms, am I wrong ?