370 likes | 511 Views
Robofest NXT Programming Workshop Aug. 24, 2006 CJ Chung Associate Professor of Computer Science Lawrence Tech University CHUNG@LTU.edu www.Robofest.net. RoboLab, RCX code, and NXPL Follow a line and stop when the bumper is hit. Agenda. Intro to NXT Construction of NXT basic model
E N D
Robofest NXT Programming WorkshopAug. 24, 2006CJ ChungAssociate Professor of Computer ScienceLawrence Tech UniversityCHUNG@LTU.eduwww.Robofest.net chung
RoboLab, RCX code, and NXPLFollow a line and stop when the bumper is hit chung
Agenda • Intro to NXT • Construction of NXT basic model • Intro to NXT programming Language: Move, Loop, Sensors, Wait, Display and Switches • Advanced NXT Programming features: Advanced My Blocks, Multiple Tasks, and Variables • NXT Programming Tips • Intro to Thanksgiving RoboParade chung
Robots to be used • TriBot Driving Base (Robo Center, Quick Start Vehicle) • Add a bumper • Add a light sensor facing down chung
Exercises • Go forward 2 seconds and come back • Go forward 4 rotations and come back • Go forward 720 degrees and come back chung
Spin Right 90 degrees 1.1 rotations What is wrong? chung
Turn Right 90 degrees 1.1 rotations What is wrong? chung
Turn Right (spin) 90 degrees How to connect beams? How to extend beams? chung
Parallel Sequence Beam • Move the mouse point over the starting point (or over the wire stub), and pressing and holding your mouse button while you move the mouse upwards or downwards – not reliable… • Easier way chung
My Blocks • Wrap a procedure into a package • To do the same thing from different places; to reuse code; to make code non-redundant • To divide a large task into smaller meaningful modules (provide structure) • To hide complex details chung
How to create MyBlocks • Start with working code • Highlight blocks to include • Click the “Create My Block” button • Name the MyBlock • Describe the MyBlock • Build icon(s) • MyBlock replaces the selected Blocks chung
How to reuse the MyBlock • Select it from the Custom Tab chung
A loop with a MyBlock Square! chung
Comments • Use balloon text tool • Add the following information • Author, when • Who made changes, when • How to use • Functions • Block descriptions • Assumptions • Expected results • Known bugs • Rooms to improve • Etc. chung
Sensors • Touch • Light • Sound (microphone) • Ultrasound (Distance measurement) • Rotation – embedded in the motors • Timer – Internal sensor • NXT buttons • Received messages chung
Touch Sensor • Pressed • Released • Bumped - (pressed and released) or (released and pressed) chung
Light Sensor • Percent mode • 5% - lowest dark • 100% - very bright • Shines a red light • The light can be turned off – detecting ambient (surrounding light) • Live updates: See lower left corner!!!! chung
If light sensor is on the black line, the robot says “Black”; otherwise “White” – Sensor Switch chung
Ex. Modify the previous program to repeat the function endlessly when a touch sensor is pressed chung
Loop until a touch sensor is pressed Display seconds until touch sensor is pressed. Cf. RCX code Repeat Until Cf. RCX code Repeat While chung
Rotation Sensor • Each motor has an embedded rotation sensor • 360 counts per rotation • The counter can be incremented or decremented • Distance traveled can be calculated: Circumference = 2 x radius x π chung
Ex. Rotation Sensor Wait: Stop when Motor B has turned 370 degrees chung
Variable • Variables are memory containers that hold numeric values • They enable the NXT to collect and store information • You can change the value during your program • Useful to pass values to MyBlocks!!! chung
Creating a Variable • EDIT | Define Variables • Create • Name the variable (as meaningful as possible) • Select a data type • Number • Text • Logic (True / False) chung
Move forward until the robot reaches a black line (area) orhit a wall (detected by a touch sensor) Exercise: chung
How to make parameterized MyBlocks • Introduce variables to the working code • Highlight blocks to include only the working code part without variables • Click the “Create My Block” button • … chung
Not covered advanced topics • Cascading Switches • Data Hubs, and • synchronization of multiple tasks • … chung
NXT Programming Tips (Known Bugs) • Do not update firmware - freeze • “Out of Memory” problem • Do not use sound to much • Do not display graphics • Minimize number of programs on NXT • Delete unnecessary programs • Some small bugs chung
Personal Comments on NXT • Looks not stable yet • Some concepts of RCX code programming may be better • Hard to read small texts • Do not forget to add comments! • No separate NXT division in Robofest 2007 chung