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