Receive robtarget from String

in RobotStudio
Hello,
I am doing some Robot/LabVIEW communication. I want LV to send a string for a robtarget. This string will essentially say:
"CONST robtarget p10:=[[461.29,144.16,221.59],[0.29728,-0.143906,0.942789,0.0454265],[0,0,-1,0],[9E+09,9E+09,9E+09,9E+09,9E+09,9E+09]];" Defining CONST robtarget, giving it a name, position in space with tool and axes configuration data.
I need RAPID to take that string and convert it into a robtarget. Is this possible? I have this code:
" MoveJ RelTool(Home,read_positionX,read_positionY,read_positionZ,\Rx:=orientationRX,\Ry:=orientationRY,\Rz:=orientationRZ),v200,z0,tool0,\WObj:=wobj0;"
But this will only take positions in space, and tool orientation. Is there a way to accept an entire string as above, and convert it to a target declaration?
I tried doing: " VAR robtarget vartarget:=[[positionx,positiony,positionz],[orientq1,orientq2,orientq3,orientq4],[cf1,cf4,cf6,cfx],[9E9,9E9,9E9,9E9,9E9,9E9]];" and declared all those as number variables, and those variables take numbers sent from LV, but that didn't really work either...
I also looked into byte to string but couldn't figure much out...
Thanks for any help!
SM
I am doing some Robot/LabVIEW communication. I want LV to send a string for a robtarget. This string will essentially say:
"CONST robtarget p10:=[[461.29,144.16,221.59],[0.29728,-0.143906,0.942789,0.0454265],[0,0,-1,0],[9E+09,9E+09,9E+09,9E+09,9E+09,9E+09]];" Defining CONST robtarget, giving it a name, position in space with tool and axes configuration data.
I need RAPID to take that string and convert it into a robtarget. Is this possible? I have this code:
" MoveJ RelTool(Home,read_positionX,read_positionY,read_positionZ,\Rx:=orientationRX,\Ry:=orientationRY,\Rz:=orientationRZ),v200,z0,tool0,\WObj:=wobj0;"
But this will only take positions in space, and tool orientation. Is there a way to accept an entire string as above, and convert it to a target declaration?
I tried doing: " VAR robtarget vartarget:=[[positionx,positiony,positionz],[orientq1,orientq2,orientq3,orientq4],[cf1,cf4,cf6,cfx],[9E9,9E9,9E9,9E9,9E9,9E9]];" and declared all those as number variables, and those variables take numbers sent from LV, but that didn't really work either...
I also looked into byte to string but couldn't figure much out...
Thanks for any help!
SM
Tagged:
Comments
You need to convert back and forth I usually separate the values with a ; character. Here is an example how you could do it. Haven't included all the data but I think you will get an idea also you should take in to consideration error handling when converting string to values. Depending on how many decimals you want in your values (in my case 0) you may have to split the robtarget structure into separate strings because a string could only hold 80 characters.
Robotics and Vision Specialist
Consat Engineering
Thank you so much for the help, it definitely got me moving along better than I was. So now I am slightly confused on where I need the incoming data to parse to. This is my connection/data receiving/parsing code:
PROC main()
data:=TargetToString(myRobtarget);
TPWrite data;
pTarget:=StringToTarget(data);
MoveJ Home,v150,z0,tool0;
WaitTime 2;
SocketClose client_socket;
Socketcreate client_socket;
SocketConnect client_socket,"192.168.125.5",3333;
SocketSend client_socket\Str:="Connection Successful"\NoOfBytes:=21;
! Clear the port of any data
!SocketReceive client_socket\RawData:=parse_data\Time:=1;
IF ERRNO=ERR_SOCK_TIMEOUT THEN
ENDIF
ClearRawBytes parse_data;
i:=1;
WHILE i=1 DO
peek_value:=SocketPeek(client_socket);
IF peek_value>=1 THEN
ClearRawBytes parse_data;
SocketReceive client_socket\RawData:=parse_data\Time:=25;
bytes_available:=RawBytesLen(parse_data);
SocketSend client_socket\RawData:=parse_data;
IF bytes_available>=1 THEN
UnpackRawBytes parse_data,1,command\Hex1;
IF 42=command THEN
! Read a position.
! UnpackRawBytes parse_data\Network,2,read_positionX\Float4;
! UnpackRawBytes parse_data\Network,6,read_positionY\Float4;
! UnpackRawBytes parse_data\Network,10,read_positionZ\Float4;
! ! Read an orientation.
! UnpackRawBytes parse_data\Network,14,orientationRX\Float4;
! UnpackRawBytes parse_data\Network,18,orientationRY\Float4;
! UnpackRawBytes parse_data\Network,22,orientationRZ\Float4;
! Moving relative to the tool coordinates, absolute move from position "Home" (all axes at 0 degrees)
!MoveJ RelTool(Home,read_positionX,read_positionY,read_positionZ,\Rx:=orientationRX,\Ry:=orientationRY,\Rz:=orientationRZ),v200,z0,tool0,\WObj:=wobj0;
!Read a position (x,y,z).
UnpackRawBytes parse_data\Network,2,robtarget.pos.x\Float4;
UnpackRawBytes parse_data\Network,6,robtarget.pos.y\Float4;
UnpackRawBytes parse_data\Network,10,robtarget.pos.z\Float4;
! Read tool orientation (quaternion angles).
UnpackRawBytes parse_data\Network,30,robtarget.orient.q1\Float4;
UnpackRawBytes parse_data\Network,34,robtarget.orient.q2\Float4;
UnpackRawBytes parse_data\Network,38,robtarget.orient.q3\Float4;
UnpackRawBytes parse_data\Network,42,robtarget.orient.q4\Float4;
!Read axes configuration (axis1,axis4,axis6,axisx)("x" can refer to axis 5 at times).
UnpackRawBytes parse_data\Network,46,robtarget.confdata.cf1\Float4;
UnpackRawBytes parse_data\Network,50,robtarget.confdata.cf4\Float4;
UnpackRawBytes parse_data\Network,54,robtarget.confdata.cf6\Float4;
UnpackRawBytes parse_data\Network,58,robtarget.confdata.cfx\Float4;
!MoveJ vartarget,v100,z10,tool0,\WObj:=wobj0;
WaitTime 2;
ELSE
TPWrite "Unhandled command: "\Num:=command;
ENDIF
ENDIF
IF ERRNO>0 THEN
IF ERRNO=ERR_SOCK_TIMEOUT THEN
ELSE
i:=0;
ENDIF
ENDIF
WaitTime 1;
ENDIF
ENDWHILE
ENDPROC
I included what you posted above, below all of this code. What do I need to change in order to parse the incoming string? In other words, how would I receive a string from LabVIEW, and where what variables do I need to place the data to?
Thanks for all the help!
SM
I usually do the communication in a background task and yield to the foreground when new data has arrived.
Here is an example of the code that almost use every time as the base and then just do what ever I need to do in the ParseMessage routine.
In my cases the robot is usually the server
The RobOS() is just for testing if I the code is running on a real controller or a Virtual controller
Robotics and Vision Specialist
Consat Engineering
One more question, how should I go about with the error handling? I've never really done much with the errors. I want the robot to send a message to LB via socket to say it arrived at position "X,Y,Z...". And if it doesn't arrive at that position for whatever reason (joint limit, target out of reach, collision, etc.) I don't want the RAPID program to stop, but rather send a message to LV saying it didn't get to the target for reason of Error #"...", but have the RAPID program wait on "standby" for LV to tell it what to do next. How could I go about doing that?
Thanks for all your help!
SM
Robotics and Vision Specialist
Consat Engineering
Thanks,
SM
Robotics and Vision Specialist
Consat Engineering
VAR errstr JointLim:="Robot will reach joint limit!";
VAR errstr OutReach:="This target is out of reach for the robot arm!";
VAR jointtarget jointpos1;
VAR errnum ERR_JOINTLIM:=1;
.
.
.
IF ERRNO=ERR_OUTSIDE_REACH THEN
SocketSend client_socket\Str:=OutReach;
!TRYNEXT;
ENDIF
jointpos1:=calcjointt(myRobtarget,tool0\WObj:=wobj0\ErrorNumber:=ERR_JOINTLIM);
IF ERRNO=ERR_JOINTLIM THEN
SocketSend client_socket\Str:=JointLim;
!TRYNEXT;
ENDIF
MoveJ myRobtarget,v100,fine\Inpos:=inpos50,tool0,\WObj:=wobj0;
With this code, it won't even send the message to the client. I need it to send a message to the client, and the RAPID program to just sit there until LV tells it something else to do. But so far it will just hault the program and say throw out the errors. Could it be that since joint limit and target out of reach are "fatal" errors that you can't use an error handler with them?
I also can't seem to get the "TryNext" to work, but 1st things 1st, the error handlers... Any ideas?
Thanks,
SM
i just have basic program in RS for socket communication. it looks like this
MODULE Module1