This program turns the motor on until the touch sensor is pressed, then displays "Hello, World!" on the NXT screen.
This program runs the motor until the touch sensor is pressed and stops the while loop causing the motor to brake.
This example enables a NXT car with a light sensor to detect when it has reached the edge of a table, back up, and turn in a random direction, this continues until the program is stopped.
You may notice that a NXT car with a steering value of 0 does not drive in a straight line. This problem can be resolved by implementing proportional control, where the motor steering input is a function of the difference between the motor rotation readings.
You may notice that a NXT car with independently controlled wheels might not be able drive in a straight line even though the power setting on the motors are the same. Slight differences in the motors and wheels cause them to rotate at different rates. This problem can be resolved by implementing proportional control, where the power setting of the motors is a function of the difference between the motor rotation readings.
motor A power = constant + gain*(encoder A - encoder C)
motor C power = constant - gain*(encoder A - encoder C)
This example should approximately represent the second hand of a clock as it goes around.
This program turns the motor on for five seconds, at 50 percent power, then stops the motor.
This program turns the motor on, waits for 360 degrees of rotation and then stops the motor.
This example illustrates how to write a proportional, integral controller for the NXT. On the front panel, the user inputs the desired position (in degrees) of the motor. The user can also adjust the control gains, Kp and Ki which affects the input power of the motor. Kp is a proportional gain, it scales the difference between the motor's current position and the desired position--this difference is known as the error. Ki is an integral gain, it scales the total accumulated error during the program. Play around with the gains to see what works the best.
This program uses multiple motors and multiple touch sensors. When it begins motor A runs forward until touch sensor 1 is pressed, motor B then begins to run until touch sensor 2 is pressed.