Introduction to Robots and the Mind - Methods -

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

08/2012Tanya Mishra1 EASYC for VEX Cortex Llano Estacado RoboRaiders FRC Team 1817.
An Introduction to C Adam Gleitman – IAP 2014.
23-Apr-15 Abstract Data Types. 2 Data types I We type data--classify it into various categories-- such as int, boolean, String, Applet A data type represents.
Hand Crafting your own program By Eric Davis for CS103.
School of Computing Science CMT1000 Ed Currie © Middlesex University Lecture 4: 1 CMT1000: Introduction to Programming Ed Currie Lecture 5a: Input and.
Copyright 2008 by Pearson Education 1 Building Java Programs Chapter 2 Lecture 2-1: Expressions and Variables reading:
COMP 14: Primitive Data and Objects May 24, 2000 Nick Vallidis.
Java for Robots How to program an NXT robot with a Java Brain Bert G. Wachsmuth Seton Hall University.
By Nicholas Policelli An Introduction to Java. Basic Program Structure public class ClassName { public static void main(String[] args) { program statements.
PYTHON: PART 2 Catherine and Annie. VARIABLES  That last program was a little simple. You probably want something a little more challenging.  Let’s.
Loops: Handling Infinite Processes CS 21a: Introduction to Computing I First Semester,
5 BASIC CONCEPTS OF ANY PROGRAMMING LANGUAGE Let’s get started …
Elements of a Java Program Bina Ramamurthy SUNY at Buffalo.
An Introduction to Java – Part 1 Dylan Boltz. What is Java?  An object-oriented programming language  Developed and released by Sun in 1995  Designed.
Copyright 2008 by Pearson Education 1 Building Java Programs Chapter 2 Lecture 2-1: Expressions and Variables reading:
Programming, an introduction to Pascal
BEGINNING PROGRAMMING.  Literally – giving instructions to a computer so that it does what you want  Practically – using a programming language (such.
Java methods Methods break down large problems into smaller ones Your program may call the same method many times saves writing and maintaining same code.
Chapter 2 Input, Variables and Data Types. JAVA Input JAVA input is not straightforward and is different depending on the JAVA environment that you are.
Copyright 2010 by Pearson Education 1 Building Java Programs Chapter 2 Lecture 2-1: Expressions and Variables reading:
GameDevClub CODE CHEAT SHEET NOTE: ALL OF THE CODE IS CASE-SENSITIVE AND THE SYNTAX IS STRICT SO A LOT OF YOUR ERRORS WILL PROBABLY COME FROM TYPOS If.
Midterm Review Tami Meredith. Primitive Data Types byte, short, int, long Values without a decimal point,..., -1, 0, 1, 2,... float, double Values with.
TOPIC 8 MORE ON WHILE LOOPS 1 Notes adapted from Introduction to Computing and Programming with Java: A Multimedia Approach by M. Guzdial and B. Ericson,
1 Lecture # 2. * Introducing Programming with an Example * Identifiers, Variables, and Constants * Primitive Data Types * Byte, short, int, long, float,
Introduction to Robots and the Mind - Proportional Controller - Bert Wachsmuth & Michael Vigorito Seton Hall University.
Introduction to Robots and the Mind - Programming with Sensors - Bert Wachsmuth & Michael Vigorito Seton Hall University.
Lecture 3: More Java Basics Michael Hsu CSULA. Recall From Lecture Two  Write a basic program in Java  The process of writing, compiling, and running.
Introduction to Robots and the Mind - Programming Basics - Bert Wachsmuth & Michael Vigorito Seton Hall University.
Review by Mr. Maasz, Summary of Chapter 2: Starting Out with Java.
Introduction to Programming using Java Day 3 and 4 Java Language Basics Review The “For” loop Subroutines The “String” class.
Midterm preview.
Chapter 1.2 Introduction to C++ Programming
Chapter 1.2 Introduction to C++ Programming
CIS3931 – Intro to JAVA Lecture Note Set 2 17-May-05.
Chapter 1.2 Introduction to C++ Programming
Chapter 1.2 Introduction to C++ Programming
Elementary Programming
Building Java Programs
Yanal Alahmad Java Workshop Yanal Alahmad
Primitive Data, Variables, Loops (Maybe)
Introduction to Robots and the Mind - Path Integration -
Introduction to C++ October 2, 2017.
Chapter 2.
BIT115: Introduction to Programming
Building Java Programs Chapter 2
Introduction to C++ Programming
An Introduction to Java – Part I, language basics
Chapter 2 Edited by JJ Shepherd
Building Java Programs
Building Java Programs Chapter 2
Building Java Programs
Chapter 2 Programming Basics.
Building Java Programs
Building Java Programs
Building Java Programs
Building Java Programs
Building Java Programs
Building Java Programs
Building Java Programs
Primitive Types and Expressions
Building Java Programs
Building Java Programs Chapter 2
Building Java Programs
Just Enough Java 17-May-19.
Data Types and Maths Programming Guides.
Building Java Programs
CSS161: Fundamentals of Computing
Building Java Programs
Building Java Programs
Presentation transcript:

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

Last time Learned about fields and methods What a robot “has”: fields What a robot “does”: methods Working with “fixed” Components Sound.beep(); or Sound.playNote(freq, duration); or Button.ENTER.waitForPressAndRelease(); Working with (regulated) motors Define reference to a motor as a field via public static EV3LargeRegulatedMotor nameForMotor = new EV3LargeRegulatedMotor(MotorPort.A); Use motor methods via nameForMotor.methodName(opt input)

Methods A method defines a well-defined subtask that can be called upon to solve a portion of the bigger task. Every program (task) needs to be divided up into multiple methods (subtasks), each of which is simple and flexible and tested for correctness The methods are combined, usually in the main method, to solve the overall task Every method has a header that defines its name, input and output types body that defines what the method does comments that describe the method in plain English

Example: Problem: we don’t know exactly when a program starts. Solution: Create a method that indicates that everything is ready to go, but then waits for the user to press a button. // Method to beep and wait until user presses ENTER public static void wait() { System.out.println(“Press ENTER”); Sound.beep(); Button.ENTER.waitForPressAndRelease(); } public static void main(String[] args) wait(); // rest of the program starts here

Syntax to define a method There are two types of methods: those that don’t return anything and those that do: // method that does not return anything public static void methodName(optional input) { … } or // method that does return a specific value public static returnType methodName(optional input) { … return …

Java Types Methods can return a value of a specified type, and they can have an input list of variables of certain types. Java build-in types are: int (or short) defines an integer double (or float) defines a decimal char single character boolean either true or false String list of characters

Examples Method that triples its input value and writes result on LCD screen Method that triples its input value and returns the result Method that engages both motors for n full rotations at a specified speed Method that computes the area of a right triangle with a given base and height. Method that computes both the area and the circumference of a circle with radius r Method that drives a differential drive robot forward x cm Method that rotates a differential drive robot by x degrees

Methods for Differential Drive Want to define a method that drives robot x cm. Start with arbitrary conversion factor 7.3 (or anything else): public static void drive(int distance) { int rotDegrees = (int)(7.3*distance); leftMotor.rotate(rotDegrees, true); rightMotor.rotate(rotDegrees); } Call this method in the main method: drive(10); Adjust the conversion factor through trial and error until your robot really drives 10 cm

Model for Rotation in Place Need: length of axis L radius of wheels r Could compute angle t to rotate wheels to achieve a turn by angle T

Methods for Differential Drive Want to define a method that turns robot x degrees. Start with arbitrary conversion factor 5.4 (or anything else): public static void turn(double angle) { int rotDegrees = (int)(5.4*angle); leftMotor.rotate(rotDegrees, true); rightMotor.rotate(-rotDegrees); } Call this method in the main method: turn(180); Adjust the conversion factor through trial and error until your robot really turns 180 degrees

Second Challenge Our program to solve 2nd challenge has: Two fields of type ‘Motor’ Three methods: public static void drive(int distance) public static void turn(int angle) public static void main(String[] args) drive(50); turn(90);