ROBOTC.net forums
http://www.robotc.net/forums/

Ir Seeker Trouble
http://www.robotc.net/forums/viewtopic.php?f=52&t=5024
Page 1 of 1

Author:  Casey890 [ Wed Oct 24, 2012 12:09 pm ]
Post subject:  Ir Seeker Trouble

Code:
#pragma config(Hubs,  S1, HTMotor,  HTMotor,  none,     none)
#pragma config(Sensor, S2,     Irseeker,       sensorHiTechnicIRSeeker1200)
#pragma config(Sensor, S3,     light,          sensorNone)
#pragma config(Sensor, S4,     sonar,          sensorNone)
#pragma config(Motor,  mtr_S1_C1_1,     right1,        tmotorTetrix, openLoop, reversed)
#pragma config(Motor,  mtr_S1_C1_2,     right2,        tmotorTetrix, openLoop, reversed)
#pragma config(Motor,  mtr_S1_C2_1,     left1,         tmotorTetrix, openLoop)
#pragma config(Motor,  mtr_S1_C2_2,     left2,         tmotorTetrix, openLoop)
//*!!Code automatically generated by 'ROBOTC' configuration wizard               !!*//

#include "JoystickDriver.c"




task main()
{
   while (1 == 1)
      if(SensorValue[Irseeker] == 5)
         {
  motor[left1]  =  15;
  motor[left2]  =  15;
  motor[right1] =  15;
  motor[right2] =  15;

}



      if(SensorValue[Irseeker] > 5)
         {
  motor[left1] =  -15;
  motor[left2] =  -15;
  motor[right1]=   15;
  motor[right2]=   15;
}
      if(SensorValue[Irseeker] < 5)
         {
  motor[left1] =    15;
  motor[left2] =    15;
  motor[right1] =  -15;
  motor[right2] =  -15;
}
}


This code I'm trying to use for now just to get inline and close to the IR beacon on our FTC field however it only works and goes forward when it == 5 but when it is <5 or>5 the robot is completely stationary I am having a bit of trouble please help. The goal is to drive at first like parallel for a bit to get closer and then have the IR seeker direct the robot with the beacon, but I don't know what I should do to ignore the ir beacon because I want it to satisfy ==5 so it is lined up very closely and then to maybe use a touch or light sensor combination.

Author:  JohnWatson [ Wed Oct 24, 2012 12:20 pm ]
Post subject:  Re: Ir Seeker Trouble

The problem with this one lies in the infinite loop; it does not have any opening or closing braces. In this case, ROBOTC will look at the line directly below the while loop as it's 'code' and will ONLY run that code inside of the loop. Since the first line under the while loop is the '== 5' line, the while loop will only be running that and the other two if statements are outside of the loop (and will never be reached because the while loop runs forever.

This one is a fairly simple fix:

Code:
task main()
{
   while (1 == 1)
   {
      if(SensorValue[Irseeker] == 5)
         {
  motor[left1]  =  15;
  motor[left2]  =  15;
  motor[right1] =  15;
  motor[right2] =  15;
         }

      if(SensorValue[Irseeker] > 5)
         {
  motor[left1] =  -15;
  motor[left2] =  -15;
  motor[right1]=   15;
  motor[right2]=   15;
         }

      if(SensorValue[Irseeker] < 5)
         {
  motor[left1] =    15;
  motor[left2] =    15;
  motor[right1] =  -15;
  motor[right2] =  -15;
          }
   }
}


By encompassing the rest of the code inside of the while loop, we can ensure that they are checked as well.

Author:  Casey890 [ Wed Oct 24, 2012 1:03 pm ]
Post subject:  Re: Ir Seeker Trouble

Thank you very much however I am a little bit embarrassed by that. I can't believe I forgot that scanner token...

Author:  amcerbu [ Wed Oct 24, 2012 6:59 pm ]
Post subject:  Re: Ir Seeker Trouble

It often helps to use RobotC's automatic tab formatting to find things like this. Go to Edit > Code Formatting > Format Whole File (or press Ctrl + Shift + Alt + F).

Page 1 of 1 All times are UTC - 5 hours [ DST ]
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/