RobotStudio event

leaving parts of a record blank

m_stroober
edited June 2022 in RAPID Programming
Hi all,
I wonder if it is possible to hide or skip parts of a record when I don't use them. I use a record to create settings which contains other records which define certain types in my program. Sometimes, my program requires all the types but sometimes I only need 1. Me and my colleagues struggle with the fact it looks and works quite messy when not all types are used. For now I set settings to 0 when the certain type is not use. I wonder if there is a way to skip or hide parts of the records. For example below. I want to only use setpoints_type_2 but I need to fill all of them to let the program run properly. Any suggestions?
In the example below it should be nice if the records with 0 can be hidden.

PERS settings setting1:=
[["TYPE1",0,0,0,FALSE],["TYPE2",100,10,10,TRUE],["TYPE3",0,0,0,FALSE],["TYPE4",0,0,0,FALSE],["TYPE5",0,0,0,FALSE],["TYPE6",0,0,0,FALSE]]
PERS settings setting2:=
[["TYPE1",200,30,1,FALSE],["TYPE2",100,10,10,TRUE],["TYPE3",80,5,20,FALSE],["TYPE4",10,1,10,TRUE],["TYPE5",80,80,80,TRUE],["TYPE6",400,10,30,TRUE]]

RECORD settings
setpoints_type_1;
setpoints_type_2;
setpoints_type_3;
setpoints_type_4;
setpoints_type_5;
setpoints_type_6;

RECORD setpoints type 1
string: type_name
num: speed;
num: zone; 
num: acceleration;
bool: calc_speed

RECORD setpoints type 2
string: type_name
num: speed;
num: zone; 
num: acceleration;
bool: calc_speed


RECORD setpoints type 3
string: type_name
num: speed;
num: zone; 
num: acceleration;
bool: calc_speed

RECORD setpoints type 4
string: type_name
num: speed;
num: zone; 
num: acceleration;
bool: calc_speed

RECORD setpoints type 5
string: type_name
num: speed;
num: zone; 
num: acceleration;
bool: calc_speed


RECORD setpoints type 6
string: type_name
num: speed;
num: zone; 
num: acceleration;
bool: calc_speed


Tagged:

Comments

  • Hi, this is a interesting question and i'm curious how others solve this kind of issue.
    I wrote an example how I do based on your data. 
    I think it's important that the code is flexible and it's easy for endusers to read and modify the code.
    With my method I can change the record structure (amount of setpoint_types or what's included in a setpoint_type)  and only have to update the syntax in 3 datas.
    And I would not have to do any changes to the programs that don't need the new changes.
    Splitting the code in different modules also make's it easier to handle. 

    First I would create a module called records that looks like this:
        !***********
        !*** MODULE RECORDS
        !***********
        RECORD Programdata
            string Name;
            string SetupProc;
        ENDRECORD
        
        RECORD SettingsData
            setpoints_type_1 spd1;
            setpoints_type_2 spd2;
            setpoints_type_3 spd3;
            setpoints_type_4 spd4;
            setpoints_type_5 spd5;
            setpoints_type_6 spd6;
        ENDRECORD
        
        RECORD SetpointData
            string type_name;
            num speed;
            num zone;
            num acceleration;
            bool calc_speed;
        ENDRECORD
        
        ALIAS SetpointData setpoints_type_1;
        ALIAS SetpointData setpoints_type_2;
        ALIAS SetpointData setpoints_type_3;
        ALIAS SetpointData setpoints_type_4;
        ALIAS SetpointData setpoints_type_5;
        ALIAS SetpointData setpoints_type_6;
    I also like to have a module for all my data declarations, so I would put these datas there.
        !***********
        !*** MODULE DATAS
        !***********
        CONST SetpointData spdNull:=["",0,0,0,FALSE];
        CONST SettingsData sdNull:=[["",0,0,0,FALSE],["",0,0,0,FALSE],["",0,0,0,FALSE],["",0,0,0,FALSE],["",0,0,0,FALSE],["",0,0,0,FALSE]];
        PERS SettingsData sdCurrent:=[["",0,0,0,FALSE],["",0,0,0,FALSE],["",0,0,0,FALSE],["",0,0,0,FALSE],["",0,0,0,FALSE],["",0,0,0,FALSE]];
        PERS Programdata pdActive:=["",""];
        
    Next I would have a module for my programs.
    This is the module where endusers would create / edit programs. 
        !***********
        !*** MODULE PROGRAMS
        !***********
        CONST Programdata pdProgram1:=["Program 1","pdsetup_Program1"];
        CONST Programdata pdProgram2:=["Program 2","pdsetup_Program2"];
        
        PROC pdsetup_Program1()
            sdCurrent:= sdNull;
            pdActive:= pdProgram1;
            !Setup SetpointData #1
            !Reserved
            !Setup SetpointData #2
            sdCurrent.spd2.type_name:="TYPE2";
            sdCurrent.spd2.speed:=100;
            sdCurrent.spd2.zone:=10;
            sdCurrent.spd2.acceleration:=10;
            sdCurrent.spd2.calc_speed:=TRUE;
            !Setup SetpointData #3
            !Reserved
            !Setup SetpointData #4
            !Reserved
            !Setup SetpointData #5
            !Reserved
            !Setup SetpointData #6
            !Reserved
        ENDPROC
        
        PROC pdsetup_Program2()
            sdCurrent:= sdNull;
            pdActive:= pdProgram2;
            !Setup SetpointData #1
            sdCurrent.spd2.type_name:="TYPE1";
            sdCurrent.spd2.speed:=200;
            sdCurrent.spd2.zone:=30;
            sdCurrent.spd2.acceleration:=1;
            sdCurrent.spd2.calc_speed:=FALSE;
            !Setup SetpointData #2
            sdCurrent.spd2.type_name:="TYPE2";
            sdCurrent.spd2.speed:=100;
            sdCurrent.spd2.zone:=10;
            sdCurrent.spd2.acceleration:=10;
            sdCurrent.spd2.calc_speed:=TRUE;
            !Setup SetpointData #3
            sdCurrent.spd2.type_name:="TYPE3";
            sdCurrent.spd2.speed:=80;
            sdCurrent.spd2.zone:=5;
            sdCurrent.spd2.acceleration:=20;
            sdCurrent.spd2.calc_speed:=FALSE;
            !Setup SetpointData #4
            !Reserved
            !Setup SetpointData #5
            !Reserved
            !Setup SetpointData #6
            !Reserved
        ENDPROC
    Then in my actual jobProcs I would check the data like this:
        PROC rType1Job()
            IF sdCurrent.spd1 = spdNull RETURN;
        ENDPROC
        PROC rType2Job()
            IF sdCurrent.spd2 = spdNull RETURN;
        ENDPROC
        PROC rType3Job()
            IF sdCurrent.spd3 = spdNull RETURN;
        ENDPROC
        PROC rType4Job()
            IF sdCurrent.spd4 = spdNull RETURN;
        ENDPROC
        PROC rType5Job()
            IF sdCurrent.spd5 = spdNull RETURN;
        ENDPROC
        PROC rType6Job()
            IF sdCurrent.spd6 = spdNull RETURN;
        ENDPROC

    Has anyone found a different solution?

    The biggest drawback of this method is that the users can edit the programs with "ProgramData" on the flexpendant. But they learn quickly to do it with ProgramEditor.

    I like the ability to quickly add more data to the settings, and not have to update old programs that dosen't need the changes. 
    Systemintegrator - Web / C# / Rapid / Robotstudio

    If I helped, please press Vote Up  :smile:

    ☑️2024 - RobotStudio® User Group