
Re: Robot only runs when plugged into comp. w/ USB to Serial
Yes we realized this last week, the sonar was not working till we made this change. Here is the code we are using.
const tSensors sonarSensor = (tSensors) in5; //sensorSONAR //*!!!!*//
//*!!CLICK to edit 'wizard' created sensor & motor configuration. !!*//
task main ()
{
wait1Msec(2000);
bMotorReflected[port2] = 1;
while (SensorValue[sonarSensor] > 5 || SensorValue[sonarSensor] < 0 ) // drive to far wall
{
motor [port2] = 63;
motor [port3] = 63;
}
motor [port2] = 0; //pause
motor [port3] = 0;
wait1Msec(500);
motor [port2] = 63; //turn 180
motor [port3] = -63;
wait1Msec(1143);
while (SensorValue[sonarSensor] > 5 || SensorValue[sonarSensor] == -1) // drive to near wall
{
motor [port2] = 63;
motor [port3] = 63;
}
}
While hooked to the computer, the program runs well. First the time delay, then the first while loop until we trigger the sensor, then the turn, then the last while loop. When off the computer it just does the "wait1Msec(2000);" and the turn.