|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
|
|
Thread Tools | Rate Thread | Display Modes |
|
|
|
#1
|
|||
|
|||
|
FTC Block Party IR-Sensor
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.
|
|
#2
|
||||
|
||||
|
Re: FTC Block Party IR-Sensor
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.
|
|
#3
|
|||
|
|||
|
Re: FTC Block Party IR-Sensor
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.AutonomousIR.c, I apologize I don't know how to get the code to display in the post
|
|
#4
|
||||
|
||||
|
Re: FTC Block Party IR-Sensor
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.
Code:
for(int i = 0; i < 4; i++)
{
// put code for a single basket here
}
P.S. You can use tags to inline code in your post. Look for the button with the # symbol in the post editor |
|
#5
|
|||
|
|||
|
Re: FTC Block Party IR-Sensor
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
|
|
#6
|
|||
|
|||
|
Re: FTC Block Party IR-Sensor
I was thinking it would be something like this but I don't know for sure
Code:
task main()
{
if (conditional1(sensor)==2)
{
if(conditional2(sensor) > 100)
{
//run bucket commands
}
else
{
//move on to next bucket
}
|
|
#7
|
||||
|
||||
|
Re: FTC Block Party IR-Sensor
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 && Code:
task main()
{
if (conditional1(sensor)==2 && conditional2(sensor) > 100)
{
//run bucket commands
}
else
{
//move on to next bucket
}
}
Last edited by RyanCahoon : 27-02-2014 at 14:06. |
|
#8
|
|||
|
|||
|
Re: FTC Block Party IR-Sensor
Thank you very much
|
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|