Variables, logic and sensors Day 3 Computer Programming through Robotics CPST 410 Summer 2009.

Slides:



Advertisements
Similar presentations
Introduction to Programming
Advertisements

Robofest 2005 Introduction to Programming RIS 2.0 RCX Code.
Getting started with LEGO NXT Mindstorms software This is intended to be a short introduction to the LEGO Mindstorms software and programming the LEGO.
Jason Howard. Agenda I. How to download robotc II. What is tele-op used for? III. How to build a basic tele-op program IV. Getting the robot to drive.
How Do You Make a Program Wait?. 1. What is an algorithm? 2. Can you think of a reason why it might be inconvenient to program your robot to always go.
Vex Robotics Introduction to Sensors. introduction to sensors Sensors assist robots in seeing and feeling the physical world through which they travel.
Programming with Alice Computing Institute for K-12 Teachers Summer 2011 Workshop.
More switches Day 6 Computer Programming through Robotics CPST 410 Summer 2009.
Bellevue University CIS 205: Introduction to Programming Using C++ Lecture 3: Primitive Data Types.
Introduction to a Programming Environment
EducateNXT NXT... an introduction The Kit and the Software.
Introduction to NXT Software and Functionality Bot’oberfest October 15, 2007.
1 ©2006 INSciTE Lab Two Task: Make the program from Lab One (Move forward 5 rotations and turn right 90 degrees) into a MyBlock.
RobotC For Beginners Tyler Lutz and Keaton Bonds DRSS Enterprise.
The NXT is the brain of a MINDSTORMS® robot. It’s an intelligent, computer-controlled LEGO® brick that lets a MINDSTORMS robot come alive and perform.
Reviewing Common Blocks for St. Agnes Elementary School Teachers by Jenny Chang Feb. 26th, 2007 USC & University Neighborhood Outreach Robotics STEM program.
LEGO Mindstorms NXT Programming We will be using the Common Palette for our Robots This is how you download your program onto the brick Drag and drop a.
Testbed: Exercises.
Loops and Switches. 1. What kind of blocks are these? 2. Name two kinds of controls that can be specified to determine how long a loop repeats. 3. Give.
Robotics Catchup/Review: switch, arithmetic, range, loop Bluetooth Lab: Finish parallel parking. Next: Use Bluetooth communication for calculate & send.
What is RobotC?!?! Team 2425 Hydra. Overview What is RobotC What is RobotC used for What you need to program a robot How a robot program works Framework.
Encapsulation Day 11 Computer Programming through Robotics CPST 410 Summer 2009.
GIRLS Robotic Camp. Let’s Begin Meet and Greet – Camp leaders introduce themselves – Students introduce themselves.
Programming 101 The Common Palette Content provided by Connor Statham (6 th Grade Student) Formatting by Shannon Sieber.
Adapted for STLP Camp ‘09 Mobile Robots Why do robots need to move?
Introduction to the Basic Parts of LEGO’s NXT Robotics
Coding for the FIRST Tech Challenge: RobotC
© The McGraw-Hill Companies, 2006 Chapter 4 Implementing methods.
IPC144 Introduction to Programming Using C Week 1 – Lesson 2
More switches, Comparison Day 7 Computer Programming through Robotics CPST 410 Summer 2009.
Robotics Overview of NXT-G Actuators in Mindstorms. Touch sensor Labwork: Right turn. Touch/bump. [Explore move versus Motor Move mini & motor mini. Motor*.]
Robotics Light sensor. Calibration. Reverse engineering challenge. Lab work: Create and show your program. Add light sensor (different orientations). Robot.
EV3 Workshop Oct 3, 2015 Instructor: Chris Cartwright
Downloading and Installing Autodesk Revit 2016
The LOGIC and MATH blocks Day 9 Computer Programming through Robotics CPST 410 Summer 2009.
C Hints and Tips The preprocessor and other fun toys.
Motors and Sound Troubleshooting Tips. © H-CCS Problem 1 Why can’t I download my program to the RCX?
Downloading and Installing Autodesk Inventor Professional 2015 This is a 4 step process 1.Register with the Autodesk Student Community 2.Downloading the.
Introduction to Data & Advanced Programming Blocks ROBOTICS II Module 1 Done by: Eng Nooran Drak.
BMTRY 789 Lecture 11: Debugging Readings – Chapter 10 (3 rd Ed) from “The Little SAS Book” Lab Problems – None Homework Due – None Final Project Presentations.
Conditions and loops Day 4 Computer Programming through Robotics CPST 410 Summer 2009.
Lego MindStorm An Introduction to Blocks. Blocks Blocks are used to give instructions to your robot. There are many types of blocks You can use the blocks.
Comparison the RANGE block Day 8 Computer Programming through Robotics CPST 410 Summer 2009.
LEGO MINDSTORM Session 1 Setup Brick Sound Brick Status Light
Robotics NXT-G: variables, file Rotation sensor Lab: Use buttons to hit specific ball. Homework: Postings. Start planning mapping the room.
 2008 Pearson Education, Inc. All rights reserved JavaScript: Introduction to Scripting.
