Proc with argument
I have mulitple programs wich are all the same but just changing one number
PROC MoveToPos1()
SetDO DoMoveToPosition1,1;
WaitDI DiPosition1,1;
SetDO DoMoveToPosition1,0;
ENDPROC
PROC MoveToPos2()
SetDO DoMoveToPosition2,1;
WaitDI DiPosition2,1;
SetDO DoMoveToPosition2,0;
ENDPROC
I want to replace them with a single proc with an argument, something like this:
PROC MoveToPos(num Position)
SetDO "DoMoveToPosition"+NumToStr(Position,0);,1;
WaitDI "DiPosition"+NumToStr(Position,0);,1;
SetDO "DoMoveToPosition"+NumToStr(Position,0);,0;
ENDPROC
This doesn't work and gives me a type mismatch error. I've tried also with the StrToVal function, but it doesn't work either.
Is there any way to do this?
Thank you
Comments
-
Try this:PROC MoveToPos(num Position)
%"SetDO DoMoveToPosition"+ValToStr(Position)+",1"%;
%"WaitDo DiMoveToPosition"+ValToStr(Position)+",1"%;
%"SetDO DoMoveToPosition"+ValToStr(Position)+",0"%;
ENDPROCHope it will work out.Best regards,blind3rr
blind3rr2013-03-11 01:46:47Benteler Maschinenbau CZ0 -
[QUOTE=londoneye]Hello
PROC MoveToPos(num Position)
SetDO "DoMoveToPosition"+NumToStr(Position,0);,1;
WaitDI "DiPosition"+NumToStr(Position,0);,1;
SetDO "DoMoveToPosition"+NumToStr(Position,0);,0;
ENDPROC
[/QUOTE]The ; shoudn't be inside the calls - only at the end.Try remove them.Just looked a bit further into it - you can't give SetDO etc. a string as it expect a type of signalDO.Mayby this approach can be used?PROC MoveToPos(num Position)TEST PositionCASE 1:SetDO DoMoveToPosition1,1;WaitDI DiPosition1,1;SetDO DoMoveToPosition1,0;CASE 2:SetDO DoMoveToPosition2,1;WaitDI DiPosition2,1;SetDO DoMoveToPosition2,0;DEFAULT:TPWrite " No such position exist";Stop;ENDTESTENDPROCRegards, Lars
DanLars2013-03-11 10:11:45Lars Glud
Danrob A/S0 -
[QUOTE=blind3rr]
Try this:PROC MoveToPos(num Position)
%"SetDO DoMoveToPosition"+ValToStr(Position)+",1"%;
%"WaitDo DiMoveToPosition"+ValToStr(Position)+",1"%;
%"SetDO DoMoveToPosition"+ValToStr(Position)+",0"%;
ENDPROCHope it will work out.Best regards,blind3rr
[/QUOTE]
It gives me this error
40226: Name error
Description
Task T_ROB1: Procedure name
SetDO DoMoveToPosition3 1
is not a RAPID identifier excluding
reserved words
Actions
The procedure name, must be a legal
RAPID identifier not equal to any of
the reserved words of the RAPID
language. Change the name expression.
What is % supposed to do anyway?. I cannot find it in the manual?
0 -
[QUOTE=londoneye]
What is % supposed to do anyway?. I cannot find it in the manual?
[/QUOTE]A text string encapsulated in % will be called as if it where at PROC. Like this:PROC mainvar num path := 1;%"path" + NumToStr(path,0);% // Calling path1path := 2;%"path" + NumToStr(path,0);% // Calling path2ENDPROCPROC path1...ENDPROCPROC path2...ENDPROCAs far as I can rememberRegards, LarsLars Glud
Danrob A/S0 -
Something that would work is to use GetDataVal, for example:MoveToPos(
num nIO)
VAR string strInput;
VAR string strOutput;
VAR signaldo ioOutput;
VAR signaldi ioInput;
VAR string nuStr;
nuStr := NumToStr(nIO, 0);
strOutput := "DoMoveToPosition" + nuStr;
strInput := "DiPosition" + nuStr;
GetDataVal strOutput, ioOutput;
GetDataVal strInput, ioInput;
Set ioOutput;
WaitDI ioInput, 1;
Reset ioOutput;
ENDPROCThe call would look something like this:
PROC main()MoveToPos(1);
MoveToPos(2);
MoveToPos(3);
MoveToPos(4);
ENDPROC
AlexK2013-03-12 10:44:42Best regards
Alexander Källberg0 -
[QUOTE=AlexK]
Something that would work is to use GetDataVal, for example:MoveToPos(
num nIO)
VAR string strInput;
VAR string strOutput;
VAR signaldo ioOutput;
VAR signaldi ioInput;
VAR string nuStr;
nuStr := NumToStr(nIO, 0);
strOutput := "DoMoveToPosition" + nuStr;
strInput := "DiPosition" + nuStr;
GetDataVal strOutput, ioOutput;
GetDataVal strInput, ioInput;
Set ioOutput;
WaitDI ioInput, 1;
Reset ioOutput;
ENDPROCThe call would look something like this:
PROC main()MoveToPos(1);
MoveToPos(2);
MoveToPos(3);
MoveToPos(4);
ENDPROC
[/QUOTE]
That worked!!!!
Thak you very much
0 -
Your welcome, glad it worked!AlexK2013-03-18 12:08:48Best regards
Alexander Källberg0
Categories
- All Categories
- 5.5K RobotStudio
- 396 UpFeed
- 18 Tutorials
- 13 RobotApps
- 297 PowerPacs
- 405 RobotStudio S4
- 1.8K Developer Tools
- 250 ScreenMaker
- 2.8K Robot Controller
- 316 IRC5
- 61 OmniCore
- 7 RCS (Realistic Controller Simulation)
- 801 RAPID Programming
- AppStudio
- 3 RobotStudio AR Viewer
- 18 Wizard Easy Programming
- 105 Collaborative Robots
- 5 Job listings