Hello. I recently finished creating a very simple IR code that basically tells the robot to drive parallel to the ring rack until the IR beacon mounted to the side of the robot detects that the beacon is directly in front of the sensor. The robot then turns so the ring rack is in front of it, then it drives forward and places the ring. However, the wood platform in the middle that holds the ring rack causes a variation so that the turn the robot takes to face the dispenser after it detects the IR becomes inconsistent depending on which peg the IR is on. To fix that, we added another IR beacon mounted to the front of the robot, which is ideally supposed to cause the robot to stop when it is perfectly straight with the dispenser to make sure the turn aligns the robot to score perfectly every time. However, I was having an issue with having two “if” statements. When I tested the code I created, the robot did not stop directly in front of the dispenser when the second IR beacon reached the middle value, it instead went forward. I believe this to be because the other beacon is attempting to move the robot according to its commands when the robot changed position. Is there any way to make it so that the first “if” statement is temporarily nullified while the second “if” statement is occurring? Below is my code, and any help would be greatly appreciated in determining how to nullify the first “if” statement while the second one is taking place, or if I should just restructure the code entirely. Thanks again!
JIT
Code:
#pragma config(Hubs, S1, HTMotor, HTMotor, none, none)
#pragma config(Sensor, S3, IRSeeker2, sensorHiTechnicIRSeeker1200)
#pragma config(Motor, mtr_S1_C1_1, motorD, tmotorTetrix, openLoop)
#pragma config(Motor, mtr_S1_C1_2, motorE, tmotorTetrix, openLoop)
#pragma config(Motor, mtr_S1_C2_1, motorF, tmotorTetrix, openLoop, reversed)
#pragma config(Motor, mtr_S1_C2_2, motorG, tmotorTetrix, openLoop, reversed)
//!!Code automatically generated by ‘ROBOTC’ configuration wizard !!//
task main()
{
motor[motorD] = 100;
motor[motorE] = 100;
motor[motorF] = 100;
motor[motorG] = 100;
wait1Msec(400);
motor[motorD] = 0;
motor[motorE] = 0;
motor[motorF] = 0;
motor[motorG] = 0;
motor[motorD] = 100;
motor[motorE] = 100;
motor[motorF] = -100;
motor[motorG] = -100;
wait1Msec(500);
motor[motorD] = 0;
motor[motorE] = 0;
motor[motorF] = 0;
motor[motorG] = 0;
while(1 == 1)
{
if(SensorValue[IRSeeker2] == 5)
{
motor[motorD] = 0;
motor[motorE] = 0;
motor[motorF] = 0;
motor[motorG] = 0;
}
if(SensorValue[IRSeeker2] > 5)
{
if(SensorValue[IRSeeker] == 5;
{
motor[motorD] = 0;
motor[motorE] = 0;
motor[motorF] = 0;
motor[motorG] = 0;
}
else
{
motor[motorD] = 100;
motor[motorE] = 100;
motor[motorF] = -100;
motor[motorG] = -100;
}
}
if(SensorValue[IRSeeker2] < 5)
{
motor[motorD] = 100;
motor[motorE] = 100;
motor[motorF] = 100;
motor[motorG] = 100;
}
}
}