EV3 Software EV3 Robot Workshop
Programming 101 The Common Palette Content provided by Connor Statham (9 th Grade Student) Formatting by Shannon Sieber.
Introduction to Computer Programming - Project 2 Intro to Digital Technology.
Programming - Motion Intro to Robotics. Motors and Sensors Setup The first thing we need to do is tell ROBOTC that we have motors on our robot. Choose.
ROBOTC Software EV3 Robot Workshop
Data Hubs and Wires. Begin by adding a basic Move block, 5 rotations 75% power.
Mindstorm NXT-G Introduction Towson University Robotics.
ROBOTC Software EV3 Robot Workshop Lawrence Technological University.
VEX and Robot C Chris Patterson Frisco ISD CTE Center Presented by.
Announcements Assignment 2 Out Today Quiz today - so I need to shut up at 4:25 1.
Vex Robotics program three: using motors and sensors together.
MEH108 - Intro. To Engineering Applications KOU Electronics and Communications Engineering.
Lego Mindstorm Robots 9797 kit.  Students will learn how to identify how to detect a change in a condition.  Students will learn where and how to identify.
How Do You Make a Program Wait?
LEGO Robotics Workshop
Understanding Communication with a Robot? Activity (60 minutes)
Loops and Switches Pre-Quiz
Automation and Robotics
Module F: Presentation Understanding Robot Fundamentals
Displaying sensor values while a robot is running
An Introduction to VEX IQ Programming with Modkit
The programming page of the Brick
Loops and Switches How Do You Make Loops and Switches? lesson > TeachEngineering.org Center for Computational Neurobiology, University of Missouri.
Getting started with LEGO EV3 Mindstorms software
Presentation transcript:

Variables, logic and sensors Day 3 Computer Programming through Robotics CPST 410 Summer 2009

