The Finch Robot and the While Loop - PowerPoint PPT Presentation

About This Presentation
Title:

The Finch Robot and the While Loop

Description:

THE FINCH ROBOT AND THE WHILE LOOP Pepper ... See how hardware and physical actions can be controlled with code Lab group practice Extra: ... – PowerPoint PPT presentation

Number of Views:183
Avg rating:3.0/5.0
Slides: 15
Provided by: krisl150
Learn more at: https://home.adelphi.edu
Category:
Tags: finch | hardware | loop | robot

less

Transcript and Presenter's Notes

Title: The Finch Robot and the While Loop


1
The Finch Robot and the While Loop
  • Pepper

2
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
  • Extra One robot available for creating game
  • Will need to learn methods
  • May need to debug issues
  • Will it help you learn for the final?

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

4
Installing
  • Download Java package from http//www.finchrobot.c
    om/Creating,20Compiling,20and20Running20Progra
    ms20for20Finch/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)

5
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)

6
Controlling commands
  • Set Finch Beak Color
  • 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

7
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)

8
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)

9
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)

10
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

11
Do While
  • Spin at least once, and then keep spinning until
    the lights turn off
  • do
  • myFinch.setWheelVelocities(255,-255,100
    0)
  • while (myFinch.isRightLightSensor(10)
    true)
  • // run with lights off see one spin first

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

13
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

14
Your Turn
  • Probably not needed, but see finch.jar in
    preferences
  • Download java finch package
  • http//www.finchrobot.com/Creating,20Compiling,2
    0and20Running20Programs20for20Finch/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 right and test.
  • Then make it do something until it hits a wall.
Write a Comment
User Comments (0)
About PowerShow.com