Hi there, I want to write a program in robotc NXT that will make the robot to move above a black strip and when it find a white object it remove it from is way and when it finds a black object it by pass it and return back to the black track......help!!. This is my first attempt to write an NXT robot code and this what i have right now.
#pragma config(Sensor, S4, sonarSensor, sensorSONAR)
#pragma config(Sensor, S1, colorPort, sensorCOLORFULL)
//*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//
task main()
{
string sColor;
int distance_in_cm = 20; // Create variable 'distance_in_cm' and initialize it to 20(cm).
while(1)
{
if(SensorValue[sonarSensor] > distance_in_cm) // While the Sonar Sensor readings are less than the specified, 'distance_in_cm':
{
motor[motorB] = 20;
motor[motorC] = 20;
}
else if (SensorValue[sonarSensor] < distance_in_cm)
{
switch (SensorValue[colorPort])
{
case BLACKCOLOR: sColor = "Black";
motor[motorC] = -10; // Motor C is run at a 75 power level.
motor[motorB] = -10;
wait1Msec(1000);
motor[motorC] = 360; // Motor C is run at a 75 power level.
motor[motorB] = -360;
break;
case WHITECOLOR: sColor = "White";
motor[motorA] = 1;
wait1Msec(100);
motor[motorB] = 0;
motor[motorC] = 0;
wait1Msec(1000);
motor[motorA] = -10;
wait1Msec(100);
motor[motorA] = 10;
wait1Msec(100);
break;
default: sColor = "???";
motor[motorB] = 0;
motor[motorC] = 90;
wait1Msec(100000);
break;
}
nxtDisplayCenteredTextLine(2, sColor);
wait1Msec(50);
}
}
}
I appreciate your time and help