Universal Robots Forum

Rising and falling edge in Polyscope

# Summary

Ability to use rising and falling edge detection when programming in Polyscope.

# What is it?

The ability to check for a rising or falling edge, e.g. when using the expression editor.
It could be 2 extra butons in the expression edtior, which would make this really easy and accessible.

Something like this:
UR_EE

# Why is it needed?

It would give a bit more power and flexibility to Polyscope programming, without the need of a PLC.

I currently have a project where it would be so much easier to just have an event that checks for a rising edge on an input and then sets a single pulse on an output - once.

Event:
digital_in[1] REdge - set digital_out[1] for 500ms
(just as an explanation, I don’t know polyscope script)

Here’s a script that does what you’re asking. You can just change the input, output, and duration variables to whatever you need. I do agree, having them built in would sure be handy.

thread risingEdge():

input = 1
output = 1
outputDuration = 0.5

while(True):
while(not get_digital_in(input)):
sync()
end
set_digital_out(output, True)
sleep(outputDuration)
set_digital_out(output, False)
while(get_digital_in(input)):
sync()
end
end
end

thrd = run risingEdge()

Thanks alot for this!

As I am fairly new to this, is it possible to define the variables when calling the thread?
If I recall correctly you can not do something like thrd = run rising Edge(1,1,0.5)?

Correct, you cannot pass parameters into a thread. However, you could define these 3 variables as installation variables, thus making them globally accessible in your program. From there you could write a script function like setRisingEdge(input, output, duration) and call this function in your program. It could then change the variables being looked at in the thread.

This also might have some negative side effects that I’m not seeing right now, but it might be worth a try!

Thanks, will have a try at that!

As I have no access to the robot at the moment, would something like this work?

def risingEdge(IN, OUT, DURATION):
	thread risingEdge():
		input = IN
		output = OUT
		outputDuration = DURATION
		while(True):
			while(not get_digital_in(input)):
				sync()
			end
			set_digital_out(output, True)
			sleep(outputDuration)
			set_digital_out(output, False)
			while(get_digital_in(input)):
				sync()
			end
		end
	end
end

Hmm I put this in on my simulator and found an interesting result. Variables set inside the thread do not see the variables passed into the function. They appear to be out of scope. Running your code as is throws an error that the IN, OUT, and DURATION are not defined. You can set these in the installation, and then it will run, but the value will not be changed regardless of what is passed into the function.

So in short, it appears that no, that will not work.

I’m not totally sure on your use case, but you CAN make them installation variables and then just change these programmatically. Below, I’ve setup “input” and “output” as installation variables. These are globally scoped, so even the thread can see them.

You’ll notice the script is slightly different, as I’m not actually looking at any inputs, but rather all outputs. This is just so I can test it on my simulator. With this script, you are able to toggle output 1 ON to see output 2 pulse for half a second. Then after the 2 second wait, the “input” gets changed to 5. Now toggling output 5 will toggle output 2 for half a second.

Thanks for all your efforts!

As I only need to monitor 1 input for my current project I will just hard code it.
It would have been interesting for possible future projects to have a rising edge function defined that can be used multiple times with different inputs.

Thanks again!