self.command.mdi() - without self.command.wait_complete()

More
3 years 4 months ago #273798 by zz912
Test with wait:
Code:
            self.command.mode(linuxcnc.MODE_MDI)             self.command.wait_complete()             self.command.mdi("G91 G1 X1 F100")             self.command.wait_complete()             self.command.mode(linuxcnc.MODE_MANUAL)             self.command.wait_complete()
 

Attachment not found



Test without wait:
Code:
            self.command.mode(linuxcnc.MODE_MDI)             self.command.wait_complete()             self.command.mdi("G91 G1 X1 F100")             #self.command.wait_complete()             self.command.mode(linuxcnc.MODE_MANUAL)             self.command.wait_complete()
 

Attachment not found

Please Log in to join the conversation.

More
3 years 4 months ago #273799 by zz912

So, how much is the default time delay and can we adjust the time delay?
 
linuxcnc.org/docs/2.9/html/config/python...command_code_methods
Code:
wait_complete([float])
Wait for completion of the last command sent. If timeout in seconds not specified, default is 5 seconds. Return -1 if timed out, return RCS_DONE or RCS_ERROR according to command execution status.

Please Log in to join the conversation.

More
3 years 4 months ago #273895 by newbynobi
Hallo and thanks for staying on this strange behavior.

I do not understand, why the GUI Changes to AUTO Mode in the example without wait complete, as you do not request that mode.
That could also be the reason, that you do not get any movement, as you are in AUTO Mode. But your code tells linuxcnc to change to MDI 

That's really strange.

Norbert

Please Log in to join the conversation.

More
3 years 4 months ago #273896 by zz912
Hello,

I'm glad you noticed that.

My explanation is that if self.command.mdi() is not followed by self.command.wait_complete() then unpredictable LCNC behavior occurs.

What I mean is that there can be widget changer commands after self.command.mdi(), but they must be followed by self.command.wait_complete().

Unfortunately, I have a problem with time right now. I plan to do some more tests. Once these tests confirm or disprove my other theories, I want to define the rules for using the Python Interface.

For example, I want to know how a command run from halui behaves and at the same time a command run from the python interface.

Once I define these rules I will make a PullRequest to edit Gmoccapy.

Zdenek

Please Log in to join the conversation.

More
3 years 4 months ago #274170 by zz912
Hello everybody,

So I found time to test LCNC again. I think the conclusion of the previous test is clear. Not using self.command.wait_complete() can lead to unexpected LCNC behavior. If we wanted to avoid this unpredictable behavior, we just need to add self.command.wait_complete() after each self.command.mdi().

The result of today's test surprised me.

In the gmoccapy.ini file, in the HALUI section, I added:
Code:
MDI_COMMAND = G91 G1 Y1 F10

In the gmoccapy.py file, in the on_tbtn_flood_toggled section, I added:
Code:
            self.command.wait_complete(30)             self.command.mode(linuxcnc.MODE_MDI)             self.command.wait_complete(30)             self.command.mdi("G91 G1 X1 F10")             self.command.wait_complete(30)             self.command.mode(linuxcnc.MODE_MANUAL)             self.command.wait_complete()

Video:
 

Attachment not found



If I run the Python Interface command separately, everything goes fine.

If I run "HALUI - MDI COMMAND" separately, everything goes fine.

If I run the command Python Interface and then run the command "HALUI - MDI COMMAND" the Python Interface and "HALUI - MDI COMMAND" is aborted.

If I do it the other way round I run HALUI - MDI COMMAND and then run Python Interface command "HALUI - MDI COMMAND" is executed and Python Interface is not executed This produces a message: "Must be in MDI mode to issue MDI command".
 

Please Log in to join the conversation.

More
3 years 4 months ago #274203 by zz912
Hello everybody,

I spent the whole day thinking about what to conclude from the previous test.

First half of the test:

If I run the command Python Interface and then run the command "HALUI - MDI COMMAND" the Python Interface and "HALUI - MDI COMMAND" is aborted.

I decided to consider this LCNC behavior and not do anything about it. If one wants to avoid this condition, one runs HALUI MDI-COMMAND via the and2 component and the is-idle pin.

