+ All Categories
Home > Documents > LEGO Mindstorms NXT Carnegie Mellon Dacta Lego Timothy Friez Miha Štajdohar...

LEGO Mindstorms NXT Carnegie Mellon Dacta Lego Timothy Friez Miha Štajdohar...

Date post: 19-Dec-2015
Category:
View: 214 times
Download: 0 times
Share this document with a friend
Popular Tags:
42
LEGO Mindstorms NXT LEGO Mindstorms NXT Carnegie Mellon Dacta Lego Timothy Friez Miha Štajdohar [email protected] SOURCES: SOURCES:
Transcript

LEGO Mindstorms NXTLEGO Mindstorms NXT

Carnegie MellonDactaLegoTimothy FriezMiha Š[email protected]

SOURCES:SOURCES:

Principles of RoboticsIntegrity. Robots hold together throughout the competition (no small

task when you are talking about robots built out of Legos).

Accuracy. The robot's mechanical outputs and its location acquisition and feedback to the RCX and subsequent programming provide the intelligence for precise performance.

Execution. The robot performs the tasks it was designed to accomplish.

Repeatability. The robot can perform the exact routine time and time again.

Ergonomics. The robot is easy to handle, reconfigure, and change batteries or reprogram if necessary.

Efficiency. The robot's design makes optimal use of its parts to execute tasks, minimize friction, and use power.

Why students learn more when Why students learn more when they participate in a real they participate in a real

challenge?challenge?

Sophisticated robots can be buildSophisticated robots can be build

• Accuracy of mapping Accuracy of mapping program and NXTprogram and NXT– Draw letter “E”Draw letter “E”– Circle ProgramCircle Program– Light Following on Light Following on

simulationsimulation

• More videos at More videos at http://www.youtube.com/ehttp://www.youtube.com/ece191nxtce191nxt

Examples of mobile Examples of mobile and humanoid and humanoid

robots robots • MotivationMotivation• Project OverviewProject Overview• Hardware SpecificationHardware Specification

– Lego RobotLego Robot• Programming Programming

EnvironmentsEnvironments– NXCNXC– RobotCRobotC

• Method and ApproachMethod and Approach• IdeasIdeas• DesignDesign

Mindstorms NXT• mindstorms.lego.com

Mindstorms NXT• mindstorms.lego.com

Ideas

• youtube.com

• ...

Brick

• 4 sensor inputs• 3 sensor inputs / motor outputs • Programmable

Purchasing NXT Kits

• Two options (same price; $250/kit)– Standard commercial kit– Lego Education kit

• http://www.lego.com/eng/education/mindstorms/

• Advantages of education kiteducation kit– Includes rechargeable battery ($50 value)– Plastic box superior to cardboard– Extra touch sensor (2 total)

• Standard commercial kitcommercial kit– Includes NXT-G visual language

From Idea to From Idea to Pseudo-Code to Pseudo-Code to software to robot software to robot

behaviorbehavior

Thinking about Programming

Creating a successful robot takes a team effort between humans and machines.

Role of the RobotThe robot follows the instructionsit is given, thereby carrying out theplan.

Human/Machine Communication

1. Because humans and robots don’t normally speak the same language, a special language must be used to translate the necessary instructions from human to robot.

2. These human-to-robot languages are called programming languages.

3. Instructions written in them are called programs.

4. ROBOTC is just one of many such programming languages that humans use to talk to machines.

Think about “Behaviors”Behaviors are a convenient way to talk about what a robot is doing and what it must

do. Moving forward, stopping, turning, looking for an obstacle… these are all behaviors.

Complex BehaviorSome behaviors are big, like “solve the maze.”

• Basic or Simple Behavior1. Some behaviors are small, like

“go forward for 3 seconds.” 2. Big behaviors are actually made

up of these smaller ones.

Planning the Behaviors

The main principle is braking large behaviors into hierarchies of smaller The main principle is braking large behaviors into hierarchies of smaller and smaller behaviors. and smaller behaviors.

You have to understand every piece of input-output behavior of a robotYou have to understand every piece of input-output behavior of a robot

PSEUDOCODE1. As the programmer becomes

