Universal Robots Forum

Reading status of digital inputs at the wrist

I’m developing a new URCap for an actuator directly connected at the wrist of the robot. In the Installation node I’m adding a button to let the user manually test the actuator. Once the button is pressed the URCap sets a digital output at the wrist that triggers and end to end motion of the actuator. When the actuator comes to the end of the stroke (it takes less than a second) an internal proximity sensor is activated and its signal is directly connected at one digital input at the wrist. Similarly, a second proximity sensor is connected to the other digital input at the wrist to detect the other ened of th stroke motion whenever the same initial digital output is reset (i.e. the user presses another button on the UI).
I also have two LEDs on the UI that I want to turn off or on accordingly with the status of the two proximity sensors once the motion is completed.
The problem that I have is that I cannot update properly the UI…I see the LEDs change status only if I move from the Installation node to another TAB of the Polyscope and then back. However, everything works well in case I replace my actuator with a simple manual switch that connects the inputs to the 24Vdc (PNP signals) and I comment out the waiting loop: in this case, if press one the physical switches and the push the button the LEDs are updated correctly at the end of the wait time.
Is it necessary to launch a background script to wait for the motion to complete and then read the digital input state? If so, how can I return the status of the digital inputs from the script ? Using a function? Is there an example code ?
Here below my pseudo-code:

public DigitalIO tool_in1
public DigitalIO tool_out1
if userButton_pressed
{

tool_out1.setValue(true);

//begin of part of code eventually excluded for the physical switches test

long startTime, currentTime, elapsedTime = 0;
startTime = System.currenTimeMillis();

while (!tool_in1.getValue())
{
currentTime=System.currentTimeMillis();
elapsedTime=currentTime-startTime;

if(elapseTime>=MAX_WAIT_TIME)

{
break;
}
}
//end of part of code eventually excluded for the physical switches test

if(tool_in1.getValue())
{
icon.setIcon(LED_on);
icon.repaint()
}
else
{
icon.setIcon(LED_off);
icon.repaint()
}

}

Hello Andrea,

Once you enter the correspondent view, you could start a separate Thread, which checks the status of the inputs periodically and not only if the buttons was pressed. See the openview()-Method of the myDaemonSwing-Example as a reference for the thread.