INTRODUCTION TO NXTG Part 1



INTRODUCTION TO NXTG Part 1

1. Introduction:

The heart of the Lego MindStorms NXT system is the NXT brick (controller). It is a 16-bit microprocessor, you can plug in all sensors in ports at the bottom of the brick and you can plug all motors at the top. Any programs you write to control the robot are stored in the brick. Programs can be written in a visual programming language, NXT G, or traditional programming languages like Java or C. In this class, you will use NXT G.

[pic]

The figure above shows the NXT brick, and the functionality of each button.

Motors can be plugged into output ports A, B, or C. If you are communicating with the NXT via a USB cable then you plug in the USB cable to the USB port at top of the NXT brick. We can also communicate with the NXT using Bluetooth; the BT level light shows the signal strength and the status of the connection. We can connect the sensors to the input ports shown as 1, 2, 3, and 4. You navigate through the screen using the control keys on the brick. The key in the middle is the enter key and it is used to turn on the brick. The left and right keys are used to navigate through the different levels of the menus on the screen and the small button, under the enter key, is the back button. To turn off the NXT brick, press the back button all the way top, and press back button again. Then press enter to turn off.

Sensors:

[pic]

Light Sensor:

The light sensor is used to measure light. It can be done in two ways:

• Reads light intensity from surroundings

• Reads reflection from IR emitter.

Ultrasonic Sensor:

Ultrasonic sensor measures distance. It can measure up to 3-4ft from robot.

Sound Sensor:

Sound Sensor senses the sound level.

Touch Sensor:

Touch Sensor is just a simple switch that the NXT brick can use to detect when it comes in contact with something.

Motors:

The motors are really efficient devices in the NXT system. There is a rotation sensor built into this motor, so that the NXT brick knows exactly how much the orange colored axel has rotated. The NXT brick can control two or three motors at a time.

[pic]

Building the Robo:

Install the CD given in the kit (Lego Mindstorms).

• After installing go to the “Robo Center” and click on vehicles as shown.

[pic]

• Click the go button as shown

[pic]

• Go to “1.Driving Base” and click on “quickstart”.

[pic]

• Go to “building guide” and click on “start”. Follow the instructions and build the robot.

2. To start a new program: Click on file on the top of the tool bar, and click on the “new” menu item. You will get a window to start the new program which is named as “untitled 1” and so on… You can rename the program to whatever you want.

3. Explanations of some programming blocks used:

3.1 MOVE BLOCK:

You can find this block at the top left corner of the Lego Mindstorm program shown as

[pic]

We can select this block and drag it on the screen. When we drag the block on to the middle window in the software, then it is displayed as shown

[pic]

The descriptions for symbols:

[pic]

1. The letters at the top right corner of the block show which of the ports on the NXT brick will be controlled.

2. This icon shows which direction your robot will go.

3. This icon shows the power level. Your robot’s speed may also be affected by other conditions, like the surface it is moving over or whether it is moving up or down a slope.

4. This icon shows whether you have set the Duration property to unlimited, degrees, rotations, or seconds.

When the move block is selected the control panel at the bottom of the window gives you lots of information about what you can do with the move block, the move block can control more than one motor at a time. The control panel is shown below.

[pic]

1. Select the motors you would like to control. If you choose to control two motors (Example: B & C), the motors will be synchronized, going forward or backwards at exactly the same power. If you select three motors, motors B & C will be synchronized.

2. Choose whether the motors will go forward, go backwards, or stop. Selecting Stop will also reset the motors.

When you set a Move or Motor blocks' direction, you are specifying the direction the motor will spin. This may be different than the direction your robot actually moves. Depending on how you build your robotic invention, setting the motors to go forwards may cause your creation to move backwards. The image below shows a motor spinning in the default, forwards direction.

[pic]

3. If you’re using two motors to drive a vehicle (with one on each side), the Steering slider will appear with the chosen port letters indicated at each side. Move the slider to set a curved path for your robot. With the slider all the way to either side, your vehicle will spin in place means one motor spins forward and another one spins backward.

4. This slider and the editable input box will let you set the power level [0-100%].

5. Using the Duration pull-down menu, you can set the motors to run for an unlimited interval or for a set number of seconds, rotations [default] or degrees. By choosing Time, Rotation or Degrees you can control how far your robot will travel.

6. Choose whether the motors will brake or coast after they’ve finished their action. If you want your robot to stop precisely at an exact location, set the motors to brake. Setting your motors to brake will also keep your robot from slowly rolling backwards on a slope but the setting will wear out the NXT’s batteries quicker because the motors are doing work to keep the robot in place.

7. The feedback boxes will count how many degrees or full rotations your motors turn. Press the reset button to return the values to zero. (To receive feedback, make sure that the motors are connected to the chosen ports and that communication has been established with the NXT.)

