Lego mindstorms intro

39

Transcript of Lego mindstorms intro

Page 1: Lego mindstorms intro
Page 2: Lego mindstorms intro

What is a Robot?

Page 3: Lego mindstorms intro

Robots Robots • A machine that is able to interact

with and respond to its environment in an autonomous fashion.

• A robot is characterized by three central capabilities: the ability to Sense, the ability to Plan, and the ability to Act. Sense, Plan, Act.

Page 4: Lego mindstorms intro

NXTNXT BrickBrick

• The electronic component that controls the operation of the robot by following instructions contained in a stored program. Based on these instructions and the data received from any connected sensors, the NXT can direct the actions of the robot to perform a large range of tasks.

Page 5: Lego mindstorms intro

SensorsSensors• A device that detects some important

physical quality or quantity about the surrounding environment, and conveys the information to the robot in electronic form. A Sound Sensor, for example, will detect, vibrations in the air, and send an electrical signal to the NXT indicating how strong those vibrations were.

Page 6: Lego mindstorms intro

TheThe KitKit

Page 7: Lego mindstorms intro

KitKit ManagementManagement

• Store Kit in same location

• At beginning of class get kit ready

• With 3 min left start cleaning

• Do not loose or break pieces

• Follow instructions

• Keep pieces in correct bin

Page 8: Lego mindstorms intro

FirstFirst RobotRobot

• Build the basic taskbot with no sensors attached located on Page 8 of the Mindstorms Education Book located in your kit.

Page 9: Lego mindstorms intro

ProgrammingProgramming• Once your robot has been constructed

the next step is to get it to do something. For that we are going to have to learn about Programming. Programming is the act of creating software or some other set of instructions for a Computer/Robot.

10100100 10010100 111100101 101010110 1101010101

Page 10: Lego mindstorms intro

Block ProgrammingBlock Programming

• A block is the basic unit of programming in the NXT programming software. Generally, one block represents one command given to the robot, although some blocks (such as the Loop block) are used instead to organize and control the execution of other blocks. Blocks perform their operations in order along the Sequence Beam

Page 11: Lego mindstorms intro

CodingCoding• Code: General term for any command or group

of commands in a program. In the NXT Programming Software, this is one or more blocks.

• Compiler: The compiler is a part of the NXT Programming Software that takes the blocks in a program and converts them into machine language that the NXT brick can understand and run. The compiled code is not exactly the same as the code written in blocks on your computer; this is why you cannot load the program back onto the computer once it is compiled and downloaded to the NXT.

Page 12: Lego mindstorms intro

Interactive Servo Motor

• The primary source of physical motion in the Mindstorms NXT system. The Interactive Servo Motors include both an electric motor (which allows them to spin the orange barrel portion of the motor on command) and a built-in rotation sensor. The rotation sensor allows the NXT to monitor the amount the motor has turned, and control the motors accordingly.

Page 13: Lego mindstorms intro

Blocks Blocks • Motor/Move Block: Blocks designed to

control motors on the robot. The Motor and Move blocks can both be used to control the movement of a robot, and have both advantages and disadvantages in doing so.

• Loop Block: In the NXT programming software, a programming block that repeats sequences of code. Its default behavior is to repeat the blocks it contains forever, but it can be configured to repeat them for given numbers of times, or under certain conditions.

Page 14: Lego mindstorms intro

Programming Activities

• Move Forward:• Move_motor_multi.rbt• Move_motor_same_line.rbt• Move_motorblock.rbt• Square Move:• Squaremove_no_loop.rbt• Squaremove_loop.rbt• Circle • Circle_1_moveblock.rbt• Figure 8• Figure 8_loop.rbt

Page 15: Lego mindstorms intro

Sound & Display Blocks Sound Block

Display Block

Use this block to display an image, write some text, or draw a shape on the NXT’s display screen.

You can use this block to play a sound file or a single tone. To compose a melody of tones, arrange several sound blocks in a row with each set to play different tones.

Page 16: Lego mindstorms intro

The Wait BlockThe 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.

Page 17: Lego mindstorms intro

Programming Activity

• Sounds.rbt – Use the sound blocks to make your robot make three different sounds. They can be words or notes.

• Display.rbt – Use the display block and the wait block to make something appear on your screen for 3 seconds then have another something else appear for 3 seconds. It can be either an image or text.

Page 18: Lego mindstorms intro

Lesson 3Lesson 3

Page 19: Lego mindstorms intro

Today’s Programs

• Detect Sound

• Sound Direction

• Sound Power

Page 20: Lego mindstorms intro

SensorsSensors• A device that detects some important

physical quality or quantity about the surrounding environment, and conveys the information to the robot in electronic form. A Sound Sensor, for example, will detect, vibrations in the air, and send an electrical signal to the NXT indicating how strong those vibrations were.

Page 21: Lego mindstorms intro

ImportantImportant ConceptsConcepts

• Input: Something which is sent to the NXT which is used in its program. An input is typically a sensor value sent by a sensor.

• Output: Something which NXT sends. An output is typically power sent to a motor.

Page 22: Lego mindstorms intro

