We tried to use a vex sensor onto our FRC robot to be used to count revolutions by counting a series of alternating black and white tape on a motor. However there is something wrong with my code.
#include "Main.h"
void Autonomous ( void )
{
int c = 1;
unsigned char light;
int a = 0;
int b = 0;
int value = 0;
while ( value <= 5 ) //the transition of White to Black five times
{
SetPWM ( 10 , 190 ) ; //
SetPWM ( 11 , 190 ) ;
light = GetAnalogInput ( 1 ) ;
if ( light >= 0 && light <= 99 ) //interval of white (Bright)
{
a = 1 ;
PrintToScreen ( "a: %d
" , (int)a ) ;
PrintToScreen ( "Light: %d
" , (int)light ) ;
}
if ( light > 99 ) //interval of black (Dark)
{
b = 1 ;
}
if ( a == 1 && b == 1 )
{
value++ ; //problem starts here
a =0 ;
b = 0 ;
}
}
SetPWM ( 10 , 127 ) ;
SetPWM ( 11 , 127 ) ;
}
At the incremental of the variable value the RC begins to count continously up to five at the first instance and then it stops. I want it to only increment the variable value one at a time so that I can see a smooth transition. I started to believe that the vex light sensor is not capable to be used for FRC. Anyone know the problem or should I just use at gear tooth sensor. I appreciate the response.
Did you look at the analog output in the online window? Are you using the light sensor or the line following sensor? I believe the line following sensor would work better for the task you are looking for. Both work with FRC as they are just analog sensors.
I think you would find that a sensor using uses digital inputs and interrupt routines, like the gear-tooth sensor, more reliable.
I am not familiar with the vex light sensor, however we had success in the past with a Banner light sensor (digital output) that was included in the prior year KOP. (2004/5?)
Yes it is the line following sensor and yes I did look at the terminal window however, I feel that the transition between bright to dark can not be accurately be determined with the vex line following sensor. I believe our banner light sensor from years past cannot be located so it won’t do me any good as of now.
It uses IR, probably not desirable to use this year, considering all of the potential interference from remote controls and lap counters.
Can you describe the motor or mechanism you want to count RPMs?
Edit: I also notice that the sensor should be very close to the tape. 1/8" and from the spec sheet:
Because the line follower uses an infrared LED to illuminate its target
and an infrared sensor to detect the reflected light, it will actually
work in low-light conditions or even in the dark! However, this
also means that it can easily become saturated — in other words,
everything will look white to it, like an over-exposed photograph — in
environments where there is a lot of infrared radiation. You’ll find
environments like this in competition settings where tungsten lights are
used for illumination. To avoid saturating the infrared sensor,
consider mounting it underneath the robot or adding a cardboard
shield to block ambient radiation.
I apprecitate I just realized today that the sensor uses IR, so I will consider using some sort of border like the cardboard to protect it from other IR frequencies from reaching it. Today I figured out the problem with my code and it seems that I had to nest an if statement to compensate with the transition between a dark to bright color (black to white).
if ( light >= 1 && light <= 99 ) //interval of white (Bright)
{
light = getAnalogInput(1);
if (light > 99){
a = 1;
}
PrintToScreen ( "a: %d
" , (int)a ) ;
PrintToScreen ( "Light: %d
" , (int)light ) ;
}
if ( light > 99 ) //interval of black (Dark)
{
light = getAnalogInput(1);
if (light <= 1 && light <= 99){
b = 1 ;
}
}
if ( a == 1 || b == 1 )
{
value++ ;
a =0 ;
b = 0 ;
}
Now instead of counting RPM, I made so that a certain distance equals one count. Take for example that it takes 10 inches for one round of spins of the motor. If I want to go 20 inches all I would need to do is execute this process twice. I want to know if this idea is pratical to use. I plan on getting the correct measurements at competition.
We found that when using a Vex Line Following Sensor on An FRC bot it is much easier to use it as a digital input. Assuming you are using Black and White you will either get a 0 for black and a 1 for white or vice versa.
On another note if the IR sensor is about 3 inches away form our lap counter how much interference will it receive? I think I might just put some cardboard around it on all sides to be safe.
I just tested some Vex Sensors with some remotes and found that if used as a digital input the number will fluctuate rapidly between 1 and 0 when directly exposed. this goes away after about 2 feet or so. When used as an analog input the number still changes but not as rapidly.
Btw I used a universal remote setup for a magnavox, a samsung remote, and a comcast remote
That will work, but everything has to be in increments of (10"), so if you wanted to go 155 inches, you need to choose 150 or 160. This may or may not be a problem for you.
In our robot, we use a gear tooth sensor and can count to a fraction of an inch instead of a fraction of a foot.