Struggling with sending data via TCP/IP socket connection
3 views (last 30 days)
Show older comments
I want to write script code which sends strings to a robot (Universal robot simulator, URSim) via TCP/IP, the string is a translation of the URscript for the robot into acceptable form in MATLAB. I only succeeded in making turning on/off the "digital_out". All the move commands aren't working when I run the program, the robot remained at its initial position. But when I remove the command to set digital_out, the next move command works. It means it only implement the first command. Any help on the right syntax in Matlab? I am working with examples from python http://www.zacobria.com/universal-robots-knowledge-base-tech-support-forum-hints-tips/knowledge-base/script-from-host-to-robot-via-socket-connection/ and javascript https://github.com/ABC-iRobotics/ur-nodejs-client-example/blob/master/index.js.
Here is my code:
host = '192.168.233.3';
port = 30003;
s = tcpip(host, port,'NetworkRole', 'client');
s.InputBufferSize = 221600;
fopen(s);
disp('Connected!');
While(true)
fprintf (s, strcat('set_standard_digital_out(0,False)', '\n')),
strcat('movej([-0.3596764999985558, -1.174431851788599, 1.88734483936274, -2.277712271407693, -1.5605291909381744, -0.4576386031765587], a=1.3962634015954636, v=1.0471975511965976)', '\n');
strcat('while (true)', '\n'),
strcat('movel([-0.3600129734254667, -1.0838046643374781, 1.923101135878433, -2.4040936317428048, -1.5618407243079862, -0.45651480620647433], a=1.2, v=0.25)', '\n'),
strcat('set_standard_digital_out(0,True)', '\n'),
strcat('pause(1)', '\n'),
strcat('movel([-0.3596764999985558, -1.174431851788599, 1.88734483936274, -2.277712271407693, -1.5605291909381744, -0.4576386031765587], a=1.2, v=0.25)', '\n'),
strcat('movej([-0.10482278180937676, -1.1835615192007545, 1.9014732903964209, -2.2826424641984957, -1.5592584674169627, -0.20275108288563892], a=1.3962634015954636, v=1.0471975511965976)', '\n'),
strcat('movel([-0.10516193553895548, -1.0924099301580732, 1.9372874633103936, -2.409607446651929, -1.5605816595381992, -0.20162872498015805], a=1.2, v=0.25', '\n'),
strcat('set_standard_digital_out(0,False)', '\n'),
strcat('pause(1)', '\n'),
strcat('movel([-0.10482278180937676, -1.1835615192007545, 1.9014732903964209, -2.2826424641984957, -1.5592584674169627, -0.20275108288563892], a=1.2, v=0.25)', '\n'),
strcat('pause(1)', '\n'),
strcat('movel([-0.10516193553895548, -1.0924099301580732, 1.9372874633103936, -2.409607446651929, -1.5605816595381992, -0.20162872498015805], a=1.2, v=0.25)', '\n'),
strcat('set_standard_digital_out(0,True)', '\n'),
strcat('pause(1)', '\n'),
strcat('movel([-0.10482278180937676, -1.1835615192007545, 1.9014732903964209, -2.2826424641984957, -1.5592584674169627, -0.20275108288563892], a=1.2, v=0.25)', '\n'),
strcat('movej([-0.3596764999985558, -1.174431851788599, 1.88734483936274, -2.277712271407693, -1.5605291909381744, -0.4576386031765587], a=1.3962634015954636, v=1.0471975511965976)', '\n'),
strcat('movel([-0.3600129734254667, -1.0838046643374781, 1.923101135878433, -2.4040936317428048, -1.5618407243079862, -0.45651480620647433], a=1.2, v=0.25)', '\n'),
strcat('set_standard_digital_out(0,False)', '\n'),
strcat('pause(1)', '\n'),
strcat('movel([-0.3596764999985558, -1.174431851788599, 1.88734483936274, -2.277712271407693, -1.5605291909381744, -0.4576386031765587], a=1.2, v=0.25)', '\n'),
strcat('pause(1)', '\n'),
strcat('end' , '\n');
settings = fscanf(s);
end
fclose(s);
delete(s);
clear s;
The output of settings is some random unreadable data, though I think the format is as expected.
0 Comments
Answers (0)
See Also
Categories
Find more on National Instruments Frame Grabbers in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!