The Wait BlockThe 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.

Page 23: Lego mindstorms intro

BlocksBlocks• Switch Block: In the NXT programming

software, a Switch block chooses between two sequences of code. For example, when configured with a Touch Sensor, the Switch block might run one series of blocks when the sensor is pressed and another when it is not pressed.

• Sound Sensor: An NXT sensor that detects sound waves and reports the amount of sound back to the NXT.

Page 24: Lego mindstorms intro

Programming Activity

• Detect Sound.rbt – a move block, a wait block and a stop block, create a program that will cause the robot to stop driving when you clap.

• Sound Direction.rbt – Using Loop, Switch, and move blocks, create a program that will cause your robot to drive forwards when it is quiet and backwards when it is loud.

• Sound Power.rbt – Using a loop block, a move block and a sound sensor block, create a program where your robot will go faster or slower depending on the volume around it. Remember to connect the data hub from the Sound Sensor Block to the power hub on the move block.

Page 25: Lego mindstorms intro

Data StuffData Stuff • Data: Factual information, like the weight of a robot or the value

of a sensor.

• Data Flow: The process of moving data inside of a program, so that information coming out of one block as data can be input into another block as a control.

• Data Hub: A feature of most programming blocks which can be accessed by clicking on the lower left edge of the block. Note that sometimes two clicks are required to extend the Data Hub completely. Data Hubs allow programming blocks to input (receive) or output (send) data through Data Wires.

• Data Plug:. Each Data Hub consists of a number of Data Plugs, which carry a specific type of data, including number data, logic data and text data.

• Data Wire: Wires that connect output plugs from one block’s data hub to input plugs on another block’s. To create a data wire, click on a data plug, drag the wire that appears to another Plug, and click again to wire the two Plugs together.

Page 26: Lego mindstorms intro

Data Hub Demonstration

• The Random Block and a Move block

Page 27: Lego mindstorms intro

Ultrasonic Sensor

• Ultrasonic sensors generate high frequency sound waves and evaluate the echo which is received back by the sensor. Sensors calculate the time interval between sending the signal and receiving the echo to determine the distance to an object.

Page 28: Lego mindstorms intro

Programming Activity

• Distance Stop.rbt – Using a loop block, switch block and 2 move blocks make your robot drive around until something is closer that 25cm. When it comes within 25cm of another object it should stop.

Page 29: Lego mindstorms intro

Programming Activity

• Distance Turn – Using a loop block, switch block and 2 move blocks make a program where your robot will drive around and avoid obstacles.

Page 30: Lego mindstorms intro

New Blocks

• Number to Text Block -This block will take a number (like a reading from a sensor) and turn it into text that can be displayed on the NXT’s screen. The input number can be typed in or supplied dynamically by a data wire.

Page 31: Lego mindstorms intro

Data StuffData Stuff • Data: Factual information, like the weight of a robot or the value

of a sensor.

• Data Flow: The process of moving data inside of a program, so that information coming out of one block as data can be input into another block as a control.

• Data Hub: A feature of most programming blocks which can be accessed by clicking on the lower left edge of the block. Note that sometimes two clicks are required to extend the Data Hub completely. Data Hubs allow programming blocks to input (receive) or output (send) data through Data Wires.

• Data Plug:. Each Data Hub consists of a number of Data Plugs, which carry a specific type of data, including number data, logic data and text data.

• Data Wire: Wires that connect output plugs from one block’s data hub to input plugs on another block’s. To create a data wire, click on a data plug, drag the wire that appears to another Plug, and click again to wire the two Plugs together.

Page 32: Lego mindstorms intro

Programming Activity

• Display Distance.rbt – Make a program where your display screen will show the distance from your ultrasonic sensor to the objects in front of it. Use a Sensor Block, Number to Text block and a Display Block.

Page 33: Lego mindstorms intro

Light Sensor

• The light sensor includes a light emitting diode (LED) light source that can be tuned on and off from software. This allows to measure either the reflected LED light shining back from an object or the ambient light falling on the sensor.

Page 34: Lego mindstorms intro

ThresholdThreshold:

• A “cutoff” or dividing line between two regions. One common use for thresholds is to divide the hundreds of possible sensor readings from a sensor (a Light Sensor can give a value anywhere from 0-100, for example) into two manageable categories.

Threshold = Value A + Value B

2

Page 35: Lego mindstorms intro

Programming Activity

• Stop at line.rbt – using 2 move blocks, and a wait block– make a program that will cause your robot to stop when it drives over the black line.

Page 36: Lego mindstorms intro

Programming Activity

• Follow Line.rbt – Using a loop, switch and 4 move blocks create a program that will cause your robot to follow the black line.

Page 37: Lego mindstorms intro

Programming Activity

• Basic sumo.rbt – create a program that will cause your robot to drive around inside the black sumo wrestling ring, with out falling out. – Loop, move, wait blocks.

Page 38: Lego mindstorms intro

Multitasking

Page 39: Lego mindstorms intro

Programming Activity

• Multitask.rbt – Using your basic sumo program, make it so if it senses an opponent closer that 30cm it will charge forward really fast.