Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   Programming (http://www.chiefdelphi.com/forums/forumdisplay.php?f=51)
-   -   FTC Block Party IR-Sensor (http://www.chiefdelphi.com/forums/showthread.php?t=127224)

ashb1025 26-02-2014 12:55

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.

RyanCahoon 26-02-2014 15:53

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.

ashb1025 27-02-2014 12:45

Re: FTC Block Party IR-Sensor
 
1 Attachment(s)
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.Attachment 16394, I apologize I don't know how to get the code to display in the post

RyanCahoon 27-02-2014 13:09

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
}

--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

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

ashb1025 27-02-2014 13:35

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
        }


RyanCahoon 27-02-2014 13:49

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
  }
}


ashb1025 27-02-2014 13:51

Re: FTC Block Party IR-Sensor
 
Thank you very much


All times are GMT -5. The time now is 02:29.

Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi