Report 2:

Introduction to Programming NXT

By Team 5:

Christopher Harbourne

Eric Sheldon

Session 4 Assignment

Uploaded on 5/22/17

Part 1 Questions:

Include a listing of the program

Program 1 was titled start.nxc, A Simple Sensor-Activated System.

Describe in words what the program should do.

This program is designed to keep the wheels running in an infinite loop, due to the while (true) statement. Every time the sensor is pressed, given a minimum of 400 milliseconds has passed, the wheels reverse direction.

Describe the actual performance of the robot when you run the program

When this program is run, it does exactly as we expected. It starts off running the wheel in the forward direction. Every time we pressed the sensor, the motor reversed direction, and this continued an infinite loop until we aborted the program.

What happens when you touch the switch?

When the switch is touched, the motors receive a signal from the brick to reverse direction.

What do you think the statement ‘until (SENSOR_1 == 1);’ does?

This statement prevents the program from progressing to the next line, reversing direction, until the switch is pressed. The program cannot progress past this true/false condition until the true condition has been met.

What do you think the punctuation marks ; mean?

The semicolon is used to mark the end of a statement, so it is clear where one statement ends and another one begins.

What do the back-to-back until statements accomplish?

They prevent the program from progressing past themselves until their condition has been met (true).

Why is the second ‘until’ statement until(SENSOR_1 == 0); needed?

This statement is necessary to prevent continuous reversals from happening if the sensor is accidentally held down. This prevents the program from progressing to the point where it can reverse the motors until the sensor has been released and has met the condition of (=0).

Part 2 Questions:

Include a listing of the program

Program 2 is titled tribot1.nxc, Drive Straight Ahead.

Describe in words what the program should do.

This is a simple program written to make the Tribot drive forward at 75% power for 5 seconds and then come to a stop.

Describe the actual performance of the robot when you run the program

When we first attempted to compile the program, we discovered two errors. The #define function was in all capital letters when it should have been all lowercase, and line ten was missing the closing bracket after the condition. Once this was fixed, the compilation and download went smoothly. When the program was run, the Tribot did exactly what we expected. It drove perfectly straight for 5 seconds and stopped. No power adjustment to either motor was necessary.

What is the effect of changing the values of the power level? What happens when power level is small but not 0?

Changing the power levels changed the speed at which the Tribot moved. The lower the power, the slower it went. When we set the level to any value below 9, there did not appear to be enough power to move the Tribot. Once we had it on 9, it began to inch forward, very slowly.

Part 3 Questions:

Include a listing of the program

Program 3 was titled tribot2.nxc, Drive and Turn.

Describe in words what the program should do.

This program is written to start the Tribot off driving straight at 75% power. It then includes an infinite while (true) loop where it alternates between turning for 2 seconds and then driving forward for 1 second, alternating which direction it turns each iteration.

Describe the actual performance of the robot when you run the program

This program also ran as expected. With the initial time conditions, the Tribot drove forward about 6 inches and then rotated in alternate directions approximately 270 degrees. Playing around with it and adjusting the time definitions gave us varying degrees of rotation on the turns, and varying distances traveled in the straight portions.

General Questions:

What is the role of the curly braces { }?

The curly brackets define a statement or set of statements that all belong to a specific, defined task.

What does the statement Wait(5000); do?

The statement instructs the brick to wait until the (time=5000 milliseconds) condition has been met before progressing to the next line of code.

What does the statement while(true) {....} do?

The ‘while’ statement defines a condition that must be met as true for the instructions in the following lines to begin, and when false, to stop. Putting the term ‘true’ in the brackets after ‘while’ sets it always equal to true, creating an infinite loop of the subsequent instructions.

Contributions:

Both of us built the Tribot and reviewed/practiced the three programs.

The report was typed up by Chris.