Universal Robots Forum

How to use force mode in a URCap?

I am trying to activate force mode in my URCap without going into execution mode, while a signal is active.
I tried to do it using a socket in the following way, but I have not had good results:

// Create a new Socket Client
Socket sc = new Socket(“127.0.0.1”, 30002);
if (sc.isConnected()){
System.out.println(“Connected to UR Secondary Client”);
}

// Create stream for data
DataOutputStream out;
out = new DataOutputStream(sc.getOutputStream());
String thisCommand = “def Force():\n” +
" zero_ftsensor()\n" +
" sleep(0.02)\n" +
" force_mode(tool_pose(), [1, 1, 1, 1, 1, 1], [0.0, 0.0, 0.0, 0.0, 0.0, 0.0], 2, [0.15, 0.15, 0.15, 1.0471975511965976, 1.0471975511965976, 1.0471975511965976])\n" +
" while (not (read_input_boolean_register(127)==False)):\n" +
" sync()\n" +
" end\n" +
" end_force_mode ()\n" +
“end\n”;

// Send command
out.writeUTF(thisCommand);
System.out.println("Send this: "+thisCommand);
out.flush();

// Perform housekeeping
out.close();
sc.close();
System.out.println(“Disconnected from UR Secondary Client”);

For multiple lines of URScript you need to change

// Send command
out.writeUTF(thisCommand);
System.out.println("Send this: "+thisCommand);
out.flush();

to

// Send command
out.writeBytes(thisCommand);
out.write(thisCcommand.getBytes(“US-ASCII”));
out.flush();

see also here

1 Like

It works perfect
Thank you