Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
This sample implements a Java class to:
- Send URScript commands for immediate execution by URControl
- Extract a variable from URScript to Java
- Proxy URScript functions to Java

Check out the package ["com.jbm.urcap.sample.scriptCommunicator.communicator"](https://github.com/BomMadsen/URCap-ScriptCommunicator/tree/master/com.jbm.urcap.sample.scriptCommunicator/src/main/java/com/jbm/urcap/sample/scriptCommunicator/communicator).
You can run "InterfaceTester.java" to try out the features.
Expand Down
22 changes: 20 additions & 2 deletions com.jbm.urcap.sample.scriptCommunicator/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@

<groupId>com.jbm.urcap.sample</groupId>
<artifactId>scriptCommunicator</artifactId>
<version>1.0-SNAPSHOT</version>
<name>scriptCommunicator</name>
<version>${git.commit.id.describe}</version>
<name>scriptCommunicator</name>
<packaging>bundle</packaging>

<properties>
Expand Down Expand Up @@ -43,6 +43,24 @@

<build>
<plugins>
<plugin>
<groupId>pl.project13.maven</groupId>
<artifactId>git-commit-id-plugin</artifactId>
<version>3.0.0</version>
<executions>
<execution>
<id>get-the-git-infos</id>
<goals>
<goal>revision</goal>
</goals>
<phase>validate</phase>
</execution>
</executions>
<configuration>
<dotGitDirectory>${project.basedir}/.git</dotGitDirectory>
</configuration>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,27 +1,138 @@
package com.jbm.urcap.sample.scriptCommunicator.communicator;

import com.ur.urcap.api.domain.value.Pose;
import com.ur.urcap.api.domain.value.PoseFactory;
import com.ur.urcap.api.domain.value.Position;
import com.ur.urcap.api.domain.value.Rotation;
import com.ur.urcap.api.domain.value.simple.Angle;
import com.ur.urcap.api.domain.value.simple.Length;
import com.ur.urcap.api.domain.value.simple.Length.Unit;


public class InterfaceTester {

/**
* This class can be used to test the Exporter and Sender
* Hit the Play button in your IDE, to execute this
*
*/
private static class TestPose implements Pose{
private double x;
private double y;
private double z;
private double rx;
private double ry;
private double rz;
private Length.Unit lengthUnit;
private Angle.Unit angleUnit;

TestPose(double x, double y, double z, double rx, double ry, double rz, Length.Unit lengthUnit,
Angle.Unit angleUnit) {
this.x = x;
this.y = y;
this.z = z;
this.rx = rx;
this.ry = ry;
this.rz = rz;
this.lengthUnit = lengthUnit;
this.angleUnit = angleUnit;
}

@Override
public Position getPosition() {
// TODO Auto-generated method stub
return null;
}

@Override
public Rotation getRotation() {
// TODO Auto-generated method stub
return null;
}

@Override
public double[] toArray() {
// TODO Auto-generated method stub
return null;
}

@Override
public double[] toArray(Unit lengthUnit, Angle.Unit angleUnit) {
// TODO Auto-generated method stub
return null;
}

@Override
public boolean epsilonEquals(Pose other, double epsilon) {
// TODO Auto-generated method stub
return false;
}

@Override
public boolean epsilonEquals(Pose other, double lengthEpsilon, Unit lengthUnit, double angleEpsilon,Angle.Unit angleUnit) {
// TODO Auto-generated method stub
return false;
}

@Override
public String toString() {
return new String("p["+x+","+y+","+z+","+rx+","+ry+","+rz+"]");

}

}
private static class TestPoseFactory implements PoseFactory{

@Override
public Pose createPose(double x, double y, double z, double rx, double ry, double rz, Length.Unit lengthUnit,
Angle.Unit angleUnit) {
return new TestPose( x, y, z, rx, ry, rz, lengthUnit, angleUnit);
}

}

public static void main(String[] args) {
/**
* Testing Sender
*/

ScriptSender sender = new ScriptSender();

ScriptCommand senderCommand = new ScriptCommand("SenderCommand");
senderCommand.appendLine("textmsg(\"Add something to the logfile...\")");

senderCommand.setAsSecondaryProgram();
sender.sendScriptCommand(senderCommand);

/**
* Testing Proxy
*/
PoseFactory poseFactory = new TestPoseFactory();
ScriptTypeConverter typeConverter = new ScriptTypeConverter(poseFactory);
ScriptProxy proxy = new ScriptProxy(typeConverter);
Double acos = proxy.acos(0.6);
//test against java
System.out.println("Double acos result is: "+ acos);

proxy.set_digital_out(5, true);
System.out.println("dig in result is: "+ proxy.get_configurable_digital_in(6));

System.out.println("force result is: "+ proxy.force());

Pose actualTCP = proxy.get_actual_tcp_pose();
System.out.println("actual TCP pose result is: "+ actualTCP);
Pose invActualTCP = proxy.pose_inv(actualTCP);
System.out.println("inverted actual TCP pose result is: "+ invActualTCP);
Pose zeroPose = proxy.pose_trans(actualTCP, invActualTCP);
System.out.println("zeroPose pose result is: "+ zeroPose);





/**
* Testing Exporter
*/

ScriptExporter export = new ScriptExporter();

ScriptCommand commandString = new ScriptCommand("Command1");
Expand All @@ -36,6 +147,7 @@ public static void main(String[] args) {

int resultInt = export.exportIntegerFromURScript(commandInt, "var_1");
System.out.println("Integer result is: "+resultInt);

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public String exportStringFromURScript(ScriptCommand command, String variable_na
return reply;
}

private ScriptCommand buildScriptCommandToExport(ScriptCommand command, String variable_name) {
protected ScriptCommand buildScriptCommandToExport(ScriptCommand command, String variable_name) {
// Change to secondary program
command.setAsSecondaryProgram();

Expand All @@ -104,12 +104,11 @@ private ScriptCommand buildScriptCommandToExport(ScriptCommand command, String v
return command;
}

private String readValueFromRobot(ScriptCommand commandWithReturn) {
protected String readValueFromRobot(ScriptCommand commandWithReturn) {
String input = "";
try{
// Create return socket
ServerSocket server = new ServerSocket(RETURN_PORT);

ScriptSender sender = new ScriptSender(SEND_IP);
sender.sendScriptCommand(commandWithReturn);

Expand Down
Loading