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

IRSeeker Problems
http://www.robotc.net/forums/viewtopic.php?f=41&t=5308
Page 1 of 1

Author:  PanthersRage [ Sat Dec 29, 2012 10:29 am ]
Post subject:  IRSeeker Problems

Still kind of new to this site and wasn't sure if I was suppose to post this here.

But, my issue is in the programming of the IRSeeker. (I'll try to post the code below).

But the problem is that it is suppose to move forward without a signal from the IR Beacon, but seems to only go in circles. (Because I would assume, 0 signal is read as < 5) I have 2 Seekers for this project, but I am mainly concerned with IRSeeker2

So, is there way to properly set up a range? Where it will turn if it is between 1 and 5 and go forward when it is 0?

Thank you so much! :D

The Code:

Code:
#pragma config(Hubs,  S1, HTMotor,  HTMotor,  none,     none)
#pragma config(Sensor, S1,     ,               sensorI2CMuxController)
#pragma config(Sensor, S2,     IRSeeker2,      sensorHiTechnicIRSeeker1200)
#pragma config(Sensor, S3,     IRSeeker3,      sensorHiTechnicIRSeeker1200)
#pragma config(Motor,  mtr_S1_C1_1,     motorD,        tmotorTetrix, openLoop)
#pragma config(Motor,  mtr_S1_C1_2,     motorE,        tmotorTetrix, openLoop, reversed)
#pragma config(Motor,  mtr_S1_C2_1,     motorF,        tmotorTetrix, openLoop)
#pragma config(Motor,  mtr_S1_C2_2,     motorG,        tmotorTetrix, openLoop)
//*!!Code automatically generated by 'ROBOTC' configuration wizard               !!*//

task main()
{
  while(1 == 1)
 {

   if(SensorValue[IRSeeker2] == 5)
  {
     motor[motorD] = 25;
     motor[motorE] = 25;
  }


   if(SensorValue[IRSeeker2] > 5 )
  {
     motor[motorD] = 20;
     motor[motorE] = -20;
  }


  if(SensorValue[IRSeeker2] < 5)
  {
     motor[motorD] = -20;
     motor[motorE] = 20;
  }


  if(SensorValue[IRSeeker3] > 5)
  {
     motor[motorF] = 40;
  }

   if(SensorValue[IRSeeker3] < 5)
  {
     motor[motorF] = -40;
  }

   if(SensorValue[IRSeeker3] == 5)
  {
     motor[motorF] = 0;
  }
 }
}

Font size:

Tip: Styles can be applied quickly to selected text. Font colour

Author:  mightor [ Sat Dec 29, 2012 10:46 am ]
Post subject:  Re: IRSeeker Problems

Hi there,

I edited your post to put your code in inside [ code][/ code] brackets. Make sure you do this yourself on your next post. Just select the code with your mouse and hit the "Code" button just below the "subject" text field.

Anyway, to check for a range, you could do something like this:
Code:
if ((variable >= 1) && (variable <= 5))
{
  do_something();
}


= Xander

Author:  MHTS [ Sat Dec 29, 2012 1:03 pm ]
Post subject:  Re: IRSeeker Problems

You have two IR seekers. Would you explain how they are used? We use two IR seekers too for triangulation. If that's what you are doing, you could add their values together and check for 10 as the value ahead. Regardless, you could simplifier your current code by:
Code:
if ((IrDir == 0) || (IrDir == 5))
{
    // go forward
}
else if (IrDir < 5)
{
    // go left
}
else if (IrDir > 5)
{
    // go right
}

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