RobotStudio event

Receive robtarget from String

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

Comments

  • Hi
    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.


    Per Svensson
    Robotics and Vision Specialist
    Consat Engineering
  • SteveMob
    SteveMob
    edited May 2016
    Per,

    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

  • PerSvensson
    PerSvensson ✭✭✭
    Hi
    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



     
    Per Svensson
    Robotics and Vision Specialist
    Consat Engineering
  • SteveMob
    SteveMob
    edited May 2016
    Ok thanks a ton!

    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
    Post edited by SteveMob on
  • PerSvensson
    PerSvensson ✭✭✭
    You can calculate if the robot is going to be able to reach a robtarget by using CalcJointT before you actually move to that position. It's quite well described in the manual,
    Per Svensson
    Robotics and Vision Specialist
    Consat Engineering
  • Ok I'll look into it, thanks. Do you have any ideas on how to keep the RAPID program running even when it encounters an error? I need the RAPID program to be on like "standby" and sends the error message to LV, and then LV will tell RAPID what to do next. Any Ideas?

    Thanks,
    SM
  • PerSvensson
    PerSvensson ✭✭✭
    Then you need to take care of it in Error handlers that you define at the end of each FUNC or PROC. If you know what errors that could happen you a can compare it with ERRNO and take the actions you need. There are a couple of instructions related to error handling like retry(try them same instruction that failed again), trynext (try the instruction after the one that failed),raise (call the error handler in the method that called the failing method). It's also possible to define your own ERRNO.
    Per Svensson
    Robotics and Vision Specialist
    Consat Engineering
  • SteveMob
    SteveMob
    edited May 2016
    I am terrible at this error handling stuff... Is there a joint limit and/or target out of reach error handler? I found ERR_OUTSIDE_REACH, but couldn't find any documentation on it or how it works. I also tried to make my own error handler, ERR_JOINTLIM and get it to send LV a message when CalcJointT encounters this error, but I am doing something wrong because it did not do what I wanted it to do. This is my code for the JOINTLIM error handler:

        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


  • hey man need a little help, so basically i am a real noob in this stuff but i need to pass the course :D.. I have to establish a communication between robot and laptop using visual studio C#. i have creating a client app on VS. just a basic program having connect and send buttons along with ip etc. what i want to do is to send string from that client e.g [[95,180,270],[1,-0.143906,0.942789,0.0454265],[0,0,-1,0],[9E+09,9E+09,9E+09,9E+09,9E+09,9E+09]] or something similar and i want from robotstudio to receive this string and adjust to that postition, or use this value as a robottarget and adjust its position accordingly but i have no idea how to do it, i get so many errors in anything i try. i saw ur post and tried to do it as you said but i targettostring wasnt recognised in RS and was labeled as target identifier not found. please help any code anything would be helpful


     i just have basic program in RS for socket communication. it looks like this 
    MODULE Module1

        VAR socketdev serversocket;
        VAR socketdev clientsocket;
        VAR string data;

        PROC main()

            SocketCreate serversocket;
            SocketBind serversocket,"127.0.0.1",8910;
            SocketListen serversocket;

            SocketAccept serversocket,clientsocket,\Time:=WAIT_MAX;
            SocketReceive clientsocket\str:=data;
            SocketSend clientsocket\str:="Command Received";

            SocketClose clientsocket;
            SocketClose serversocket;

        ERROR
            IF ERRNO=ERR_SOCK_TIMEOUT THEN
                RETRY;

            ELSEIF ERRNO=ERR_SOCK_CLOSED THEN

                SocketClose clientsocket;
                SocketClose serversocket;
                SocketCreate serversocket;
                SocketBind serversocket,"127.0.0.1",8910;
                SocketListen serversocket;
                SocketAccept serversocket,clientsocket,\Time:=WAIT_MAX;

                RETRY;

            ELSE
                stop;

            ENDIF

        ENDPROC




    ENDMODULE
  • lemster68
    lemster68 ✭✭✭
    Read the code posted once more, TargettoString is a routine in that code.  It is unidentified because you mistyped the name, or just left it out.
    Lee Justice
  • Hi
    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.


    Hi Per,

    I have applied your solution on splitting the string and it works great with the exception that for posX which would be my trans.x position it always gives me a value of 0. I cant to seem to find the reason, would you be able to assist? Many thanks in advance.

    Kind Regards
    Alex