advanced nxt-g programming · nxt execution flow read sensor values and place in i/o map hand...

29
Advanced NXT-G Programming John Field Former Software Group Manager for MINDSTORMS® NXT

Upload: others

Post on 12-Jul-2020

0 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Advanced NXT-G Programming · NXT Execution Flow Read sensor values and place in I/O Map Hand control over to the VM VM executes part of the rxe file May read sensor values from

Advanced NXT-G Programming

John FieldFormer Software Group Manager

for MINDSTORMS® NXT

Page 2: Advanced NXT-G Programming · NXT Execution Flow Read sensor values and place in I/O Map Hand control over to the VM VM executes part of the rxe file May read sensor values from

Agenda

Benefits of MINDSTORMS Software v1.1

Complete Palette Overview

Datahubs and Wiring

Decision Making using Logic and Compare

Variables

Q & A

Page 3: Advanced NXT-G Programming · NXT Execution Flow Read sensor values and place in I/O Map Hand control over to the VM VM executes part of the rxe file May read sensor values from

Benefits of v1.1

Vista & Intel-based Mac support

Improved Performance on all OSes

Smaller Compiled Files (.rxe) on the NXT

Large Programs are easier to build

Lots of small features & bugs fixed

Page 4: Advanced NXT-G Programming · NXT Execution Flow Read sensor values and place in I/O Map Hand control over to the VM VM executes part of the rxe file May read sensor values from

PC Software Stack

fll.rbt

Blocks MyBlocks

MINDSTORMS Editor

Programs

MINDSTORMS Compiler

LabVIEW Engine

Fantom driver

VISA Engine

OS USB OS Bluetooth

MINDSTORMS.exe

Fantom.dll

Page 5: Advanced NXT-G Programming · NXT Execution Flow Read sensor values and place in I/O Map Hand control over to the VM VM executes part of the rxe file May read sensor values from

NXT Software Stack

fll.rxe

NXT VM

I/O Map

NXT FW

rxe files are the executable version of the rbt

NXT VM - Runs programs (now execute this block...)

NXT FW - Handles low level details (such as reading a sensor or handling Bluetooth)

I/O Map - Interface between them

Page 6: Advanced NXT-G Programming · NXT Execution Flow Read sensor values and place in I/O Map Hand control over to the VM VM executes part of the rxe file May read sensor values from

NXT Execution FlowRead sensor values and place in I/O Map

Hand control over to the VM

VM executes part of the rxe file

May read sensor values from I/O map

May update I/O map to tell motors to run

Motors look at the I/O map to determine what to do

Repeat

Page 7: Advanced NXT-G Programming · NXT Execution Flow Read sensor values and place in I/O Map Hand control over to the VM VM executes part of the rxe file May read sensor values from

CompletePalette

Common

Action

Sensor

Flow

Data

Advanced

Page 8: Advanced NXT-G Programming · NXT Execution Flow Read sensor values and place in I/O Map Hand control over to the VM VM executes part of the rxe file May read sensor values from

Move

Rec/Play

Sound

Display

Wait

Loop

Switch

Common

Page 9: Advanced NXT-G Programming · NXT Execution Flow Read sensor values and place in I/O Map Hand control over to the VM VM executes part of the rxe file May read sensor values from

Good for multiple motor operations.

NXT FW synchronizes the motors

Less susceptible to battery levels with turns

Move

Page 10: Advanced NXT-G Programming · NXT Execution Flow Read sensor values and place in I/O Map Hand control over to the VM VM executes part of the rxe file May read sensor values from

Motor

Sound

Display

Send Message

Motor*

Lamp*

Action

Page 11: Advanced NXT-G Programming · NXT Execution Flow Read sensor values and place in I/O Map Hand control over to the VM VM executes part of the rxe file May read sensor values from

Good for single motor operations.

Allows for fine grain control

Ramping

Motor Power

When should I use move with 1 motor?

Motor

Page 12: Advanced NXT-G Programming · NXT Execution Flow Read sensor values and place in I/O Map Hand control over to the VM VM executes part of the rxe file May read sensor values from

Touch

Sound

Light

Ultrasonic

NXT Buttons

Rotation

Timer

Receive Message

Sensor

Touch*

Rotation*

Light*

Temperature*

Page 13: Advanced NXT-G Programming · NXT Execution Flow Read sensor values and place in I/O Map Hand control over to the VM VM executes part of the rxe file May read sensor values from

Logic

Math

Compare

