IF statement question
SteveMob
✭
in RobotStudio
Hello,
I am receiving a number from Sockets that gets placed into a variable "command". I am trying to test to see of that number is a certain number:
IF command<>42 OR command<>105 OR command<>106 OR command<>5 THEN
SocketSend clientSocket\Str:="Unknown command";
GOTO MainLoopEnd;
ENDIF
I am sending it the number 42, and it still goes into this IF statement. However, if I compare just IF command<>42 (not all the other OR command<>#'s), it works just fine and skips this loop.
So my question is, how can I compare multiple values? What am I doing wrong? Is there like a certain hierarchy thing I am missing?
Thanks for any help!
SM
I am receiving a number from Sockets that gets placed into a variable "command". I am trying to test to see of that number is a certain number:
IF command<>42 OR command<>105 OR command<>106 OR command<>5 THEN
SocketSend clientSocket\Str:="Unknown command";
GOTO MainLoopEnd;
ENDIF
I am sending it the number 42, and it still goes into this IF statement. However, if I compare just IF command<>42 (not all the other OR command<>#'s), it works just fine and skips this loop.
So my question is, how can I compare multiple values? What am I doing wrong? Is there like a certain hierarchy thing I am missing?
Thanks for any help!
SM
Tagged:
0
Best Answers
-
hello,
you should use AND instead of OR
IF command<>42 AND command<>105 AND command<>106 AND command<>5 THEN
so then the program enters the if loop if the number is different from 42,105,106,5
because if you use OR, it will always enter the IF because 42<>105
You can also write
IF NOT(command=42 OR command=105 OR command=106 OR command=5) THEN
it reads more logical to test that the number is outside of possible commands
5 -
Is your question about if the approach to check singularity correct or about your code...? Because your description of checking the angle already match the code right?
There is a more short-hand notation:singularity := Abs(target.robax.rax_4)<0.1 OR Abs(target.robax.rax_5)<0.1;
5
Answers
-
Similarly I want to check if a given target approaches singularity so I am checking the joint angles, and if they come within +/- 0.1 degrees, I want to set bool singularity=true, otherwise return false:
IF ((target.robax.rax_5>-0.1) AND (target.robax.rax_5<0.1)) OR ((target.robax.rax_4>-0.1) AND (target.robax.rax_4<0.1)) THEN
singularity:=TRUE;
ELSE
singularity:=FALSE;
ENDIF
RETURN singularity;
Is there a way that I can do that?
Thanks,
SM
0
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)
- 798 RAPID Programming
- AppStudio
- 3 RobotStudio AR Viewer
- 18 Wizard Easy Programming
- 105 Collaborative Robots
- 5 Job listings