Hi,
I am trying to write a URCap that can read and display the status of digital outputs. I used the mytoolbar example, to create a toolbar that displays the status of the outputs.
For the beginning I just displayed JLabels and JPanels to show status lights in gray (off) and blue (on). For now I control the status of all status lights via a single boolean variable. Later I plan to use an array to display diffrent states, but for now I just want to try one output.
Then I tried to orient the Script part of the URCap by the LightUp example from the “my first urcap” article (> Universal Robots - URCap - My First URCap). There I saw that the “set_standard_digital_out()” is used and I thoght that than there must be an “get_standard_digital_out()”. A look in the scriptManual Page 87 (> Universal Robots - Script manual - e-Series - SW 5.11 ) showed that there is exactly this command and it returns a boolean, but I had no idea how to save the return value in a variable.
Then I found out that I get no return value when implemented this way. More research showed me that I’d need to use rtde but I have no Idea how to implement it.
Basically you need to connect to the port 30004 and retrieve the info from it with the help from rtde library.
The big issue I see here is that the RTDE library is only available in Python, meaning you would have to either convert the library to Java manually or use the Python code and wrap it in the URCap similar to this example.
See here that the register in port 1 is the outputs (the standard IO), it is an int number, where the bit 0 is the output 0, bit 1 is output 1 and so on:
Since you can already make your URCap write URScript, I would recommend to try this approach. Also in URScript you can create a MODBUS signals (see modbus_add_signal).
You can actually access the physical IO directly from Java.
import java.util.Collection;
import java.util.Iterator;
import com.ur.urcap.api.domain.io.DigitalIO;
import com.ur.urcap.api.domain.io.IO;
import com.ur.urcap.api.domain.io.IOModel;
import com.ur.urcap.api.domain.io.ModbusIO;
/*
* A library class for getting the IO on the robot
*/
public class IOHelper {
private final IOModel ioModel;
public IOHelper(final IOModel ioModel) {
this.ioModel = ioModel;
}
public DigitalIO[] getDigitalInputs() {
final Collection<DigitalIO> ioCollection = ioModel.getIOs(DigitalIO.class);
ioCollection.removeIf(n -> !n.isInput());
final int inputSize = ioCollection.size();
final Iterator<DigitalIO> itr = ioCollection.iterator();
final DigitalIO[] inputList = new DigitalIO[inputSize];
for (int i = 0; i < inputSize; i++) {
inputList[i] = itr.next();
}
return inputList;
}
public DigitalIO[] getDigitalOutputs() {
final Collection<DigitalIO> ioCollection = ioModel.getIOs(DigitalIO.class);
ioCollection.removeIf(DigitalIO::isInput);
final int outputSize = ioCollection.size();
final Iterator<DigitalIO> itr = ioCollection.iterator();
final DigitalIO[] outputList = new DigitalIO[outputSize];
for (int i = 0; i < outputSize; i++) {
outputList[i] = itr.next();
}
return outputList;
}
public ModbusIO[] getModBusInputs() {
final Collection<ModbusIO> ioCollection = ioModel.getIOs(ModbusIO.class);
ioCollection.removeIf(n -> !n.isInput());
final int inputSize = ioCollection.size();
final Iterator<ModbusIO> itr = ioCollection.iterator();
final ModbusIO[] inputList = new ModbusIO[inputSize];
for (int i = 0; i < inputSize; i++) {
inputList[i] = itr.next();
}
return inputList;
}
public ModbusIO[] getModBusOutputs() {
final Collection<ModbusIO> ioCollection = ioModel.getIOs(ModbusIO.class);
ioCollection.removeIf(ModbusIO::isInput);
final int outputSize = ioCollection.size();
final Iterator<ModbusIO> itr = ioCollection.iterator();
final ModbusIO[] outputList = new ModbusIO[outputSize];
for (int i = 0; i < outputSize; i++) {
outputList[i] = itr.next();
}
return outputList;
}
public DigitalIO getSpecificDigitalIO(final String defaultName) {
final Collection<DigitalIO> ioCollection = ioModel.getIOs(DigitalIO.class);
final int ioCount = ioCollection.size();
if (ioCount > 0) {
final Iterator<DigitalIO> ioItr = ioCollection.iterator();
while (ioItr.hasNext()) {
final DigitalIO thisIO = ioItr.next();
final String thisDefaultName = thisIO.getDefaultName();
if (thisDefaultName.equals(defaultName)) {
return thisIO;
}
}
}
return null;
}
public IO getSpecificGPIO(final String defaultName) {
final Collection<IO> ioCollection = ioModel.getIOs();
final int ioCount = ioCollection.size();
if (ioCount > 0) {
final Iterator<IO> ioItr = ioCollection.iterator();
while (ioItr.hasNext()) {
final IO thisIO = ioItr.next();
final String thisDefaultName = thisIO.getDefaultName();
if (thisDefaultName.equals(defaultName)) {
return thisIO;
}
}
}
return null;
}
public ModbusIO getSpecificModBusIO(final String signalName) {
final Collection<ModbusIO> ioCollection = ioModel.getIOs(ModbusIO.class);
final int ioCount = ioCollection.size();
if (ioCount > 0) {
final Iterator<ModbusIO> ioItr = ioCollection.iterator();
while (ioItr.hasNext()) {
final ModbusIO thisIO = ioItr.next();
final String thisSignalAddress = thisIO.getName();
if (thisSignalAddress.equals(signalName)) {
return thisIO;
}
}
}
return null;
}
}
Here’s the contents of the class file called IOHelper. I’m sure I found this on the forum years ago.
Then in your toolbar file, declare an instance of the class
private final IOHelper ioHelper;
And assign it a value in the constructor:
ioHelper = new IOHelper(context.getAPIProvider().getApplicationAPI().getIOModel());
Now you can just directly declare DigitalIO:
DigitalIO myOutput;
And assign it to the actual IO using the IOHelper:
Thank you very much. Your solution worked best for me until now.
Eclipse shows no error messages.
I only get error messages when typing
mvn install -P ursim
into the terminal.
It says:
[ERROR] (use -source 8 or higher to enable lambda expressions)
[ERROR] /home/ur/workspace/com.ur.urcap.examples.mytoolbar/src/main/java/com/ur/urcap/examples/IOHelper.java:[35,50] method references are not supported in -source 1.6
So I am now trying to replace the lambda expressions.
Better Ideas are welcome.
I am keeping you up to date.
I would probably just update your source to support lambda expressions. Been a while since I’ve done it, but you should be able to just go to the .pom file and change the 1.6 to 1.8 in the