In Range

Random

Variable

Data

Page 14: Advanced NXT-G Programming · NXT Execution Flow Read sensor values and place in I/O Map Hand control over to the VM VM executes part of the rxe file May read sensor values from

Datahubs and Wires4 Data Wires

Number

Logic

Text

Broken

2 Types of Hubs

Input/Pass-through

Output Only

Page 15: Advanced NXT-G Programming · NXT Execution Flow Read sensor values and place in I/O Map Hand control over to the VM VM executes part of the rxe file May read sensor values from

You can move wires, but they don’t look selected.

Undo is your friend.

To find and fix all broken wires

Go to forums.nxtasy.org

Search for “broken wire”

Warning: You are getting to the edge of the software. The editor isn’t always

cooperative.

http://forums.nxtasy.org/index.php?showtopic=444&hl=broken%20wires&st=0

Wiring

Page 16: Advanced NXT-G Programming · NXT Execution Flow Read sensor values and place in I/O Map Hand control over to the VM VM executes part of the rxe file May read sensor values from

Decision using Logic

Go forward for 2 rotations or the robot is within a foot of an object.

Let’s build it!

Page 17: Advanced NXT-G Programming · NXT Execution Flow Read sensor values and place in I/O Map Hand control over to the VM VM executes part of the rxe file May read sensor values from

Decision using Switch

Print “above” to the display if either the sound or light sensor exceeds 50. Otherwise, print “below”.

Let’s take a look.

Page 18: Advanced NXT-G Programming · NXT Execution Flow Read sensor values and place in I/O Map Hand control over to the VM VM executes part of the rxe file May read sensor values from

Complex Decision

If the light sensor intensity is between

0-25: play a low tone

26-75: play a middle tone

76-100: play a high tone

Also, output the region to the display

Let’s take a look at this program.

Page 19: Advanced NXT-G Programming · NXT Execution Flow Read sensor values and place in I/O Map Hand control over to the VM VM executes part of the rxe file May read sensor values from

VariablesCreate in each program & My Block that needs access

Good for

Counting

Saving Rotations

Passing data to one or more MyBlocks

Edit:Define Variables...

Page 20: Advanced NXT-G Programming · NXT Execution Flow Read sensor values and place in I/O Map Hand control over to the VM VM executes part of the rxe file May read sensor values from

Count Claps

Page 21: Advanced NXT-G Programming · NXT Execution Flow Read sensor values and place in I/O Map Hand control over to the VM VM executes part of the rxe file May read sensor values from

Store Rotations

Page 22: Advanced NXT-G Programming · NXT Execution Flow Read sensor values and place in I/O Map Hand control over to the VM VM executes part of the rxe file May read sensor values from

Variable Scope

Variables with the same name are shared globally when a program is running

fll.rbtrotations

MyBlock1rotations

rotations

Page 23: Advanced NXT-G Programming · NXT Execution Flow Read sensor values and place in I/O Map Hand control over to the VM VM executes part of the rxe file May read sensor values from

Variable Scope

To avoid problems like this, use MyBlock1_rotations & MyBlock2_rotations

fll.rbt MyBlock1

MyBlock2

rotations

rotations

rotations

Page 24: Advanced NXT-G Programming · NXT Execution Flow Read sensor values and place in I/O Map Hand control over to the VM VM executes part of the rxe file May read sensor values from

Text

Number to Text

Keep Alive

File Access

Calibrate

Reset Motor

Advanced

Great Debugging Tools

Page 25: Advanced NXT-G Programming · NXT Execution Flow Read sensor values and place in I/O Map Hand control over to the VM VM executes part of the rxe file May read sensor values from

Without Reset Motors

180 coast 180-coast

Total360

Page 26: Advanced NXT-G Programming · NXT Execution Flow Read sensor values and place in I/O Map Hand control over to the VM VM executes part of the rxe file May read sensor values from

With Reset Motors

180 coast 180

Total360 + coast

Page 27: Advanced NXT-G Programming · NXT Execution Flow Read sensor values and place in I/O Map Hand control over to the VM VM executes part of the rxe file May read sensor values from

Favorites

thenxtstep.blogspot.com

LEGOEngineering.com - click Podcasts

forums.nxtasy.org

thefieldhousehold.com/Web/NXT.html

Page 29: Advanced NXT-G Programming · NXT Execution Flow Read sensor values and place in I/O Map Hand control over to the VM VM executes part of the rxe file May read sensor values from

Q & A