7/1/09Harry Howard, CPST 410, Tulane University2 Course organization  Course home page Course home page  (  Lab (Newcomb 442) will be open for practice with 3-4 Macs, but you can bring your own laptop and all robots.

7/1/09Harry Howard, CPST 410, Tulane University3 PhotosPhotos

7/1/09Harry Howard, CPST 410, Tulane University4 Mindstorms NXT 2.0  You can preorder it now, and it will ship by 1 Aug  $  yTheme/Product.aspx? p=8547&cn=17 yTheme/Product.aspx? p=8547&cn=17

Wired! Kelly §7

7/1/09Harry Howard, CPST 410, Tulane University6 Hubs and wires  Kelly's introduction to wiring is not based on real NXT-G blocks, but rather on ones he made up for the sake of perspicuity.  I would rather you work with real blocks, so I will ignore his presentation. You should still read it, however.  We will go back to what we skipped in §3 (because it was wrong).

7/1/09Harry Howard, CPST 410, Tulane University7 Data hubs  The settings of many blocks can be changed from other parts of the program through their data hub.  Create a new program "VariableMove".  Drop a MOVE block into it.  Change its duration to degrees.  Make sure your motors are set correctly.  Put your cursor at the bottom of the MOVE block and try to pull down the indented line.

7/1/09Harry Howard, CPST 410, Tulane University8 The MOVE block data hub  Running the cursor over each icon reveals which setting it accepts.  If you have an Internet connection, click on the 'More help' link at the bottom right.

7/1/09Harry Howard, CPST 410, Tulane University9 The VARIABLE block  To illustrate the usefulness of the data hub, we will try out a new block that does not come up in detail until §18, the VARIABLE block.  Change to the Complete palette (the three interlocking squares at the bottom left).  Select the big orange plus sign (Data),  pull out a suitcase (Variable), and  drop it in front of the MOVE block.

7/1/09Harry Howard, CPST 410, Tulane University10 Using the VARIABLE block  The list shows the three types that a variable can have: Logic, Number, and Text.  Number and Text mean what they say; Logic we will take up later.  Change the type from Logic to Number.  Note that the action is set to Read and the value (0) is grayed out so that you cannot change it.  We want to change it, so set it to Write and change the value to 180.  In programming terms, we have declared a variable of type number and name 'Number 1' and set its value to 180.

7/1/09Harry Howard, CPST 410, Tulane University11 Using the VARIABLE block, cont.  However, we cannot use the variable yet.  We have to make it available to the rest of the program by reading it, but a VARIABLE block can only be set to read or write, not both.  So drop another VARIABLE block after the first.  Set its type to Number.  Set its action to Read.  Now pull out a wire from its output plug and connect it to the MOVE input plug for Duration.  You might not get it right the first time, but persevere.

7/1/09Harry Howard, CPST 410, Tulane University12 The program  Now we can use the variable.  Save, download, and run the program.  How far does your Tribot go?  180 degrees, because the setting on the MOVE data hub for Duration only accepts degrees.

7/1/09Harry Howard, CPST 410, Tulane University13 Let's display something  Drop a DISPLAY block after the MOVE block.  What should we display?  How about the number of degrees the wheels turn?  Pull down the data hub of the DISPLAY block.  Where would we connect the VARIABLE block to display its value?  CRUCIAL LIMITATION: Type cannot change.  Most of the input plugs are for numbers, but these numbers are used in positioning something on the LCD screen (and selecting the diameter of a circle).

7/1/09Harry Howard, CPST 410, Tulane University14 Type conversion  The trick is to display the number 180 as the text "180".  But these two objects are of different types.  NXT-G only supplies one block for type conversion, in the Complete palette under the Advanced icon (four squares).  The NUMBER TO TEXT block.

7/1/09Harry Howard, CPST 410, Tulane University15 The NUMBER TO TEXT block  Drop one between the MOVE and DISPLAY blocks.  Pull a wire out of the Duration output plug of the MOVE block and connect it to the input plug of the NUMBER TO TEXT block.  Again, this may take some trial and error.  Pull a wire out of the output plug of the NUMBER TO TEXT block and connect it to the Text input plug of the DISPLAY block.

7/1/09Harry Howard, CPST 410, Tulane University16 The program  Remember that the DISPLAY block is very fast, so pull a TIME WAIT block out of the Common palette and drop it after the DISPLAY block. Set it to 10 s.  Save, download, and run the program.  What happens?

7/1/09Harry Howard, CPST 410, Tulane University17 Wires and plugs [A] Input plug [B] Output plug [C] Number data wire (yellow) [D] Logic data wire (green) [E] Text data wire (orange) [F] Broken data wire (gray)

7/1/09Harry Howard, CPST 410, Tulane University18 Play time  Take a few minutes to play with the program.

NXC

7/1/09Harry Howard, CPST 410, Tulane University20 First look at BricxCC  Open BricxCC and move the Brick Command Center window to the left so that the Templates window is visible (see next slide).

7/1/09Harry Howard, CPST 410, Tulane University21 Now go to the File menu and start a new program.

7/1/09Harry Howard, CPST 410, Tulane University22 Reserved words identifiers and keywords, p. 135 __RETURN__CharLongsub __RETVAL__constMutexswitch __STRRETVAL__continueprioritytask __TMPBYTE__defaultrepeattrue __TMPWORD__doreturntypedef __TMPLONG__elsesafecallunsigned AbsfalseShortuntil AsmforSignvoid BoolgotoStartwhile breakifStop Byteinlinestring Caseintstruct

7/1/09Harry Howard, CPST 410, Tulane University23 Parsing errors  Usually because of missing or incorrect punctuation: } ; )  The parser expects these things in certain places.  If its expectations are not met, it gives an error message.  It also gets thrown off track for the upcoming code and thus generates lots of error messages only because of the first one.

