View unanswered posts | View active topics It is currently Sun Sep 21, 2014 6:11 pm






Reply to topic  [ 3 posts ] 
IRSeeker Problems 
Author Message
Rookie

Joined: Fri Nov 18, 2011 1:59 pm
Posts: 6
Post 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


Sat Dec 29, 2012 10:29 am
Profile
Moderator
Moderator
User avatar

Joined: Wed Mar 05, 2008 8:14 am
Posts: 3223
Location: Rotterdam, The Netherlands
Post 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

_________________
| Professional Conduit of Reasonableness
| (Title bestowed upon on the 8th day of November, 2013)
| My Blog: I'd Rather Be Building Robots
| ROBOTC 3rd Party Driver Suite: [Project Page]


Sat Dec 29, 2012 10:46 am
Profile WWW
Guru
User avatar

Joined: Sun Nov 15, 2009 5:46 am
Posts: 1347
Post 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
}


Sat Dec 29, 2012 1:03 pm
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 3 posts ] 

Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  



Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software for PTF.