Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Problem simulating waitDI using API
#1
Hi,

I have some problem when simulating the statement waitDI using the RoboDK API.

I attach a rdk file. In the station there is a python program called "IO Test", is the one I have the issue with. Prog2 is just added to check WaitDI instruction using the GUI (which works fine).

When executing "IO Test" the robot is suposed to wait the activation of some DI during the simulation but it just jumps that instruction. SetDO works properly as I am able to see how outputs change value while simulating.

I will highly appreciate any help with this problem.

Thank you.

Aimar
#2
I think I did not make properly the rdk file attachment. I attach it in this post.


Attached Files
.rdk   IO Test.rdk (Size: 156.58 KB / Downloads: 85)
#3
Hello Aimar,
Thanks for writing in.
RDK.waitDI() function cannot be used from the API, for the time being for simulation purposes. This is something we will definitely improve in the future. However, there is an easy way to go around it.
We can retrieve the Station Parameters using the RDK.getParam('in1') and simulate the DI being made 1 by the user by clicking 'Okay' on the message box pop up. By clicking on 'Cancel', an exception will be raised. Comments in the program below explain further. 

Code:
def WaitForBox():
    """Wait for Digital Input 1 to be 1. This function will work in simulation mode as well as to generate the robot program.
    For simulation, we run the statements under the first 'if' statement which simulate a waitDI and the code under the 'else' statement is used to generate robot program """
    robot.setDO('out1',1)
    di_param = 'in1'
    di_value = 1
    di_timeout = 2 #timeout in seconds
    if RDK.RunMode() == RUNMODE_SIMULATE:
        tstart = time.time()
        while RDK.getParam(di_param) != di_value:
            # If we want a timeout, check the timeout:
            if di_timeout >= 0 and time.time() > (tstart + di_timeout):
                # option to continue:
                if mbox("Digital input timeout: " + di_param + "\nContinue?"):
                    break
                raise Exception("Digital input timeout: " + di_param)
    else:
        robot.waitDI(di_param, di_value)  #added to generate the robot program with waitDI
    robot.setDO('out1',0)


Another important thing here is to check for the RDK.RunMode(), else you wont be able to generate program for the robot. Find attached the .rdk file.

Hope this helps.


Attached Files
.rdk   IO Test.rdk (Size: 156.67 KB / Downloads: 86)
  




Users browsing this thread:
1 Guest(s)