Second half of the test:

If I do it the other way round I run HALUI - MDI COMMAND and then run Python Interface command "HALUI - MDI COMMAND" is executed and Python Interface is not executed This produces a message: "Must be in MDI mode to issue MDI command".

Avoiding this situation is not so simple. All GUIs containing the python interface would have to be rewritten. Therefore, I would like to make a modification of the LCNC source codes.

First I will explain where the problem is.

Now the self.command.wait_complete() function waits for commands from the python interface to complete.

I would like self.command.wait_complete() to wait for commands from python interface to be completed AND to wait for MDI-COMMANDS from HALUI to be completed.

I wanted to write a FIX, but unfortunately I couldn't. I will write what I did to explain my thought process.

Here is code for waiting python commands:
github.com/LinuxCNC/linuxcnc/blob/17208c...cmodule.cc#L212-L231

I edited it like this:
Code:
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) {                 if (halui_sent_mdi == 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);     return -1; }
+
Code:
#include "../../halui.hh"

Now I will explain why I added IF with halui_sent_mdi == 0.
I don't want to use the condition emcStatus->task.interpState == EMC_TASK_INTERP_IDLE.
When HALUI starts MDI-COMMANDS it switches the MDI mode from the default mode and returns to the default mode after executing MDI-COMMANDS.
If we used the condition emcStatus->task.interpState == EMC_TASK_INTERP_IDLE, we could again create an unpredictable LCNC behavior. Again, it might work for some and it would behave randomly for some.
That's why I want to use the variable halui_sent_mdi.
github.com/LinuxCNC/linuxcnc/blob/17208c...r_intf/halui.cc#L253

Since the variable halui_sent_mdi is in a different file than emcmodule.cc, I made halui.hh which contains:
Code:
extern int halui_sent_mdi;

In halui.cc I modified:
Code:
#include "halui.hh"
+
Code:
int halui_sent_mdi = 0;

It could be compiled but could not be run.
Code:
jarda@CNC:~/Plocha$ linuxcnc LINUXCNC - 2.9.0~pre1 Machine configuration directory is '/home/jarda/linuxcnc/linuxcnc-2.9/configs/sim/gmoccapy' Machine configuration file is 'gmoccapy.ini' Starting LinuxCNC... linuxcnc TPMOD=tpmod HOMEMOD=homemod EMCMOT=motmod Note: Using POSIX non-realtime Found file(REL): ./core_sim.hal Found file(REL): ./spindle_sim.hal Found file(REL): ./simulated_home.hal Traceback (most recent call last):   File "/home/jarda/linuxcnc/linuxcnc-2.9/bin/gmoccapy", line 39, in <module>     import hal_glib            # needed to make our own hal pins     ^^^^^^^^^^^^^^^   File "/home/jarda/linuxcnc/linuxcnc-2.9/lib/python/hal_glib.py", line 5, in <module>     import linuxcnc ImportError: /home/jarda/linuxcnc/linuxcnc-2.9/lib/python/linuxcnc.so: undefined symbol: halui_sent_mdi Shutting down and cleaning up LinuxCNC... task: 246 cycles, min=0.000006, max=0.001306, avg=0.000950, 0 latency excursions (> 10x expected cycle time of 0.001000s) Note: Using POSIX non-realtime LinuxCNC terminated with an error.  You can find more information in the log:     /home/jarda/linuxcnc_debug.txt and     /home/jarda/linuxcnc_print.txt as well as in the output of the shell command 'dmesg' and in the terminal

I would like to ask for help.

Please Log in to join the conversation.

More
3 years 3 months ago #274648 by zz912
Hello everybody,

1) Problem self.command.mdi() - without self.command.wait_complete()
I made Pull Request:
github.com/LinuxCNC/linuxcnc/pull/2552
We are currently waiting for Norbert's opinion on this PR.

2) Problem command.wait_complete() dont wait for halui command
I made a separate topic:
forum.linuxcnc.org/38-general-linuxcnc-q...alui-commands#274647

Please Log in to join the conversation.

Time to create page: 0.062 seconds
Powered by Kunena Forum