Variables in NXC Hansen p. 135ff

7/1/09Harry Howard, CPST 410, Tulane University25 Variables  NXC has about 11 types of variables.  Today we will concentrate on the single numbers.  Since a number can take up a lot of storage space depending on how precisely it is specified, we want to be frugal with them.

7/1/09Harry Howard, CPST 410, Tulane University26 Simple numerical variables Keyword for typeDescription short, int16 bit; first bit indicates sign unsigned int16 bit; no bit for sign; rare long32 bit; first bit indicates sign unsigned long32 bit; no bit for sign; rare

7/1/09Harry Howard, CPST 410, Tulane University27 Variable declaration  Variables are declared using the keyword for the type, followed by a list of variable names which are separated by commas and terminated with a semicolon: int x; long y, z;  An equals sign can be followed by an initial value: int x=1, y=2, z;

7/1/09Harry Howard, CPST 410, Tulane University28 Constants  When a program contains a value that does not change during execution, it's a good idea to give it a name to make the program easier to understand.  This is done in NXC with a macro definition using the compiler directive #define, e.g.; #define METER2MM 1000 #define DEG2ROT 360  Compiler directives do not end in a semicolon.  During compilation, each macro is replaced by its value.

True or false? Feedback Kelly §8-9

7/1/09Harry Howard, CPST 410, Tulane University30 Robot does something (motor cortex) Environment changes (sensory cortex) feedforwardfeedback The place of feedback

7/1/09Harry Howard, CPST 410, Tulane University31 Robot does something (motor cortex) Environment changes (sensory cortex) feedforward feedback The complete system Robot decides (prefrontal cortex) ?

7/1/09Harry Howard, CPST 410, Tulane University32 All the sensors are in the Complete palette

7/1/09Harry Howard, CPST 410, Tulane University33 Sensor overview NXT SensorConditions TouchPressed, released, bumped Sound> n ( ) Light> n ( ) Ultrasonic< n ( ) Rotationn ( )

7/1/09Harry Howard, CPST 410, Tulane University34 Sensors and conditions  Once a sensor senses that its condition has been met, it produces a value of Yes (or True or 1).  Otherwise, it produces a value of No (or False or 0).  Such values of yes or no are known as logical values (though binary is just as accurate, and maybe more).

7/1/09Harry Howard, CPST 410, Tulane University35 Check the sensors  Plug a sensor into a sensor port (the ones along the bottom).  Create a program that displays the output of the sensor on the screen  Hint: See if any of the output plugs on the data hub help.

7/1/09Harry Howard, CPST 410, Tulane University36 DisplaySensor.rbt

Calibration Kelly §23

7/1/09Harry Howard, CPST 410, Tulane University38 Different enviornments  The Light and Sound sensors can respond differently in different environments  For example, the maximum in a brightly lit room will be different from the maximum in a dimly lit room  NXT-G provides a CALIBRATION block to account for this kind of variation

