Log in

View Full Version : FTC Block Party IR-Sensor


ashb1025
26-02-2014, 12:55
Hi, I am the main programmer for 6095, we are having some trouble with using if statements on our IR autonomous program. I am familiar with RobotC but am having some trouble. Some help would be greatly appreciated.

RyanCahoon
26-02-2014, 15:53
Can you post your code in its current state? Or at the least, give us a better idea of what you're trying to do and where you're having problems.

ashb1025
27-02-2014, 12:45
This is the code, the idea of it is to work like a check list for each of the buckets, say you have buckets 1-4 it'll check bucket 1 for a infrared signal if it doesn't get one it moves on to bucket 2, if it does then it dumps the block in the bucket and moves to the closest ramp.16394, I apologize I don't know how to get the code to display in the post

RyanCahoon
27-02-2014, 13:09
It looks like you're pretty close; you just need to repeat the check for each of the buckets. You can either copy-and-paste the code as many times as you need (probably 4 in this case), but a more maintainable way would be to use a loop.

for(int i = 0; i < 4; i++)
{
// put code for a single basket here
}

--Ryan

P.S. You can use tags to inline code in your post. Look for the button with the # symbol in the post editor

ashb1025
27-02-2014, 13:14
Thank you, and 1 more question, would you happen to know how to read the returning values from the sensor and then how to use those values for a 2 conditional if statement? For example if the first conditional returns true and the second conditional returns > 100 then run the if statement

ashb1025
27-02-2014, 13:35
I was thinking it would be something like this but I don't know for sure
task main()
{
if (conditional1(sensor)==2)
{
if(conditional2(sensor) > 100)
{
//run bucket commands
}
else
{
//move on to next bucket
}

RyanCahoon
27-02-2014, 13:49
That would definitely work, and there's no problem with that, but you would need to have two identical else {} blocks (one on each of the two if statements) so that the "move on to next bucket" code would be run if either of the conditions was false.

An easier way to do this is to use the "and" operator to combine both if statements. In ROBOTC, you write this as &&

task main()
{
if (conditional1(sensor)==2 && conditional2(sensor) > 100)
{
//run bucket commands
}
else
{
//move on to next bucket
}
}

ashb1025
27-02-2014, 13:51
Thank you very much