RobotStudio event

Non-Constant robtarget

SteveMob
SteveMob
edited May 2016 in RobotStudio
Hello,

I am doing some RobotStudio/LabVIEW communication. Basically, I want to send some numbers to RS from LV, and I want to assign those numbers into variables that can declare a robtarget. The problem I am having is that to declare a robtarget, the translation, orientation, and configuration variables have to be constant.

This is my code in a nutshell:

Module MainModule
    VAR pos P;
    VAR orient Q;
    VAR confdata C;
    VAR robtarget mytarget :=[[P.x,P.y,P.z],[Q.q1,Q.q2,Q.q3,Q.q4],[C.cf1,C.cf4,C.cf6,C.cfx],[9E9,9E9,9E9,9E9,9E9,9E9]];

 PROC main()
        MoveJ Home,v150,z0,tool0;
        WaitTime 2
!Establish connection with LV (RS is client, LV is server)
        SocketClose client_socket;
        Socketcreate client_socket;
        SocketConnect client_socket,"127.0.0.1",3333;
        !                ERROR       
        !                IF ERRNO=ERR_SOCK_TIMEOUT THEN
        !                            IF retry_no<5 THEN
        !                                WaitTime 1;
        !                                retry_no:=retry_no+1;
        !                                RETRY;
        !                            ELSE
        !                                RAISE ;
        !                            ENDIF
        !                        ENDIF
        SocketSend client_socket\Str:="Connection Successful, you are the server, I am the client!"\NoOfBytes:=59;
        ! Clear the port of any data
        !SocketReceive client_socket\RawData:=parse_data\Time:=1;
        IF ERRNO=ERR_SOCK_TIMEOUT THEN

        ENDIF

        ClearRawBytes parse_data;
        !data_buffer{1}:=StrToByte(con_data_buffer{1});

                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 (x,y,z). Receives numbers and assigns them to the variables
                                UnpackRawBytes parse_data\Network,2,P.x\Float4;
                                UnpackRawBytes parse_data\Network,6,P.y\Float4;
                                UnpackRawBytes parse_data\Network,10,P.z\Float4;

                                ! Read tool orientation (quaternion angles). Receives numbers and assigns them to the variables
                                UnpackRawBytes parse_data\Network,30,Q.q1\Float4;
                                UnpackRawBytes parse_data\Network,34,Q.q2\Float4;
                                UnpackRawBytes parse_data\Network,38,Q.q3\Float4;
                                UnpackRawBytes parse_data\Network,42,Q.q4\Float4;

                                !Read axes configuration (axis1,axis4,axis6,axisx)("x" can refer to axis 5 at times). Receives numbers and assigns to the variables
                                UnpackRawBytes parse_data\Network,46,C.cf1\Float4;
                                UnpackRawBytes parse_data\Network,50,C.cf4\Float4;
                                UnpackRawBytes parse_data\Network,54,C.cf6\Float4;
                                UnpackRawBytes parse_data\Network,58,C.cfx\Float4;
                               
                                MoveJ mytarget,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


The problem I having is that I am getting an error: "Expression "P" is not a constant expression."  This is referring to the underlined code above (robtarget declaration). I imagine that I will get the same errors for the "Q" and "C" variables. Is there a way to get past this error, or to declare different variables such that I can not have constants in my robtarget declaration so that I can send different numbers and have essentially a "new" robtarget called "mytarget"?

Thanks for any help!
SM

Best Answer