Home› Programming
Discussion
Back to discussions page
StoopidEngineer
Posts: 15 Apprentice
Trouble with scripts apparently not executing within programs |
62 views
|
Answered | |
/ Most recent by matthewd92
in Programming
|
12 comments |

in Programming
Hey All - I'm trying to do some very, very basic gripper control using the built-in digital I/O and am having all sorts of seemingly stupid problems.
To distill the problem as much as possible, I wrote a simple sub-program to open a gripper (set 'close' bit to low, wait, set 'open' bit to high, wait, assign a variable) in the UR GUI which works fine as part of a larger program.
I take the script file of the entire program, steal the sub-program out of it and paste it into a blank script file to create a script that is intended to do what the sub-program did. Because this is the only way I'm aware of to circumvent the inconceivable inability of UR robots to have sub-programs call other sub-programs (and I asked UR about it several times.)
I then turn around and load the script file into the existing program in the GUI to wind up with a script file I should be able to call anywhere I want to execute the previously made sub-program.
The problem that I'm having is that the script seemingly has no impact on the program - as far as I can tell, the controller runs through the script, and it just has no effect on anything. Do I need to redefine variables or input ranges within the script, even though they are unchanged from the main program?
I assume there has to be something really basic and obvious that I'm missing, but I can't seem to figure it out. I appreciate any advice you can offer.
Thanks!
To distill the problem as much as possible, I wrote a simple sub-program to open a gripper (set 'close' bit to low, wait, set 'open' bit to high, wait, assign a variable) in the UR GUI which works fine as part of a larger program.
I take the script file of the entire program, steal the sub-program out of it and paste it into a blank script file to create a script that is intended to do what the sub-program did. Because this is the only way I'm aware of to circumvent the inconceivable inability of UR robots to have sub-programs call other sub-programs (and I asked UR about it several times.)
I then turn around and load the script file into the existing program in the GUI to wind up with a script file I should be able to call anywhere I want to execute the previously made sub-program.
The problem that I'm having is that the script seemingly has no impact on the program - as far as I can tell, the controller runs through the script, and it just has no effect on anything. Do I need to redefine variables or input ranges within the script, even though they are unchanged from the main program?
I assume there has to be something really basic and obvious that I'm missing, but I can't seem to figure it out. I appreciate any advice you can offer.
Thanks!
Best Answer
-
matthewd92 Founding Pro, Tactile Sensor Beta Testers Posts: 1,261 Handy
Good find. Yes, you have to define the function and then “call” the function using script. You can also have the function return a value so instead of setting the global variable in the function definition you could have it return True and using an assignment node assign the function to the variable. That is where functions start becoming powerful.def someFunction() doSomethingHere return True end global answer=someFunction() # after doing something in the function the function would return the value of True allowing me to assign it in a variable or use it in a loop or if statement.
All your functions can be defined once in the before start sequence and then use the functions as many times as you wish by calling them.
Co-Founder | Vanguard Robotics
e: [email protected]
w: vanguard-robotics.com
That said, they do not seem to have impact on the program here where they are defined, or in any of the places where they are called for use.
Co-Founder | Vanguard Robotics
e: [email protected]
w: vanguard-robotics.com
Co-Founder | Vanguard Robotics
e: [email protected]
w: vanguard-robotics.com
Co-Founder | Vanguard Robotics
e: [email protected]
w: vanguard-robotics.com
From what I'm seeing, the scripts that contain the initial definition don't actually 'do' anything in the robot program? I made a program with the 4 sub-programs (open each gripper, close each gripper) followed by those programs in script form, with the script commands detailing out the 'program' and ran it - again, saw the UR GUI sub-programs execute and act as expected, but those were the only thing looping, so I put script commands in the UR GUI to do nothing but call the script files I had just defined, and then (finally) got the program to act the way I thought it should have.
So definitely a learning experience for me, and I can at least feel OK about getting the script files made correctly. I'm apparently just not sharp enough to know how to call them properly.
Thanks guys!