what does M400 exactly do?



  • The documentation says M400 waits for current moves to finish, but on the wiki it seems to be used as a "wait for anything to complete". For example in the sensorless homing example it is used after M913 like M400 would wait for the motors to update to the new current.

    So is M400 just waiting for motor moves or much more? If the former, is there a way to actually wait for any task to fully complete or G4 (dwell) would be the only way?



  • @matt3o said in what does M400 exactly do?:

    The documentation says M400 waits for current moves to finish, but on the wiki it seems to be used as a "wait for anything to complete". For example in the sensorless homing example it is used after M913 like M400 would wait for the motors to update to the new current.

    So is M400 just waiting for motor moves or much more? If the former, is there a way to actually wait for any task to fully complete or G4 (dwell) would be the only way?

    Good question.

    I've always taken the Duet documentation as it is stated - that it waits for moves to complete - not configuration commands and the like.

    I've SEEN folks use it to wait for configuration commands to complete and thought it was odd.

    Frederick


  • administrators

    Moves pass through a queue so that a sequence of moves can be executed without stopping between them. That's why commands that affect the motor parameters either wait for all moves to stop before they are executed, or in the few cases where they don't it is advisable to use M400 before them.

    Another way to describe M400 is "wait for move queue to empty".



  • @dc42 said in what does M400 exactly do?:

    ...or in the few cases where they don't...

    JOOC are those few cases intentional or just something that perhaps needs to be fixed?

    Thanks.

    Frederick



  • also is it possible to know what are the commands that actually deplete the queue?

    for example I would expect G90/G91 to do that, same as M913 and M201.

    Thanks



  • just FYI. I checked the source code, neither M913 or M201 execute a M400 automatically (LockMovementAndWaitForStandstill function). Many other Mxxx commands do.


  • administrators

    @matt3o said in what does M400 exactly do?:

    just FYI. I checked the source code, neither M913 or M201 execute a M400 automatically (LockMovementAndWaitForStandstill function). Many other Mxxx commands do.

    M201 doesn't need to because it is a configuration command so it should not be used within a sequence of moves.

    For M913 it is deliberate, so that M913 will take effect instantly if it is used within the power fail script. However, in recent firmware versions, M913 does wait for the movement queue to empty except when it is used within the power fail script.



  • @dc42 said in what does M400 exactly do?:

    M201 doesn't need to because it is a configuration command so it should not be used within a sequence of moves.

    I lower the acceleration during the sensorless homing... is that not recommended?


Log in to reply