RobotStudio event

Help with RAPID: user functions & structures?

I am using the RAPID language to create a relatively complex application to control my ABB robot that utilizes both laser sensors and cameras. I have had a lot of success with the RAPID programming language, but there are several items that I am use to in traditional "C" programing that I cannot figure out how to implement in RAPID.

1) How do I write a user "function" that returns a value? I have been able to use PROC with input arguments, but it does not seem to let you return a result. There are plenty of "functions" that are called in the code that take input arguments and return results. I must be missing something on how to write my own.

2) How do you create a "structure" in RAPID? Again, they are used all the time (e.g., pose), but I have yet to figure out how to create a user "struct."

3) Can you create "enumerated" data types in RAPID?

Where can I find information on these more "advanced" topics in the RAPID programming language?

Thanks
Michael

Comments

  • Hi Michael
    Try to find Rapid Reference manuals called RAPID Kernal and RAPID Overview.

    There you will find a lot of goodies such as:

    FUNC num veclen (pos vector)
    RETURN Sqrt(Pow(vector.x,2)+Pow(vector.y,2)+Pow(vector.z,2));
    ENDFUNC

    and
    RECORD
    newtype
    num x;

    ENDRECORD
    I guess the manuals are included on the DVD - get back here if you cannot find them.
    Good luck
    /GA?ran Manske
  • I put RECORD

    RECORD Mold

       string Name;

       num Mold_number;

       num Cannon_number;

       pos P{6};

       num W{6};

       num M_zone{6};

       num M_speed{6};

    ENDRECORD

     

    In MainModule in front of PROC Main()

    and I define new record like this

    PERS Mold Mold1;

    In PROC Main()

     

    But when run, I received this error message

    Expected 'trap' but found 'record'

    What could be the problem?

    I also have 2 traps PROC after Main()

     

    Please help, Thank you in advance

    Ake
  • Hi Ake,
    Arrays in RECORD are unfortunately not supported - I guess you need to solve this in another way. Perhaps you can use arrays of molds or multiple data in the RECORD e.g.:

    pos p1;

    pos p2;

    pos p3;

    etc.

     

    Also when creating PERS data I believe you need to give it a value:

    PERS mold mold1:=["Hello",12,....];

    Personally I always keep my PERS data as global data - that is NOT in the main PROC.

    If you need the data locally in a PROC without an initial value - use VAR!

     

    Good luck!

    GA?ran

     
  • hey Ake and GA?ran,

    to use structs (record) in S4C+ robots you need an option called developers function, in IRC5 robots you basically need an option used advanced rapid, unless you boot the system with one of the latest bootware versions (I think advanced rapid is free as from robotware 5.13

    for the problem that an array is not supported in a record. I know it is a problem but I solve it following way: if I need eg an array of 20 nums in a record, I first create a record with 20 num "elements" and use this record in the record I was intented to build. I also write a "get"-function with parameters the 20 num record and the number of element I want to access and a "set" procedure with parameters the 20 num rocord (defined as Inout parameter), the number of Item I want to change and the new value.......

    about pers variables: yes, you have to give them a value, and no you can not declare them within a routine (because there life time is only that routine, and there value can not be stored)......

    hope this helps you,

    bart
    best regards,

    bart