samhuris

profileCR777
hw-04a_nxc-program-tracing.pdf

ECE-206 HW-04A Page 1 of 1

HW-04A: NXC Program Tracing

A robot is placed in the middle of west wall, facing east, of a square arena with walls on all sides

as shown below. A black strip is drawn from north to south in the arena. Each grid in the arena

drawing represents a distance of one second travel of the robot.

Trace the NXC program and draw the paths the robot travels.

// Hardware: a touch sensor mounted on the front bumper and connected to SENSOR_1. // a light sensor also mounted in the front and connected to SENSOR_2. // OUT_C is used to control the left motor and OUT_A is used to control // the right motor. Assume that when the robot makes a 90° turn, it makes a perfect 90°

task main( ) {

int i; SetSensor(S1, SENSOR_TOUCH); SetSensorType(S2, SENSOR_TYPE_LIGHT); SetSensorMode(S2, SENSOR_MODE_PERCENT); OnFwd(OUT_AC, 40); Wait(2000); for(i=0; i<4; i++) {

if (i % 2 = = 0) Off(OUT_A);

else Off(OUT_C);

Wait(1600); //Roverbot takes // 1.6 sec time to make a 90° turn OnFwd(OUT_AC, 40); Wait(1000);

} while (SENSOR_2 > 40)

OnFwd(OUT_AC, 40); Off(OUT_C); Wait(1600); //Roverbot takes 1.6 sec time to make a 90° turn do {

OnFwd(OUT_AC, 40); } while ( SENSOR_1 = = 0); Off(OUT_AC);

}