more experienced, the organization of the behaviors in English will start to include important techniques from the programming language itself, like programming language itself, like if-else statements and loopsif-else statements and loops.

2. This hybrid languagehybrid language, halfway between English and the programming language, is called pseudocode.

3. It is an important tool in helping to keep larger programs larger programs understandableunderstandable.

ROBOTC is text based!1. Commands to the robot are first written as text on the screen.

2. They are then processed by the ROBOTC compiler into a machine language file that the robot can understand.

3. Finally, they are loaded onto the robot, where they can be run.

Software development optionsSoftware development options

• Onboard programs– RobotC– leJOS– NXC/NBC

• Remote control– iCommand– NXT_Python

NXT Brick Features

• 64K RAM, 256K Flash

• 32-bit ARM7 microcontroller

• 100 x 64 pixel LCD graphical display

• Sound channel with 8-bit resolution

• Bluetooth radio

• Stores multiple programs– Programs selectable using buttons

Programming languages

• NBC, NXC• NXT Python, .NET

http://www.teamhassenplug.org/NXT/NXTSoftware.html

IDE – interactive development environment

Programming EnvironmentsProgramming Environments• NXC

– A High-level languageA High-level language– Similar to CSimilar to C– Stand-alone language (No Stand-alone language (No

plug-ins or add-ons)plug-ins or add-ons)– The program runs in the The program runs in the

robot itself.robot itself.

NXC On Bot

More Robust languageTakes and uses values

Robust language canGraphically represent

Desired input and results

NXT Python

• http://home.comcast.net/~dplau/nxt_python/index.html

• demo

• bluetooth

• remote control

Python IDE

Python Programming EnvironmentsPython Programming Environments

• Python 2.4.4Python 2.4.4– Scripted Scripted

Programming Programming LanguageLanguage

– Plug insPlug ins• PyGame: “Simulated PyGame: “Simulated

World”World”• PyODE: Shapes, PyODE: Shapes,

vectorsvectors• PyBluez: Bluetooth PyBluez: Bluetooth

communicationcommunication• Python NXT: Python Python NXT: Python

Libraries for NXTLibraries for NXT– Programs Programs

• Light SensorLight Sensor• Ultrasound SonarUltrasound Sonar• Sound SensorSound Sensor

Python NXT

PyBluez

PyODE PyGame

• Mapping ProgramMapping Program– Generate movement on NXT robot, record movement Generate movement on NXT robot, record movement

and plot robot’s path in real time in a simulated world.and plot robot’s path in real time in a simulated world.

• Python + SimulatorPython + Simulator– Thread function, lock on global objectsThread function, lock on global objects

• NXC + SimulatorNXC + Simulator– Separate program activates robot, simulator polls output valuesSeparate program activates robot, simulator polls output values

Moves Robot

Method and ApproachMethod and Approach

Sends motor readings

Starts Pygames

Draws readings on Pygames

ROBOTC

• firmware

• tasks, program loop

• Sensors, motors

• data

• bluetooth, messageswww.robotc.net

RobotC

• Commercially supported– http://www.robotc.net/

• Not entirely free of bugs• Poor static type checking• Nice IDE• Custom firmware• Costly

– $50 single license– $250/12 classroom computers

Bluetooth

• PyBluez

• http://org.csail.mit.edu/pybluez/

Motors• Configured in terms of percentage of

available power

• Built-in rotation sensors– 360 counts/rotation– No rotation sensors in old Lego

Working with MotorsWorking with Motors

• Selecting Your Hardware Platform

1. RobotC supports a variety of different hardware platforms.

2. For these exercises we will configure RobotC to include support for the Tetrix/FTC robots Tetrix/FTC robots as well as pure LEGO robotspure LEGO robots.

3. The “FIRST Tech Challenge (NXT)” platform is a superset of the “NXT” platform.

4. Whether your robot is using LEGO motors or the Tetrix 12V motors, you can control them with nearly identical code.

• On the Robot / Platform Type menu make sure that you have “FIRST Tech Challenge (NXT)” selected.

• Click on the New icon on the RobotC toolbar to start a new program.

