WARNING - Python WaitCommandComplete timed out

More
24 Mar 2024 21:11 - 24 Mar 2024 21:13 #296649 by zz912
Hello,

Few people know that the command self.command.wait_complete() has a time limit that can be set and the default value is 5seconds.
            self.command.wait_complete()
            self.command.mode(linuxcnc.MODE_MDI)
            self.command.wait_complete()
            self.command.mdi("G91 G1 X10 F200")
            self.command.wait_complete(2)
            self.command.mdi("G91 G1 Y10 F200")
            self.command.wait_complete()           
            self.command.mode(linuxcnc.MODE_MANUAL)
            self.command.wait_complete()

The problem is that if this limit is exceeded, the source code continues and there is no warning.
I was able to create two kinds of warnings.

1) silent warning with fprintf. If the time limit is exceeded, the source code continues, but at least an error note appears in the terminal.
 
2) drastically stop the code with PyErr_Format
 
I would like to make a Pull Request, but I don't know which option to choose. Can any of you think of another option?

github.com/LinuxCNC/linuxcnc/blob/master...ns/emcmodule.cc#L213
static int emcWaitCommandComplete(pyCommandChannel *s, double timeout) {
    double start = etime();

    do {
        double now = etime();
        if(s->s->peek() == EMC_STAT_TYPE) {
           EMC_STAT *stat = (EMC_STAT*)s->s->get_address();
           int serial_diff = stat->echo_serial_number - s->serial;
           if (serial_diff > 0) {
                return RCS_DONE;
           }
           if (serial_diff == 0 &&
               ( stat->status == RCS_DONE || stat->status == RCS_ERROR )) {
                return stat->status;
           }
        }
        esleep(fmin(timeout - (now - start), EMC_COMMAND_DELAY));
    } while (etime() - start < timeout);
    PyErr_Format( error, "Python WaitCommandComplete timed out");
    //fprintf(stderr,"Error - Python WaitCommandComplete timed out \n");
    return -1; [attachment=60361]fprintf.png[/attachment]
Attachments:
Last edit: 24 Mar 2024 21:13 by zz912.

Please Log in or Create an account to join the conversation.

More
25 Mar 2024 04:55 - 25 Mar 2024 04:57 #296683 by cmorley
Why don't you check for the error in the python code?
result = self.command.wait_complete(timeout)
if result == -1:
       print( 'Command timed out: ({} second)'.format(timeout))
Last edit: 25 Mar 2024 04:57 by cmorley.

Please Log in or Create an account to join the conversation.

More
25 Mar 2024 09:36 #296703 by zz912

Why don't you check for the error in the python code?

result = self.command.wait_complete(timeout)
if result == -1:
       print( 'Command timed out: ({} second)'.format(timeout))

When you know that a time out problem will occur, you can solve it like this. However, a situation happened to me when the program was behaving randomly. It was only after much searching that I found out that WaitCommandComplete has a timeout. I'll be on the lookout for it forever. I would like other developers to be aware of this while debugging their programs. I think it can be very dangerous for moving (eg self.command.mdi("G91 G1 Y10 F200") ). Movements up to 5s are fine. For movements above 5s, the developer will notice that something is weird. Moves lasting 5s will behave randomly.

Please Log in or Create an account to join the conversation.

More
25 Mar 2024 13:11 #296715 by JT
I don't use command.wait_complete() on MDI commands because it stops the program at that point until the command completes. No status will update in your GUI because it acts like a time.sleep() and stops processing.

JT

Please Log in or Create an account to join the conversation.

Time to create page: 0.150 seconds
Powered by Kunena Forum