Robot Activity: Programming the NXT 2.0 About this Activity In this activity, you will learn about some features of the NXT 2.0 programming software. You will write and save a program for the Lego NXT robot. Finally, you will download the program and run the program on the Lego NXT robot. ****************************************************************************** I. Make sure that your robot batteries are charged. II. Robot Activity Linear Speed - Programming Your Robot Launch the Mindstorms NXT 2.0 program on your computer. Enter a file name for the new program in the Start New Program field (over type Untitled1). For example, use the file name speed. Select the Go >> button. The following screen is used to graphically create your program. At the bottom of the left column select the center tab to display the omplete palette, green, orange, and yellow squares. Math with Robots Project: Robot Activity Programming the NXT 2.0 Program Pyzdrowski, 6/26/2012-1
The omplete palette contains six programming categories on the left side: ommon: Move, Record/Play, Sound, Display, Wait, Loop, and Switch. Action: Motor, Sound, Display, Send Message, Lamp * Sensor: Sound Sensor, Ultrasonic Sensor, Rotation Sensor, Receive Message, Touch Sensor, Light Sensor, NXT Buttons, Timer, Temperature Sensor Flow: Wait, Loop, Switch, Stop Data: Logic, Math, ompare, Range, Random, Variable, onstant Math with Robots Project: Robot Activity Programming the NXT 2.0 Program Pyzdrowski, 6/26/2012-2
Advanced: Text, File Access, Reset Motor, Stop Datalog, Number to Text, Keep Alive, alibrate, Start Datalog Bluetooth onnection At the bottom of the left column select the left tab, green circle, to display the ommon palette. The ommon pallette contains the same programming objects as the ommon category under the omplete pallette: Move, Record/Play, Sound, Display, Wait, Loop, and Switch. At the bottom of the left column select the right tab, two blue rectangles, to display the ustom palette. The ustom pallette contains two selections: My Blocks Web Downloads Programming is accomplished by selecting a program object and dragging it onto the sheet and dropping it into position in the program. This process forms a graphical chart of the program. There are parameters associated with some program objects. A help facility is located on the bottom right side of the development window. This help facility is used to better understand the programming objects. Math with Robots Project: Robot Activity Programming the NXT 2.0 Program Pyzdrowski, 6/26/2012-3
Select the ommon palette. Select, drag, and drop the Move object into the program sequence where the blue start square is located. Notice that the Move object replaces the blue start square and the Move parameters will be displayed on the bottom of the development window. Initially the Move parameters are set to make the motors B and move forward one rotation. You can select which of the three motor Ports A, B, or are controlled; the Direction of Forward, Backward, or Stop; the amount of Power they receive (speed); the Duration in Degrees, Rotations, Seconds, or Unlimited; how the motors transition into the Next Action by Breaking or oasting; and how the Steering will be performed. Keep the settings defaulted with Ports B and selected, a Forward Direction, no Steering, a Power of 75, a Duration of one rotation, and the Next Action of Brake. Math with Robots Project: Robot Activity Programming the NXT 2.0 Program Pyzdrowski, 6/26/2012-4
From the Wait menu, select, drag, and drop the Time object into the program sequence after the Move object. Notice that the Time parameters will be displayed on the bottom of the development window. Keep the settings defaulted with the ontrol selection of Time and the Until selection of one Second. The Wait menu allows for the insertion of a Time, or a Sensor ontrol object. The ontrol objects are used to pause processing until the completion of an event. Time will wait for a specified number of Seconds. The Sensor object allows the selection of the type of sensor and the appropriate parameters for the sensor selected. The Touch, Light, Sound, and Distance sensors are directly available in the Wait menu. The program now has a Move of one rotation followed by a Wait of one second. Select, drag, and drop the Loop object into the program sequence after the Wait object. Notice the Loop parameters will be displayed on the bottom of the development window. Math with Robots Project: Robot Activity Programming the NXT 2.0 Program Pyzdrowski, 6/26/2012-5
hange the ontrol to Sensor. hange the Sensor to NXT Buttons. hange the Button to Enter button, the square orange button on the NXT controller. Make sure the Action is Pressed. The Loop object allows for code looping. Program objects are placed inside the loop object. The loop ontrol can process Forever, until a Sensor action occurs, for a specific Time in seconds, for a specified ount of loops, or the until the Logic state of a connected Sensor to the loop block becomes true or false. Select, drag, and drop a new Move object into the program sequence inside the Loop object. Keep the settings defaulted with Ports B and selected, a Forward Direction, no Steering, a Power of 75, a Duration of one rotation, and the Next Action of Brake. This loop will test the Enter button at the end of the loop. When the Enter button is pressed the loop will terminate. Math with Robots Project: Robot Activity Programming the NXT 2.0 Program Pyzdrowski, 6/26/2012-6
The program now has a Move of one rotation followed by a Wait of one second then a Loop containing a one rotation Move. The loop will terminate when the Enter button is pressed. Save the program. onnect the NXT controller to the computer using the USB cable. Turn the NXT on. Select the NXT icon on the lower right of the screen. Select SAN from the pop up window. When the NXT appears in the list (USB), connect to it by selecting it from the list and selecting ONNET. Once connected, close the NXT pop up window. Select the download button which is located beneath the NXT button. When complete, disconnect the USB cable from the robot and run the speed program on the NXT controller by selecting My Files, Software files, speed, and finally press the orange enter button to run the program. To stop the NXT, press the orange enter button. Math with Robots Project: Robot Activity Programming the NXT 2.0 Program Pyzdrowski, 6/26/2012-7