View unanswered posts | View active topics It is currently Sat Dec 20, 2014 2:41 pm






Reply to topic  [ 3 posts ] 
C order of Operations: is there an RobotC operator for ±? 
Author Message
Rookie

Joined: Thu Mar 13, 2014 6:12 am
Posts: 18
Post C order of Operations: is there an RobotC operator for ±?
Hello all,

Just wondering if there is an operator symbol, in RobotC, for ±? I couldn't find one on the RobotC Wiki C order of operations page, but I thought I would just make sure. Just incase there is another way of doing this, anyways, this is the code I want to simplify, in Pseudo/RobotC code first, and pure RobotC second. The RobotC version is how I beleive it would otherwise have to be written. (All variables are of 'int' type)

Code:
//Pseudo/RobotC
if(var1 == (var2 ± 5) && var3 == (var2 ± 5))     /*in english: if 'var1' is within a range of 5 around 'var2', and 'var3' is also within a range of 5 around 'var2'*/
{
}


Code:
//RobotC
if(var1 < (var2 + 5) && var1 > (var2 - 5))
{
if(var3 < (var2 + 5) && var3 > (var2 - 5))
{
}
}




EDIT: (I'll edit this message, rather then re-posting, so that it still registers as unanswered - which it is!)

I'm just wondering about the ± operation, because otherwise I have to do this (I'm not sure that it works, because it has && and ||!):
Code:

//green is 'int', green2 is 'bool', green3 is 'bool', and lght2 and lght3 are the respective S2 and S3.

if((SensorValue(lght2) < green + 5 && SensorValue(lght2) > green - 5 && green2) || (SensorValue(lght3) < green + 5 && SensorValue(lght3) > green - 5 && green3))


Sat Jul 19, 2014 5:47 am
Profile
Moderator
Moderator
User avatar

Joined: Wed Mar 05, 2008 8:14 am
Posts: 3297
Location: Rotterdam, The Netherlands
Post Re: C order of Operations: is there an RobotC operator for ±
No, ROBOTC does not have that specific operator. I am pretty sure that it does not exist in ANSI C or C++ either. I am not sure I could even type it on this keyboard without resorting to either copying and pasting or ALT-keypadnumbers.

= Xander

_________________
| Professional Conduit of Reasonableness
| (Title bestowed upon on the 8th day of November, 2013)
| My Blog: I'd Rather Be Building Robots
| ROBOTC 3rd Party Driver Suite: [Project Page]


Sat Jul 19, 2014 9:58 am
Profile WWW
Professor
User avatar

Joined: Sat Aug 31, 2013 9:15 am
Posts: 214
Post Re: C order of Operations: is there an RobotC operator for ±
There is another way you could do it using the abs function. Something like:
Code:
abs(green - SensorValue[light2]) < 5

_________________
FTC Team 6100 Chariots of Fire - Programmer (2012-2013)
FTC Team 7468 Blue Chariots of Fire - Programmer (2013-2014)
FTC Team 7468 Blue Chariots of Fire - Mentor (2014-2015)
Check out our team website at http://bluechariotsoffire.com/.


Sat Jul 19, 2014 2:31 pm
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 3 posts ] 

Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  



Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software for PTF.