3.2 LOOP BLOCK:

The loop block can be selected from left middle corner of the program shown as

[pic]

When we drag this on to the program, it will be displayed as:

[pic]

We can place any other block, for example the move block inside the loop block

[pic]

1. When a Loop block’s action property is set to “Forever,” an infinity symbol (∞) is displayed at the bottom of the trailing portion of the block.

2. If the “Show Counter” checkbox is selected in the configuration panel, a plug will appear that will allow you to use the number of completed loops as an input elsewhere in your program (if you connect a data wire from the plug to another block’s data hub). You can also use current count to control the loop itself

3. If you choose for a sensor to control the loop, the trailing portion of the Loop block will expand in size revealing an icon for the chosen sensor. For example, if you choose a Light Sensor to control the loop, a Light Sensor icon will be displayed in the expanded portion of the block. Also, any relevant information about the chosen control property will displayed at the bottom of the block.

When we select the loop block we will get a configuration window at the bottom of the program window

[pic]

The Control property pull-down menu will let you choose from five primary conditions that will affect your loop:

• Forever [default]

• Time

• Sensor (which will activate a second pull-down menu)

o Touch Sensor

o Light Sensor

o Sound Sensor

o Ultrasonic Sensor

o NXT Buttons

o (Built-in) Rotation Sensor

o Timer

o Receive Message

• Count

• Logic

3.3 WAIT BLOCK:

This block lets your robot sense its environment for a certain condition before it continues. Use the slider or type in a value to set a trigger point so that the program continues when sensor values are below or above it.

[pic]

1. The number or letter at the top right corner of the Wait block shows the port the block is monitoring. The configuration panel, which is described below, will let you change ports if necessary.

2. If you have chosen to wait for a light, sound, or ultrasonic sensor, this icon indicates at what level the trigger point is set; the more colored bars displayed, the higher the trigger point. If you have chosen to wait for a touch sensor, the icon will display the touch sensor condition (bumped, pressed, or released) that will trigger the block and allow the program to move on.

Configuring the Wait Block

The Control property pull-down menu will let you choose from two primary conditions to wait for:

• Sensor (which will activate a second pull-down menu)

o Touch Sensor

o Sound Sensor

o Light Sensor

o Ultrasonic Sensor

o NXT Buttons

o (Built-in) Rotation Sensor

o Timer

o Receive Message

4. BLOCKS TO CONTROL SENSORS

4.1 Touch Sensor

[pic]

Choose “Touch Sensor” and your program will wait for a touch sensor to be bumped, pressed, or released before going on the next block in your program.

1. Choose the port that the touch sensor is connected to. By default, the block will be set to port 1 for a touch sensor.

2. Use the radio buttons to specify whether you want the touch sensor to be bumped, pressed, or released to let the program continue. Choose Bumped if you want the block to be triggered after a quick press and release of the touch sensor. Choose Pressed if you want the block to be triggered at the instant the touch sensor is pressed in. Choose Released if you want the block to be triggered at the instant the touch sensor is released.

3. The feedback box will let you test your touch sensor. When the sensor is activated on your robot, the number 1 will be displayed here.

4.2 Sound Sensor

[pic]

Choose “Sound Sensor” and your program will wait for the sound sensor to be activated by a certain intensity of sound.

1. Choose the port where your sound sensor is plugged in. By default, the block will be set to port 2 for a sound sensor.

2. Use the slider to set the trigger value or type a value into the input box. Select the radio button to the right of the slider if you want the block to be triggered by sound levels higher than the trigger value; select the left radio button to trigger the block with sound levels lower than the trigger value. You can also use the pull-down menu to set the “true” portion of the slider.

3. The feedback box displays the current sound reading (0-100%). You can use it to try out different trigger values.

4.3 Light Sensor

[pic]

Choose “Light Sensor” and your program will wait for a light sensor to be activated by a certain intensity of light.

1. Choose the port where your light sensor is plugged in. By default, the block will be set to port 3 for a light sensor.

2. Use the slider to set the trigger value or type a value into the input box. Select the radio button to the right of the slider if you want the block to be triggered by light levels higher than the trigger value; select the left radio button to trigger the block with light levels lower than the trigger value. You can also use the pull-down menu to set the “true” portion of the slider.

3. If you check the “Generated Light” checkbox, the light sensor will turn on its own small light source and detect this light if it is reflected back to it.

4. The feedback box displays the current light reading (0-100%). You can use it to try out different trigger values.

4.4 Ultrasonic Sensor

Ultrasonic or SONAR (Sound Navigation And Ranging) sensors from one opening of the sensor emit a high frequency sound wave (~40 KHz) which bounces off an object and returns to the other opening of the sensor. Based on the time elapsed, the distance traveled is calculated. The reading depends on the surface type that the wave reflects off. The distance to smooth reflective surfaces will be detected more accurately than irregular surfaces.

