Java for Robots How to program an NXT robot with a Java Brain Bert G. Wachsmuth Seton Hall University.

Slides:



Advertisements
Similar presentations
08/2012Tanya Mishra1 EASYC for VEX Cortex Llano Estacado RoboRaiders FRC Team 1817.
Advertisements

Core Java Lecture 4-5. What We Will Cover Today What Are Methods Scope and Life Time of Variables Command Line Arguments Use of static keyword in Java.
Team 5220 Roboknights. Outline  Getting Started  Hardware Setup/Wiring  Software Setup/Pragmas  Programming with RobotC  Grammar/Syntax  Basic Statements.
Repetition Statements repeat block of code until a condition is satisfied also called loops Java supports 3 kinds of loops: while statement – repeats a.
Java Intro. A First Java Program //The Hello, World! program in Java public class Hello { public static void main(String[] args) { System.out.println("Hello,
CS 106 Introduction to Computer Science I 10 / 04 / 2006 Instructor: Michael Eckmann.
Java An introduction. Example 1 public class Example1 { public static void main (String [] args) { System.out.println (“This is the first example”); int.
Fundamental Programming Structures in Java: Comments, Data Types, Variables, Assignments, Operators.
Understanding class definitions Looking inside classes.
Programming Part 1 Armond R. Smith Zhenying Wu. Overview of this Class ● Transition from FTC -> FRC ● Using Your Resources ● Java Keywords o Data Types.
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.
Comp 248 Introduction to Programming Chapter 4 - Defining Classes Part A Dr. Aiman Hanna Department of Computer Science & Software Engineering Concordia.
Introduction to Programming Prof. Rommel Anthony Palomino Department of Computer Science and Information Technology Spring 2011.
Recitation 2 Main Method, API & Packages, Java Basics.
By Nicholas Policelli An Introduction to Java. Basic Program Structure public class ClassName { public static void main(String[] args) { program statements.
Introduction to Programming David Goldschmidt, Ph.D. Computer Science The College of Saint Rose Java Fundamentals (Comments, Variables, etc.)
CSC204 – Programming I Lecture 4 August 28, 2002.
TUTORIAL 10: PROGRAMMING WITH JAVASCRIPT Session 2: What is JavaScript?
CIS 260: App Dev I. 2 Programs and Programming n Program  A sequence of steps designed to accomplish a task n Program design  A detailed _____ for implementing.
/* Documentations */ Pre process / Linking statements Global declarations; main( ) { Local Declarations; Program statements / Executable statements; }
CHAPTER 3 GC Java Fundamentals. 2 BASICS OF JAVA ENVIRONMENT  The environment  The language  Java applications programming Interface API  Various.
 JAVA Compilation and Interpretation  JAVA Platform Independence  Building First JAVA Program  Escapes Sequences  Display text with printf  Data.
Announcements  If you need more review of Java…  I have lots of good resources – talk to me  Use “Additional Help” link on webpage  Weekly assignments.
Variables and Functions. Open your Encoder program Let’s begin by opening the “Labyrinth Auto Straight” code. Save this file as Labyrinth with variables.
CIS 260: App Dev I. 2 Programs and Programming n Program  A sequence of steps designed to accomplish a task n Program design  A detailed _____ for implementing.
Using Data Within a Program Chapter 2.  Classes  Methods  Statements  Modifiers  Identifiers.
A First Simple Program /* This is a simple Java program. Call this file "Example.java".*/ class Example { // Your program begins with a call to main().
Session Three Review & Conditional Control Flow. Java File Hierarchy Projects Packages Classes Methods.
An Introduction to Java – Part 1 Dylan Boltz. What is Java?  An object-oriented programming language  Developed and released by Sun in 1995  Designed.
C++ Basics C++ is a high-level, general purpose, object-oriented programming language.
Introduction to Java Lecture Notes 3. Variables l A variable is a name for a location in memory used to hold a value. In Java data declaration is identical.
Introduction to Java Java Translation Program Structure
BEGINNING PROGRAMMING.  Literally – giving instructions to a computer so that it does what you want  Practically – using a programming language (such.
Anatomy of a Java Program. AnotherQuote.java 1 /** A basic java program 2 * 3 Nancy Harris, James Madison University 4 V1 6/2010.
Chapter 5 Classes and Methods II Lecture Slides to Accompany An Introduction to Computer Science Using Java (2nd Edition) by S.N. Kamin, D. Mickunas, E.
1 Basic Java Constructs and Data Types – Nuts and Bolts Looking into Specific Differences and Enhancements in Java compared to C.
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.
Developed at Sun Microsystems in 1991 James Gosling, initially named “OAK” Formally announced java in 1995 Object oriented and cant write procedural.
Spring 2009 Programming Fundamentals I Java Programming XuanTung Hoang Lecture No. 8.
CSC 110 – Intro to Computing - Programming
1 Lecture # 2. * Introducing Programming with an Example * Identifiers, Variables, and Constants * Primitive Data Types * Byte, short, int, long, float,
Vex Robotics program three: using motors and sensors together.
Introduction to Robots and the Mind - Programming with Sensors - Bert Wachsmuth & Michael Vigorito Seton Hall University.
Problem of the Day  Why are manhole covers round?
UFCFY5-30-1Multimedia Studio Coding for Interactive Media Fundamental Concepts.
Eastside Robotics Alliance / Newport Robotics Group 1 T/Th, 6:30 – 8:30 PM Big Picture School Day 3 · 10/9/2014.
Introduction to Robots and the Mind - Programming Basics - Bert Wachsmuth & Michael Vigorito Seton Hall University.
Session Three Review & Conditional Control Flow. Java File Hierarchy Projects Packages Classes Methods.
MINDSTORMS NXT with JAVA
Chapter 2 Elementary Programming
Introduction to Robots and the Mind - Path Integration -
IT Basic Wednesday 14 April 2010
Lecture Note Set 1 Thursday 12-May-05
CompSci 230 Software Construction
Intro to Java.
Introduction to Robots and the Mind - Methods -
CS/ENGRD 2110 Spring 2017 Lecture 5: Local vars; Inside-out rule; constructors
LRobot Game.
An Introduction to Java – Part I, language basics
Chap 1 Chap 2 Chap 3 Chap 5 Surprise Me
Recap Week 2 and 3.
elementary programming
Fundamental OOP Programming Structures in Java: Comments, Data Types, Variables, Assignments, Operators.
In this class, we will cover:
Classes, Objects and Methods
Names of variables, functions, classes
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.
Methods/Functions.
Introduction to java Part I By Shenglan Zhang.
Presentation transcript:

Java for Robots How to program an NXT robot with a Java Brain Bert G. Wachsmuth Seton Hall University

The Setup Differential drive robot with ultrasound distance sensor mounted in front Java VM uploaded to NXT Connection NXT PC via USB or Bluetooth Eclipse setup for Java programming Eclipse configured for LeJOS

Java Program A Java program is called a “class” Java is case-sensitive Statements are grouped with { … } or end in a semicolon ; Every Java program for the NXT has the same blueprint: import lejos.nxt.*; public class Test { public static void main(String args[]) { }

Java Basics Java programs contain the basic frame work and “state” variables to store global info and data (aka fields) functions to define particular subtasks (aka methods) Comments to explain code in plain English Single-line comments start with // Multi-line comments are enclosed in /* … */ Program execution starts at the “main” method and proceeds linearly unless redirected.

import lejos.nxt.*; public class Test { // global variables go here: static int heading = 0.0; // function to define subtask: static void turn(int degrees) { // subtask code goes here } public static void main(String args[]) { // this is where the program starts // code to call the ‘turn’ function goes here }

Defining Variables All variables must have a name, a type, and a value compatible with the type. All variables must be declared before use All variables have a range where they are valid: State variables are valid everywhere, e.g.: static int stateVariable = -9; Local variables are valid in the block they are defined in Variables can have types int, float (= 5.7f), double (= 5.7), boolean (= true or false), char (= ‘b’), or String (= “text”) There is a special type called “void” and a special value named “null”

Defining Functions Functions have header and a body Header defines name, input variables (and types), and return type (often void) Body defines what the function actually does public static void turn(int degrees) { // code here } Functions must be called with values matching the input variables as defined in the function header

NXT Programs To write Java code for the NXT, your first statement must be: import lejos.nxt.*; Then you can use special commands relevant to your NXT. All possible commands are documented in the LeJOS API, which must be available as you program. See: Robotics Pages -> Lectures -> link: LeJOS API or C:\JavaNXT\lejos_nxj\docs\api\index.html Click on “lejos.nxt” in top-left frame, then pick class in bottom left, to read details in main info frame.

Sample Programs Make some noise Show some text Move forward for 1 second Rotate for 1 second Move forward for one 360-degree wheel rotation Move forward for x degrees wheel rotation Move forward for x cm Rotate for x degrees