Thread: IR Code RobotC
View Single Post
  #2   Spotlight this post!  
Unread 04-10-2012, 21:42
RyanCahoon's Avatar
RyanCahoon RyanCahoon is offline
Disassembling my prior presumptions
FRC #0766 (M-A Bears)
Team Role: Engineer
 
Join Date: Dec 2007
Rookie Year: 2007
Location: Mountain View
Posts: 689
RyanCahoon has a reputation beyond reputeRyanCahoon has a reputation beyond reputeRyanCahoon has a reputation beyond reputeRyanCahoon has a reputation beyond reputeRyanCahoon has a reputation beyond reputeRyanCahoon has a reputation beyond reputeRyanCahoon has a reputation beyond reputeRyanCahoon has a reputation beyond reputeRyanCahoon has a reputation beyond reputeRyanCahoon has a reputation beyond reputeRyanCahoon has a reputation beyond repute
Re: IR Code RobotC

Start by reading through your second program, and restating it in English:

When the program starts, it does three comparisons, seeing whether the value returned by the IR sensor is equal to, greater than, or less than 5. Only one of these will be true. Based off of the results of these comparisons, it sets the motors to either drive straight, turn right or turn left. Then, regardless of the case, the program waits for 5 seconds. Then the program exits.

From this description, we can conclude that the program is only checking the IR sensor one time. As to why it always defaulted to the third case, it's possible that when the program first starts, the sensor gets a couple of bad readings because it's still "warming up." You wouldn't notice these in the first program because it's checking the sensor continuously a couple hundred times a second.

If you want the program to only run for a certain amount of time and then stop, I would recommend using the first program, but changing the while loop condition to stop looping after a certain amount of time. You can check out the RobotC docs on Timing for more info, but here's what I would suggest:

Code:
task main()
{
time100[T1] = 0;
while(time100[T1] < 50)
{

// insert sensor if statements here

}
}
__________________
FRC 2046, 2007-2008, Student member
FRC 1708, 2009-2012, College mentor; 2013-2014, Mentor
FRC 766, 2015-, Mentor