7/1/09Harry Howard, CPST 410, Tulane University39 The CALIBRATION block  Found in Complete > Advanced  Sets the minimum (0%) and maximum (100%) values detected by a sound or light sensor.

7/1/09Harry Howard, CPST 410, Tulane University40 Usage  Although a single one can set both the min and max, it is safer to check each extreme separately, i.e. use one CALIBRATION block for the min and another for the max.  How do you decide the min and max?  Design a program to calibrate the light sensor for our room.

Sensors in NXC

7/1/09Harry Howard, CPST 410, Tulane University42 Sensor options  You may recall that the sensor blocks had lots of options.  These have to be set by special statements in NXC.  There are three things to set  the sensor port: 1, 2, 3, 4  the sensor type: light, sound, touch, etc.  the sensor mode: how the data is collected

7/1/09Harry Howard, CPST 410, Tulane University43 Sensor port names  There are three naming schemes  S1, S2, S3, S4  IN_1, IN_2, IN_3, IN_4  SENSOR_1, SENSOR_2, SENSOR_3, SENSOR_4

7/1/09Harry Howard, CPST 410, Tulane University44 Set sensor type to a port  SetSensorLight(port)  SetSensorSound(port)  SetSensorTouch(port)

7/1/09Harry Howard, CPST 410, Tulane University45 Sensor type constants Sensor TypeMeaning SENSOR_TYPE_NONEno sensor configured SENSOR_TYPE_TOUCHNXT or RCX touch sensor SENSOR_TYPE_LIGHT_ACTIVENXT light sensor with light SENSOR_TYPE_LIGHT_INACTIVENXT light sensor without light SENSOR_TYPE_SOUND_DBNXT sound sensor with dB scaling SENSOR_TYPE_SOUND_DBANXT sound sensor with dBA scaling

7/1/09Harry Howard, CPST 410, Tulane University46 Sensor mode constants Sensor ModeMeaning SENSOR_MODE_RAWraw value from 0 to 1023 SENSOR_MODE_BOOLboolean value (0 or 1) SENSOR_MODE_EDGEcounts number of boolean transitions SENSOR_MODE_PULSEcounts number of boolean periods SENSOR_MODE_PERCENTvalue from 0 to 100 SENSOR_MODE_ROTATIONrotation (16 ticks per revolution)

7/1/09Harry Howard, CPST 410, Tulane University47 SetSensor function  It is convenient to set the type and the mode at the same time.  The SetSensor function makes this a little easier by providing a set of standard type/mode combinations (on the next slide) and a single function to call them:  SetSensor(port, constant configuration)  Example  SetSensor(S1, SENSOR_TOUCH);

7/1/09Harry Howard, CPST 410, Tulane University48 Sensor type-mode constants Sensor configuration constant TypeMode SENSOR_TOUCHSENSOR_TYPE_TOUCHSENSOR_MODE_BOOL SENSOR_PULSESENSOR_TYPE_TOUCHSENSOR_MODE_PULSE SENSOR_EDGESENSOR_TYPE_TOUCHSENSOR_MODE_EDGE SENSOR_LIGHTSENSOR_TYPE_LIGHTSENSOR_MODE_PERCENT SENSOR_ROTATIONSENSOR_TYPE_ROTATIONSENSOR_MODE_ROTATION

7/1/09Harry Howard, CPST 410, Tulane University49 Reading sensor values  Once these options have been set, the processed sensor reading can be read from its port using the function: Sensor(port)  Example x = Sensor(S1); // read sensor at port 1  The ultrasonic sensor has its own function: SensorUS(port) x = SensorUS(S1); // read ultrasonic sensor at port 1

7/1/09Harry Howard, CPST 410, Tulane University50 Next time  P1  This will just be a quiz on the blocks  Whatever we did not finish today  Random numbers  'Line Follower' - project done in class