Introduction to Robots and the Mind - Path Integration -

Slides:



Advertisements
Similar presentations
Static Methods Static methods are those methods that are not called on objects. In other words, they don’t have an implicit parameter. Random number generation.
Advertisements

Week 9: Methods 1.  We have written lots of code so far  It has all been inside of the main() method  What about a big program?  The main() method.
The Turtle Laboratory Sequence Myles McNally LMICSE Workshop November , 2004 University of Mississippi.
The Turtle Laboratory Sequence LMICSE Workshop August , 2006 Villanova University.
Copyright 2006 by Pearson Education 1 Building Java Programs Chapter 3: Parameters, Return, and Interactive Programs with Scanner.
The Turtle Laboratory Sequence LMICSE Workshop June , 2005 Alma College.
1 Algorithms and Problem Solving. 2 Outline  Problem Solving  Problem Solving Strategy  Algorithms  Sequential Statements  Examples.
 To be able to write larger programs ◦ By breaking them down into smaller parts and passing data between the parts.  To understand the concepts of Methods.
Lecture 7. Review Homework 1 (sample solution) Project 1 will be assigned next week –Draw a picture (whatever you want) in the world by using turtles.
SuperCorners. Problem The Corners sample robot has a simple strategy: first, move into a corner of the arena, and second sweep the gun back and forth.
Java for Robots How to program an NXT robot with a Java Brain Bert G. Wachsmuth Seton Hall University.
Week 4-5 Java Programming. Loops What is a loop? Loop is code that repeats itself a certain number of times There are two types of loops: For loop Used.
Chapter 6: Iteration Part 2. Create triangle pattern [] [][] [][][] [][][][] Loop through rows for (int i = 1; i
Methods and You. Up to this point, I have covered many different data types with you. Variables can be considered the nouns of an English sentence. If.
Karel J Robot An introduction to BlueJ and Object- Oriented Programming.
Lecture 2: Static Methods, if statements, homework uploader.
INTEL ULTIMATE ENGINEERING EXPERIENCE. INSTRUCTORS BRAD NICHOLS MICHAEL KATIC RYAN SCOTT Feel.
 The pool rack example could be implemented using a for loop.  It is also possible to write recursive methods that accomplish things that you might.
CSC 204 Programming I Loop I The while statement.
Copyright © Curt Hill Mathematics Functions An example of static methods.
Overview of Project 3 Slides are available at : Updated 1/28 Due Date for project has been extended to next Friday 2/6.
Introduction to Programming David Goldschmidt, Ph.D. Computer Science The College of Saint Rose Java Methods (a.k.a. Functions)
BEGINNING PROGRAMMING.  Literally – giving instructions to a computer so that it does what you want  Practically – using a programming language (such.
CS305j Introduction to Computing Classes 1 Topic 23 Classes – Part I "A 'class' is where we teach an 'object' to behave." -Rich Pattis Based on slides.
Truth and while Today 15 Minutes online time to finish the random/Swing programs. Truth tables: Ways to organize results of Boolean expressions. Note Taking:
The Math class Java provides certain math functions for us. The Math class contains methods and constants that can be very useful. The Math class is like.
The Math Class Methods Utilizing the Important Math Operations of Java!
CS 121 – Quiz Feb 17 th. Question 2 We want to count how many days there were such that the temperature is at least degrees lower than the.
Cumulative algorithms. 2 Adding many numbers How would you find the sum of all integers from ? // This may require a lot of typing int sum = 1 +
AP Computer Science A – Healdsburg High School 1 Unit 9 - Parameter Passing in Java.
CS0007: Introduction to Computer Programming The for Loop, Accumulator Variables, Seninel Values, and The Random Class.
CS305j Introduction to Computing Parameters and Methods 1 Topic 8 Parameters and Methods "We're flooding people with information. We need to feed it through.
Introduction to Robots and the Mind - Proportional Controller - Bert Wachsmuth & Michael Vigorito Seton Hall University.
Copyright 2011 by Pearson Education Building Java Programs Chapter 3 Lecture 3-2: Return values, Math, and double reading: 3.2,
Introduction to Robots and the Mind - Programming with Sensors - Bert Wachsmuth & Michael Vigorito Seton Hall University.
Introduction to Programming G50PRO University of Nottingham Unit 6 : Control Flow Statements 2 Paul Tennent
Lesson 7 Iteration Structures. Iteration is the third control structure we will explore. Iteration simply means to do something repeatedly. All iteration.
Midterm 2 Review Notes on the CS 5 midterm Take-home exam due by 5:00 pm Sunday evening (11/14) Hand in your solutions under the door of my office, Olin.
Introduction to Robots and the Mind - Sensors - Bert Wachsmuth & Michael Vigorito Seton Hall University.
Introduction to Robots and the Mind - Programming Basics - Bert Wachsmuth & Michael Vigorito Seton Hall University.
Chapter 7 Iteration. Chapter Goals To be able to program loops with the while, for, and do statements To avoid infinite loops and off-by-one errors To.
Lecture 6: While Loops and the Math Class
ECE Application Programming
COMP 14 Introduction to Programming
Department of Computer Science
10.2 Implementation and Execution of Recursive Code
Counted Loops.
Introduction to Robots and the Mind - Methods -
Building Java Programs
Building Java Programs
Computing Adjusted Quiz Total Score
An Introduction to Java – Part I, language basics
Building Java Programs
Truth tables: Ways to organize results of Boolean expressions.
Robotics and EV3 - Behavior-Based Robots -
CNC Milling/Lathe interface Introduction
Truth tables: Ways to organize results of Boolean expressions.
Repeating Behaviors.
Take out a piece of paper and PEN.
class PrintOnetoTen { public static void main(String args[]) {
METHODS, CLASSES, AND OBJECTS A FIRST LOOK
Building Java Programs
Scope of variables class scopeofvars {
Robotics Week 4 Functions and reusable code
Building Java Programs
Agenda Warmup Lesson 1.9 (random #s, Boolean variables, etc)
Building Java Programs
LOOPS The loop is the control structure we use to specify that a statement or group of statements is to be repeatedly executed. Java provides three kinds.
Random Numbers while loop
Presentation transcript:

Introduction to Robots and the Mind - Path Integration - Bert Wachsmuth & Michael Vigorito Seton Hall University

Robot with Sense of Location Goal: Robot should know its location, the location of “home”, and that of “food” found Superimpose a Cartesian Coordinate system with home at the origin and maintain “(x,y) location” and “heading” variables. Start at location = (0,0), heading = 0 degree and update both variables at every move

Base Program public class KnowThyPlace { // define constants: TURN_FACTOR, TURN_SPEED, TRAVEL_FACTOR, TRAVEL_SPEED // define 2 fields for left/right motors // define following methods public static void turn(double angle) public static void travel(double dist) public static void main(String args[]) }

Adding “brain cells” public class KnowThyPlace { // as before but add three fields public static double x = 0.0; public static double y = 0.0; public static double heading = 0.0; // define following methods public static void turn(double angle) public static void travel(double dist) public static void main(String args[]) }

Figuring new heading

Keeping Track while Turning public static void turn(double angle) { motorLeft.setSpeed(TURN_SPEED); motorRight.setSpeed(TURN_SPEED); double degrees = TURN_FACTOR * angle; motorRight.rotate((int)degrees, true); motorLeft.rotate(-(int)degrees); // updating heading of robot heading = (heading + angle) % 360; }

Figuring new (x,y) location

Keeping Track while Driving public static void travel(double dist) { motorLeft.setSpeed(TRAVEL_SPEED); motorRight.setSpeed(TRAVEL_SPEED); double degrees = TRAVEL_FACTOR * angle; motorRight.rotate((int)degrees); motorLeft.rotate((int)degrees); // Updating (x,y) location of robot x = x + dist*Math.cos(heading*Math.PI/180.0); y = y + dist*Math.sin(heading*Math.PI/180.0); }

Distance and Angle We need to compute the distance between two points (x,y) and (xNew,yNew) and the angle between them:

Distance and Angle Here is the code to compute distance and angle between points (x1,y1) and (x2,y2): public static double findDistance(double x1, double y1, double x2, double y2) { return Math.sqrt( (x2–x1)*(x2–x1) + (y2–y1)*(y2–y1) ); } public static double findAngle(double x1, double y1, return Math.atan2( (y2-y1), (x2-x1) ) * 180.0 / Math.PI; Note the use of Math.atan2, not the regular Math.atan

Reaping the Benefits We can now add a method “driveTo” to drive to a specific spot in our coordinate system: public static void driveTo(double xNew, double yNew) { double angle = findAngle(x, y, xNew, yNew); double dist = findDist(x, y, xNew, yNew); // find out which angle to turn based on current heading // and computed angle in which the new point is: int turnAngle = (int)(angle – heading) % 360; turn(turnAngle); travel(dist); }

Using the driveTo method We can use driveTo to drive to specific points in an imaginary coordinate system, while returning to our starting point simply by calling driveTo(0,0) For example, to drive in a square we’d say (after calibrating the parameters, see next slide): public static main(String[] args) { driveTo(100,0); driveTo(100,100); driveTo(0, 100); driveTo(0, 0); }

Calibration The calculations depend on your robot making exact turns distance does not have to be exact, but turns have to be as exact as possible Calibrate your robot before running it, especially if its environment has changed Replace any code in the main method by a call to “turn(360)” and execute Adjust TURN_FACTOR until the robot makes a perfect 360 degree turn Similarly adjust TRAVEL_FACTOR until a call to “travel(100)” results in a distance of 1 meter traveled

Random Movements Make sure you calibrated the constants (previous slide). Create a counting loop for 4 random movements, then return “home” public static main(String[] args) { int count = 0; while (count < 4) // Creating two random numbers between 20 and 80 double x = 60*Math.random() + 20; double y = 60*Math.random() + 20; // Driving to that random location driveTo(x,y); count = count + 1; } // Returning “home” to the origin driveTo(0, 0);