Go to Post Our team has a forum..... chiefdelphi.com Ok I had to say it. - Mike Martus [more]
Home
Go Back   Chief Delphi > Technical > Programming
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Closed Thread
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 02-10-2012, 21:09
Just_In_Time Just_In_Time is offline
Registered User
no team
 
Join Date: Jul 2012
Rookie Year: 2010
Location: United States
Posts: 18
Just_In_Time is an unknown quantity at this point
IR Code RobotC

Hello. I am a student on a FTC team with a question regarding IR sensor coding in RobotC. I was recently working on a program that uses the IR Beacon for this year's FTC Game. I started off with a more basic and conventional IR Code as follows:

task main()
{
while(1 == 1)
{
if(SensorValue[IRSeeker2] == 5)
{
motor[motorD] = 50;
motor[motorE] = 50;
motor[motorF] = -50;
motor[motorG] = -50;
}

if(SensorValue[IRSeeker2] > 5)
{
motor[motorD] = 50;
motor[motorE] = 50;
motor[motorF] = 50;
motor[motorG] = 50;
}

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

This worked very well and did exactly what it was intended to do; follow the IR beacon infinitely. However, when looking at the code and testing it with the IR beacon on the ring dispenser I realized I needed something that stopped a just slightly before reaching the ring rack so that we could place the ring instead of the code going on infinitely. Below is the code that I came up with.

task main()
{
if(SensorValue[IRSeeker2] == 5)
{
motor[motorD] = 50;
motor[motorE] = 50;
motor[motorF] = -50;
motor[motorG] = -50;
wait1Msec(5000);
}

if(SensorValue[IRSeeker2] > 5)
{
motor[motorD] = 50;
motor[motorE] = 50;
motor[motorF] = 50;
motor[motorG] = 50;
wait1Msec(5000);
}

if(SensorValue[IRSeeker2] < 5)
{
motor[motorD] = -50;
motor[motorE] = -50;
motor[motorF] = -50;
motor[motorG] = -50;
wait1Msec(5000);
}
}

However, this didn't work as intended. Instead of doing the desired task when the IR beacon was at different positions, each time it defaulted to the third section which is what it is supposed to do only when the sensor value is < 5. I made sure that it wasn't a physical problem with the bot by running our previous code and it still worked as well as it did before. Therefore, I am a tad stuck as to why it isn't changing when the beacon is in different positions. Any help with this would be very much appreciated. Thanks.

JIT
  #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
  #3   Spotlight this post!  
Unread 05-10-2012, 21:45
Just_In_Time Just_In_Time is offline
Registered User
no team
 
Join Date: Jul 2012
Rookie Year: 2010
Location: United States
Posts: 18
Just_In_Time is an unknown quantity at this point
Re: IR Code RobotC

Thank you very much; that was exactly what I was looking for.

JIT
Closed Thread


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -5. The time now is 00:44.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi