RobotStudio event

SearchL

Hello,
i am a beginner, so excuse me :)
My robot has to search for edge with SearchL. If search did not get any match, It should try the search 3 times again. How should i build the syntax right?

Tuomas

Answers

  • soup
    soup ✭✭✭
    MODULE mSearchExample

        ! tool and wobj data
        TASK PERS tooldata tGripper1:=[TRUE,[[-98.8713,1.66235,131.444],[0.958572,-6.3433E-05,0.284642,-0.0108527]],[2,[0,0,50],[1,0,0,0],0,0,0]];
        TASK PERS wobjdata wobjPaper1:=[FALSE,TRUE,"",[[842.843,389.57,8.88436],[0.0132869,-0.00221957,-0.0038117,0.999902]],[[0,0,0],[1,0,0,0]]];

        ! home and service positions
        CONST jointtarget pHome:=[[0,0,0,0,60,0],[0,9E9,9E9,9E9,9E9,9E9]];
        CONST jointtarget pService:=[[53.3131,32.8006,36.608,-90.2556,25.1677,139.011],[9E+09,9E+09,9E+09,9E+09,9E+09,9E+09]];

        ! speed data
        VAR speeddata vIntermid:=[250,30,200,15];
        VAR speeddata vDispense:=[50,30,200,15];

        ! search positions
        CONST jointtarget jSearch_Start:=[[19.0408,41.392,14.4539,-65.2267,13.6518,84.7809],[9E+09,9E+09,9E+09,9E+09,9E+09,9E+09]];
        CONST robtarget pSearch_End:=[[139.37,943.08,188.16],[0.0127536,-0.999531,0.0155706,-0.0230594],[-1,0,-1,0],[9E+09,9E+09,9E+09,9E+09,9E+09,9E+09]];
        PERS robtarget pSearch_Found:=[[152.064,466.067,184.558],[0.0127333,-0.999531,0.0155973,-0.0230583],[-1,0,-1,0],[9E+09,9E+09,9E+09,9E+09,9E+09,9E+09]];
        
        ! search error and search delta (to be used elsewhere)
        VAR num nErrorCounter;
        VAR num nFKey;
        PERS num nSearch_Delta:=-33.933;
        
        ! temp signals, to be replaced with real signals
        VAR signaldi di5_Trigger;
        VAR signaldo do9_Light;

        ! ******************************************************************************************************************** !
        PROC rSearch()
            
            ! check the eye before search attempt(s)
            WHILE di5_Trigger=1 DO
                ErrLog 4800,"SEARCH EYE ERROR","Example Search photoeye is blocked","before the search.","Clean photoeye and press the Play","button to continue.";
                Stop;
            ENDWHILE
            
            ! search
            MoveAbsJ jSearch_Start\NoEOffs,vIntermid,fine,tGripper1\WObj:=wobjPaper1;
            SearchL\Stop,di5_Trigger,pSearch_Found,pSearch_End,vDispense,tGripper1\WObj:=wobjPaper1;
            
            ! search successful, use search data to do/calculate something
            Clear nErrorCounter;
            PulseDO\PLength:=3.0,do9_Light;
            nSearch_Delta:=pSearch_Found.trans.y-500;
            MoveAbsJ jSearch_Start\NoEOffs,vIntermid,z50,tGripper1\WObj:=wobjPaper1;
            
        ERROR
            IF ERRNO=ERR_WHLSEARCH THEN
                IF nErrorCounter<2 THEN
                    ! error and redo search
                    Incr nErrorCounter;
                    ErrLog 4800,"SEARCH ERROR "+NumToStr(nErrorCounter,0),"The example search "+NumToStr(nErrorCounter,0)+" errored.","","Trying example search again.","";
                    MoveAbsJ jSearch_Start\NoEOffs,vIntermid,fine,tGripper1\WObj:=wobjPaper1;
                    RETRY;
                ELSE
                    ! give-up on search
                    MoveAbsJ pService,vIntermid,fine,tGripper1,\WObj:=wobjPaper1;
                    Incr nErrorCounter;
                    ErrLog 4800,"SEARCH ERROR "+NumToStr(nErrorCounter,0),"The example search "+NumToStr(nErrorCounter,0)+" errored.","Examine tool and photoeye and press","the Play button to move Home.","";
                    Stop;
                    MoveAbsJ pHome\NoEOffs,vIntermid,fine,tGripper1\WObj:=wobjPaper1;
                    Clear nErrorCounter;
                    EXIT;
                ENDIF
            ENDIF
        ENDPROC

    ENDMODULE