Configuring your Motors• You need to tell RobotC how your motors are attached to your NXT. • On the Robot menu, open the Motors and Sensors Setup wizard

and select the FTC Servo/Motor Ctrl tab.

• A. Using LEGO NXT Motors– If your robot is using LEGO NXT motors for the drive wheels, select “No

controllers configured”:

Then go to the Motors tab and fill it in according to which ports your drive motors are plugged into. Make sure to enter the names “motorLeft” and “motorRight” correctly so that your robot will go in the correct direction.

Click OK.

Using pragmas

• Two #pragma#pragma statements and a comment line should have been inserted into your program looking something like this:

#pragma config(Motor, motorA, motorLeft, tmotorNormal, PIDControl)#pragma config(Motor, motorB, motorRight, tmotorNormal, PIDControl)

//*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//

• A #pragma#pragma is an instruction to the RobotC compiler to change something about how your program gets compiled.

• The config()config() pragma tells RobotC to automatically include the necessary necessary prefix code to configure your programprefix code to configure your program to use the motor and sensor ports you specified in the wizard.

Important recommendations to Robot C programmer

1. You should not modifyshould not modify these lines of code by hand.

2.2. If the configuration of your robot changesIf the configuration of your robot changes, go back into the Motor and Sensor Setup wizard and change the values there.

3. When you exit the wizard it will update the #pragmas to reflect the changes you made.

4. Comment lines in RobotC begin with “//”.

5. Everything that follows a double-slash to the end of the line is ingored by the compiler.

6. The comment inserted by the wizard is a reminder that the #pragmas preceeding it were automatically created for you.

A. Using Tetrix 12V Motors If your robot is using the Tetrix 12V motors for its drive wheels select the configuration that matches how your robot is wired. For example, if you have one motor controller plugged into sensor port 1 and one servo controller plugged into your motor controller, you should choose “Standard Configuration.”

Using Tetrix 12 Volt MotorsUsing Tetrix 12 Volt Motors

Then select the Motors tab, select “Motor equipped (12V)” in the lowest two Type dropdowns. Make sure to name them “motorRight” and “motorLeft” according to how your robot is wired. Also assuming that your motors are pointing away from each other, make sure to reverse one of them. Don’t worry about picking the right one to reverse right now. We’ll correct it later if necessary.

Click OK.

Using Tetrix 12 Volt MotorsUsing Tetrix 12 Volt Motors

• Three #pragma statements and a comment line should have been inserted into your program looking something like this:

• #pragma config(Hubs, S1, HTMotor, HTServo, none, none)#pragma config(Motor, mtr_S1_C1_1, motorRight, tmotorNormal, PIDControl, reversed)#pragma config(Motor, mtr_S1_C1_2, motorLeft, tmotorNormal, PIDControl)//*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//

• A #pragma is an instruction to the RobotC compiler to change something about how your program gets compiled.

• The config() pragma tells RobotC to automatically include the tells RobotC to automatically include the necessary prefix codenecessary prefix code to configure your program to use the motor and sensor ports you specified in the wizard.

Using Tetrix 12 Volt MotorsUsing Tetrix 12 Volt Motors

1. You should not modify these lines of code by hand.

2. If the configuration of your robot changes, go back into the Motor and Sensor Setup wizard and change the values there.

3. When you exit the wizard it will update the #pragmas to reflect the changes you made.

Using Tetrix 12 Volt MotorsUsing Tetrix 12 Volt Motors

1. Comment lines in RobotC begin with “//”.

2. Everything that follows a double-slash to the end of the line is ingored by the compiler.

3. The comment inserted by the wizard is a reminder that the #pragmas preceeding it were automatically created for you.

Using Tetrix 12 Volt MotorsUsing Tetrix 12 Volt Motors

Programming Your Motors

Enter a blank line or two after the code that was inserted by the Motor and Sensor Setup wizard and then type in the following:

task main() { motor[motorLeft] = 50; // Half power motor[motorRight] = 50;

wait1Msec(1000); // One second

motor[motorLeft] = 0; // Stop motor[motorRight] = 0; }

First example of Programming First example of Programming MotorsMotors


Recommended