View unanswered posts | View active topics It is currently Sat Sep 20, 2014 4:04 pm






Reply to topic  [ 4 posts ] 
Ir Seeker Trouble 
Author Message
Rookie

Joined: Mon Feb 27, 2012 5:26 pm
Posts: 20
Post 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.


Wed Oct 24, 2012 12:09 pm
Profile
Site Admin
Site Admin

Joined: Thu May 24, 2012 12:15 pm
Posts: 578
Post 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.

_________________
Check out our Blog! And our Facebook page!
Need help? Take a look at our Wiki and our Forums.

I just met you,
And this is crazy,
But here's my code now,
So fix it, maybe?
~ Carly Rae Jepsen parody


Wed Oct 24, 2012 12:20 pm
Profile
Rookie

Joined: Mon Feb 27, 2012 5:26 pm
Posts: 20
Post 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...


Wed Oct 24, 2012 1:03 pm
Profile
Novice

Joined: Sun Oct 21, 2012 10:01 pm
Posts: 76
Post 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).


Wed Oct 24, 2012 6:59 pm
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 4 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.