The Finch Robot and the While Loop

Slides:



Advertisements
Similar presentations
AP Computer Science Anthony Keen. Computer 101 What happens when you turn a computer on? –BIOS tries to start a system loader –A system loader tries to.
Advertisements

1chung 5 th Annual Robofest 2004 Informational Meeting Mar. 20, 2004 Chan Jin Chung Ali Khazaal Jason Lo Computer Science Lawrence Technological University.
Picture It Very Basic Game Picture Pepper. Original Game import java.util.Scanner; public class Game { public static void main() { Scanner scan=new Scanner(System.in);
ENGG1100 Ch6: Introduction To Engineering Design (Digital Logic) Part 2 of digital logic KH WONG ENGG1100. Ch6-Digital Logic (part2) v3h1.
Lab7: Introduction to Arduino
Begin Java Pepper. Objectives What is a program? Learn the basics of your programming tool: BlueJ Write a first Java program and see it run Make some.
Automation and Robotics
Introduction to Object-Oriented Programming CS 21a: Introduction to Computing I First Semester,
From the NXT top menu Connect desired hardware as indicated Enter a command in the box indicated from the menu provided Repeat for all 5 boxes.
Introduction to Sensors
Java for Robots How to program an NXT robot with a Java Brain Bert G. Wachsmuth Seton Hall University.
ENGG1100 Introduction to Engineering Design Digital Logic (Part 2) Prof. Kin Hong Wong Department of Computer Science and Engineering.
T HE F INCH R OBOT AND THE W HILE L OOP Pepper. T HE R OBOT Developed by Carnegie Mellon students to teach CS Supports many compilers, including Java.
Introduction to Object-Oriented Programming
Copyright © Curt Hill Turtles The beginning of media computation.
How to link the robot and the computer (Bluetooth) How to turn on and off How to connect the adaptor Fluke card connection Sec Getting Started How.
Barclays Robot Challenge Learn how to Program Robots.
BEGINNING PROGRAMMING.  Literally – giving instructions to a computer so that it does what you want  Practically – using a programming language (such.
1 Class 1 Lecture Topic Concepts, Definitions and Examples.
1 Project 7: Looping. Project 7 For this project you will produce two Java programs. The requirements for each program will be described separately on.
Using the BlueJ IDE with Mindstorms LMICSE Workshop June , 2005 Alma College.
Automation and Robotics.  First you select the platform type so that you can use Natural Language PLTW.
Casne.ncl.ac.uk Taking care of the CrumbleBot Please do NOT stress the robot's motors 1.Do NOT push the robot 2.Do NOT hold the.
ROBOTC for CORTEX Teacher Training © 2011 Project Lead The Way, Inc. Automation and Robotics VEX.
Presentation Outline I. Background Information II. Design Project
Introduction to Programming in RobotC
Exploring Computer Science Lesson 6-5
CSC111 Quick Revision.
What you asked me to teach…
Follow The Guidelines.
Eclipse Navigation & Usage.
INC 161 , CPE 100 Computer Programming
IT Basic Wednesday 14 April 2010
Finch Robot Class L4 How do I… ? LED color (Range 0 to 100)
Automation and Robotics
Basics for Robotics Programming
Introduction to javadoc
Building Java Programs
Building Java Programs
Java I.
Automation and Robotics
Sensors and Logic Switches
An Introduction to Java – Part I, language basics
Exploring Computer Science Lesson 6-5
Building Java Programs
Follow The Guidelines Light Sensor
Alice Variables Pepper.
Introductory Presentation
Storing Values as Variables
While Loops and If-Else Structures
Introductory Presentation
Building Java Programs
While Loops and If-Else Structures
While Loops and If-Else Structures
While Loops and If-Else Structures
if-else Structures Principles of Engineering
Automation with RobotC
Introduction to javadoc
Robotics Week 4 Functions and reusable code
While Loops and If-Else Structures
Building Java Programs
Automation with RobotC
CS334: Logisim program lab6
Random Numbers while loop
While Loops and If-Else Structures
Lego MINDSTORMS EV3.
While Loops And If-Else Structures
Getting started with LEGO EV3 Mindstorms software
LEGO Mindstorms Robot and Java
The beginning of media computation Followed by a demo
Presentation transcript:

The Finch Robot and the While Loop Pepper

The Robot Developed by Carnegie Mellon students to teach CS Supports many compilers, including Java Web site: http://www.finchrobot.com/ Why – Illustrate while and do /while loops with physical example Why 2: See how hardware and physical actions can be controlled with code Lab group practice

Hardware Input Sensors Output Power Obstacles Light Accelerometer (how fast is it going) Temperature Output Wheels turn LED lights Speaker Power Long USB Cord

Installing Download Java package from http://www.finchrobot.com/Creating,%20Compili ng,%20and%20Running%20Programs%20for%20 Finch/bluej Place it in the folder you want to use Unzip it Open sample project in sourceFiles bluej.pkg Create your own package inside sample project (or add jar file finch.jar to bluej via preferences Or add finch.jar to the +libs folder inside SourceFiles)

Make a Finch Controller Bring in the knowledge: import edu.cmu.ri.createlab.terk.robot.finch.Finch; Create a finch object that knows finch commands: Finch myFinch = new Finch(); Always end with quit and exit: myFinch.quit(); System.exit(0);

Controlling commands Set Finch Beak Color: Make Finch Speak: myFinch.setLED(red,green,blue); // 0 to 255 Make Finch Speak: myFinch.saySomething("The Finch will say this."); Make Finch Move: myFinch.setWheelVelocities(left,right,time) // -255 to 255 & time is in milliseconds // negative number rolls backwards // hold the cord or it may have difficulty

Simple program – package Pepper; import edu.cmu.ri.createlab.terk.robot.finch.Finch; public class FinchSimple { public static void main(final String[] args) { // Instantiating the Finch object Finch myFinch = new Finch(); myFinch.setWheelVelocities(255,255,1000); myFinch.saySomething(“I am now All Done"); // Always end your program myFinch.quit(); System.exit(0); }

Get Finch Sense Information Obstacles: All true/false isObstacle() isObstacleLeftSide() isObstacleRightSide() Light: All true/false, but using light level threshold. Returns true if less than the threshold isRightLightSensor(10) isLeftLightSensor(10) In dark, it will be true up to about 4 In light, it will be true up to about 40 Ex: if (myFinch.isRightLightSensor(10) == true) { System.out.println(“It is light out”);} else {System.out.println(“It is dark out”);}

Make it do an action while a condition is true Keep moving forward until it senses an obstacle while ( myFinch.isObstacle() == false ){ myFinch.setWheelVelocities(255,255,200); } // then back up myFinch.setWheelVelocities(-255,-255,1000);

Another - Make it do an action while a condition is true Spin until the lights turn off while (myFinch.isRightLightSensor(10) == true){ myFinch.setWheelVelocities(255,-255,1000); } // when the lights are out, this will be false // when the lights are on, this will be true // could say spin while lights are on // WILL NOT SPIN AT ALL IF LIGHTS OFF

Do While Spin at least once, and then keep spinning until the lights turn off do { myFinch.setWheelVelocities(255,-255,1000); } while (myFinch.isRightLightSensor(10) == true); // run with lights off – see one spin first

Get orientation info Orientation: All true/false isFinchLevel() isFinchUpsideDown() isBeakDown() isBeakUp() isLeftWingDown() isRightWingDown()

Your Takeaway Difference between while and do while Creating an object of a class gives your program powerful tools A sense of how hardware can be controlled by code Perhaps a desire to code your game using this little robot

Your Turn Probably not needed, but see finch.jar in preferences Download java finch package http://www.finchrobot.com/Creating,%20Compiling,%20and%20Running%20Programs%20for%20Finch/bluej New class Import above class: import edu.cmu.ri.createlab.terk.robot.finch.Finch; Inside main method, create a finch object Finch myFinch = new Finch(); Close your finch at the end of main myFinch.quit(); System.exit(0); Add code to make it move forward, backward, right and left, all for one second each.