[pic]

Choose “Ultrasonic Sensor” and your program will wait for the ultrasonic sensor to be activated by detecting an object at a certain distance.

1. Choose the port where your Ultrasonic sensor is plugged in. By default, the block will be set to port 4 for an ultrasonic sensor.

2. If you choose the radio button to the left of the slider, the block will be triggered when it detects an object that is closer than the trigger distance; select the right radio button to trigger the block when it detects an object farther away than the trigger distance. Use the slider to set the trigger distance or type a value directly into the input box (0-250 if configured for centimeters or 0-100 if configured for inches. Remember that highly reflective surfaces can be detected farther away than non-reflective surfaces.

3. Select to read values in Centimeters or Inches.

4. The feedback box displays the current ultrasonic reading (0-250 cm or 0-100 inches). A reading of 0 indicates the closest distance the sensor can detect. If configured for centimeters, a reading of 250 indicates the farthest distance the sensor can detect (i.e., roughly 250 cm). If configured for inches, a reading of 100 indicates the farthest distance the sensor can detect (i.e., roughly 100 in).

4.5 NXT Buttons

[pic]

If you choose “NXT Buttons,” the program will wait for a chosen NXT button to be bumped, pressed, or released before moving on.

1. Select which NXT button will send out a “true” signal when activated and cause the program to move on.

2. Choose Bumped if you want the chosen button to be activated after a quick press and release. Choose Pressed if you want the chosen button to be activated at the instant the button is pressed in. Choose Released if you want the chosen button to be activated at the instant the button is released.

4.6 (Built-in) Rotation Sensor

[pic]

If you choose “Rotation Sensor,” the program will advance when a motor has turned a set number of rotations or degrees.

1. Choose the port where your motor is plugged in.

2. Use the radio buttons to set the direction you want: forwards or backwards.

3. Choose to count either Rotations or Degrees by using the pull-down menu.

4. Type the number of rotations or degrees you want to go by before your program moves forward).

5. The feedback box will display the current number of rotations or degrees. Use the reset button to clear the feedback box.

4.7 Timer

[pic]

If you choose “Timer,” the program will advance when one of the NXT’s internal timers reaches a certain time value.

1. Choose the NXT timer that you would like to monitor.

2. Type a time value (in seconds) in the input box. You can use the arrows to increase or decrease the value.

4.8 Receive Message

[pic]

If you choose “Receive Message,” the program will advance when your NXT receives a certain Bluetooth message.

1. The pull-down menu will let you select the message type (Text, Number, or Logic) of the message that you expect to receive.

2. To compare the incoming message to a test message, either type in the test text or number (if you have chosen Text or Number respectively as the format), or use the radio buttons to choose the test logic value (true or false).

3. Choose the mailbox number where the incoming message will arrive.

4.9 Touch* Sensor

[pic]

Choose “Touch* Sensor” and your program will wait for a touch sensor to be bumped, pressed, or released before going on the next block in your program.

1. Choose the port that the touch sensor is connected to. By default, the block will be set to port 1 for a touch sensor.

2. Use the radio buttons to specify whether you want the touch sensor to be bumped, pressed, or released to let the program continue. Choose Bumped if you want the block to be triggered after a quick press and release of the touch sensor. Choose Pressed if you want the block to be triggered at the instant the touch sensor is pressed in. Choose Released if you want the block to be triggered at the instant the touch sensor is released.

3. The feedback box will let you test your touch sensor. When the sensor is activated on your robot, the number 1 will be displayed here.

4.10 Light* Sensor

[pic]

Choose “Light* Sensor” and your program will wait for a light sensor to be activated by a certain intensity of light.

1. Choose the port where your light sensor is plugged in. By default, the block will be set to port 3 for a light sensor.

2. Use the slider to set the trigger value or type a value into the input box. Select the radio button to the right of the slider if you want the block to be triggered by light levels higher than the trigger value; select the left radio button to trigger the block with light levels lower than the trigger value. You can also use the pull-down menu to set the “true” portion of the slider.

3. The feedback box displays the current light reading (0-100%). You can use it to try out different trigger values.

4.11 Rotation* Sensor

[pic]

If you choose “Rotation* Sensor,” the program will advance when a rotation* sensor has turned a set number of ticks (16 per rotation).

1. Choose the port where your rotation sensor is plugged in. By default, the block will be set to port 2 for a rotation sensor. You can change this selection if you need to.

2. Use the radio buttons to set the direction you want: forwards or backwards.

3. Set the trigger point by typing a value into the input box. Choose greater than (>) if you want the block to be triggered when the number of ticks (16 to a rotation) is more than the trigger value; choose less than ( ................
................

In order to avoid copyright disputes, this page is only a partial summary.

Google Online Preview   Download