Use a record and array in routines
ArneBert
✭
in RobotStudio
Hello
I'm a student who has a school assignment about a robot and we are using an record array to store our data about different thing like, height, color, position and if the piece is good.
But we need to make sure are date if modified is transferred to the other routines, but we are having difficulties to use the array in a routine. You can see what we have below:
I'm a student who has a school assignment about a robot and we are using an record array to store our data about different thing like, height, color, position and if the piece is good.
But we need to make sure are date if modified is transferred to the other routines, but we are having difficulties to use the array in a routine. You can see what we have below:
MODULE MainModule
RECORD Stift
string strStift;
bool baanwezig;
num numkleur;
num numhoogte;
robtarget robpunt;
ENDRECORD
Var Stift stiftarray{5}:=
[["stift1", True, 10, 1000, [[1,0,0],[1,0,0,0],[1,1,0,0],[11,12.3,9E9,9E9,9E9,9E9]]],
["stift2", false, 200, 20,[[1,0,0],[1,0,0,0],[1,1,0,0],[11,12.3,9E9,9E9,9E9,9E9]]],
["stift3", True, 30, 30,[[1,0,0],[1,0,0,0],[1,1,0,0],[11,12.3,9E9,9E9,9E9,9E9]]],
["stift4", false, 40, 40,[[1,0,0],[1,0,0,0],[1,1,0,0],[11,12.3,9E9,9E9,9E9,9E9]]],
["stift5", true, 50, 50,[[1,0,0],[1,0,0,0],[1,1,0,0],[11,12.3,9E9,9E9,9E9,9E9]]]];
!CONST robtarget P_test_kleur:=[[273.53,322.55,187.08],[0.000164752,0.706799,0.707415,-0.000414261],[0,-1,1,0],[9E+09,9E+09,9E+09,9E+09,9E+09,9E+09]];
PROC main()
Detectie_Hoogte_en_Kleur stiftarray{5};
FOR i FROM 1 TO Dim(stiftarray,1) DO
TPWrite NumToStr(stiftarray.numhoogte,0);
ENDFOR
ENDPROC
PROC Detectie_Hoogte_en_Kleur (inout num stiftarray{*})
FOR i FROM 1 TO Dim(stiftarray,1) DO
stiftarray{i}.numhoogte:= stiftarray{i}.numhoogte + 40;
!MoveJ stiftarray{i}.robpunt,v20, z50,t_sensor;
ENDFOR
ENDPROC
ENDMODULE
Thanks for your help
Arne Berteloot
Thanks for your help
Arne Berteloot
Tagged:
0
Answers
-
The array is a global variable, so you can use and edit it without explicitly passing it into a routine. Try calling Detectie_Hoogte_en_Kleur alone in main & remove the need for the INOUT from the Detectie_Hoogte_en_Kleur procedure. Also your TPWrite needs a dimension (I'd assume you meant, "TPWrite NumToStr(stiftarray{i}.numhoogte,0);).
0 -
Thanks for you"re help. So if we for instance put in the routine Detectie_Hoogte_en_Kleur and put numhoogte to 5 for example, this value leaves the routines also and if we call another routine it would give the same number?
And yes your correct about TPWrite, my bad
0 -
The FOR loop of adding 40 to all numhoogte in the array threw me off. If you're trying to pass just a part of an array, say 5, you could just pass the num to identify it and only add 40 to that entry.
PROC main()
Detectie_Hoogte_en_Kleur 5;
FOR i FROM 1 TO Dim(stiftarray,1) DO
TPWrite NumToStr(stiftarray.numhoogte,0);
ENDFOR
ENDPROC
PROC Detectie_Hoogte_en_Kleur (inout num id)
stiftarray{id}.numhoogte:= stiftarray{id}.numhoogte + 40;
ENDPROC
0 -
Thanks your a great help.0
-
Soup I tried it your way and I got always the same error, this one:
So I tried with a number as you see below but it still doesn't work and now I get this error on the dim(stiftarray{numcounter,0}:
MODULE MainModuleRECORD Stiftstring strStift;bool baanwezig;num numkleur;num numhoogtestift;num numoffsethoogte;robtarget robpunt;ENDRECORDVar Stift stiftarray{6}:=[["stift1", True, 10, 100, 0, [[1,0,0],[1,0,0,0],[1,1,0,0],[11,12.3,9E9,9E9,9E9,9E9]]],["stift2", false, 200, 20,0,[[1,0,0],[1,0,0,0],[1,1,0,0],[11,12.3,9E9,9E9,9E9,9E9]]],["stift3", True, 30, 300,0,[[1,0,0],[1,0,0,0],[1,1,0,0],[11,12.3,9E9,9E9,9E9,9E9]]],["stift4", false, 40, 400, 0,[[1,0,0],[1,0,0,0],[1,1,0,0],[11,12.3,9E9,9E9,9E9,9E9]]],["stift5", true, 50, 500,0,[[1,0,0],[1,0,0,0],[1,1,0,0],[11,12.3,9E9,9E9,9E9,9E9]]],["stift6", true, 60, 600,0,[[1,0,0],[1,0,0,0],[1,1,0,0],[11,12.3,9E9,9E9,9E9,9E9]]]];!einde array!Belangrijke punten!Punt voor te testen van kleurCONST robtarget P_test_kleur:=[[273.53,322.55,187.08],[0.000164752,0.706799,0.707415,-0.000414261],[0,-1,1,0],[9E+09,9E+09,9E+09,9E+09,9E+09,9E+09]];!We gaan 3 punten nodig hebben op pallet 1 om volgende zaken te weten: verschuiving in X en y ten opzichte van 2 stiften.!We gaan dus 1 stift als centraal punt nemenCONST robtarget P_stift_positie124:=[[0,-200,nummaxhoogtestift],[1,0,0,0],[0,0,1,0],[9E+09,9E+09,9E+09,9E+09,9E+09,9E+09]];!1 stift kiezen die opgeschoven is in de X richtingCONST robtarget P_stift_positie114:=[[50,-200,nummaxhoogtestift],[1,0,0,0],[0,0,1,0],[9E+09,9E+09,9E+09,9E+09,9E+09,9E+09]];!1 stift kiezen die opgeschoven is in de y-richtingCONST robtarget P_stift_positie123:=[[0,-220,nummaxhoogtestift],[1,0,0,0],[0,0,1,0],[9E+09,9E+09,9E+09,9E+09,9E+09,9E+09]];!Maximale hoogte die en stift mag hebben moet lager zijn dan 15cm!via deze constante is dit ook makkelijk aan te passen.CONST num nummaxhoogtestift:= 150;!plaat dikte bepalen en instelbaarCONST num numplaat:= 50;!gewenste hoogte die we instellenCONST num numingestelde_hoogte:= numplaat + nummaxhoogtestift;!effecteive hoogte van stiftVAR num numeffectieve_hoogte:=0;!variabele voor offsets!in x richtingVAR num numxoffset:=0;!in y richtingVAR num numyoffset:=0;VAR num numaantal_stiften:=6;PROC main()Detectie_Hoogte_en_Kleur numaantal_stiften;FOR numaantal_stiften FROM 1 TO Dim(stiftarray{numaantal_stiften},1) DOTpwrite numtostr(stiftarray{numaantal_stiften}.numkleur,0);ENDFORENDPROCPROC Detectie_Hoogte_en_Kleur(inout num numcounter)FOR i FROM 1 TO Dim(stiftarray{numcounter},1) DOstiftarray{numcounter}.numkleur:= stiftarray{numcounter}.numkleur + 40;ENDFORENDPROCENDMODULE
Thanks0 -
Sorry -- the INOUT is not needed -- PROC Detectie_Hoogte_en_Kleur (num id)
0 -
Now it works great thanks. I can't thank you enough!!!!!!!!!!!0
Categories
- All Categories
- 5.5K RobotStudio
- 394 UpFeed
- 18 Tutorials
- 13 RobotApps
- 297 PowerPacs
- 405 RobotStudio S4
- 1.8K Developer Tools
- 249 ScreenMaker
- 2.7K Robot Controller
- 309 IRC5
- 59 OmniCore
- 7 RCS (Realistic Controller Simulation)
- 783 RAPID Programming
- AppStudio
- 3 RobotStudio AR Viewer
- 18 Wizard Easy Programming
- 105 Collaborative Robots
- 4 Job listings