GET130 Intro to Engineering Technology Fall 2013

Similar documents
UNIT- 3 Introduction to C++

The Arithmetic Operators. Unary Operators. Relational Operators. Examples of use of ++ and

The Arithmetic Operators

Operators. Java operators are classified into three categories:

Language Basics. /* The NUMBER GAME - User tries to guess a number between 1 and 10 */ /* Generate a random number between 1 and 10 */

Sir Muhammad Naveed. Arslan Ahmed Shaad ( ) Muhammad Bilal ( )

SECTION II: LANGUAGE BASICS

Basic operators, Arithmetic, Relational, Bitwise, Logical, Assignment, Conditional operators. JAVA Standard Edition

GO - OPERATORS. This tutorial will explain the arithmetic, relational, logical, bitwise, assignment and other operators one by one.

BASIC ELEMENTS OF A COMPUTER PROGRAM

Macro Programming Reference Guide. Copyright 2005 Scott Martinez

Introduction to Visual Basic and Visual C++ Arithmetic Expression. Arithmetic Expression. Using Arithmetic Expression. Lesson 4.

Basics of Java Programming

CS313D: ADVANCED PROGRAMMING LANGUAGE

Statements and Operators

Chapter 3: Operators, Expressions and Type Conversion

Photogram. Programmable Photoshop Language Language Reference Manual. ( ), Group Leader. (

Le L c e t c ur u e e 2 To T p o i p c i s c t o o b e b e co c v o e v r e ed e Variables Operators

Ordinary Differential Equation Solver Language (ODESL) Reference Manual

06/11/2014. Subjects. CS Applied Robotics Lab Gerardo Carmona :: makeroboticsprojects.com June / ) Beginning with Python

CS2900 Introductory Programming with Python and C++ Kevin Squire LtCol Joel Young Fall 2007

Fundamental of Programming (C)

JScript Reference. Contents

Quick Reference Guide

Information Science 1

CGS 3066: Spring 2015 JavaScript Reference

CHIL CSS HTML Integrated Language

Unit-II Programming and Problem Solving (BE1/4 CSE-2)

Objectives. Introduce the core C# language features class Main types variables basic input and output operators arrays control constructs comments

Program Fundamentals

Expressions and Data Types CSC 121 Spring 2015 Howard Rosenthal

Lexical Considerations

Will introduce various operators supported by C language Identify supported operations Present some of terms characterizing operators

Chapter 4: Basic C Operators

C++ Programming: From Problem Analysis to Program Design, Third Edition

The Warhol Language Reference Manual

Petros: A Multi-purpose Text File Manipulation Language

Starting with a great calculator... Variables. Comments. Topic 5: Introduction to Programming in Matlab CSSE, UWA

BCA-105 C Language What is C? History of C

COMS 469: Interactive Media II

Mirage. Language Reference Manual. Image drawn using Mirage 1.1. Columbia University COMS W4115 Programming Languages and Translators Fall 2006

BoredGames Language Reference Manual A Language for Board Games. Brandon Kessler (bpk2107) and Kristen Wise (kew2132)

Chapter 2. Designing a Program. Input, Processing, and Output Fall 2016, CSUS. Chapter 2.1

JAVA OPERATORS GENERAL

Chapter 4: Control Structures I (Selection)

OBJECT ORIENTED SIMULATION LANGUAGE. OOSimL Reference Manual - Part 1

Unit 6 - Software Design and Development LESSON 3 KEY FEATURES

Language Reference Manual

In Delphi script, when values are assigned to variables, the colon-equal operator is used; :=

Objectives. Chapter 2: Basic Elements of C++ Introduction. Objectives (cont d.) A C++ Program (cont d.) A C++ Program

Chapter 2: Basic Elements of C++

Chapter 2. C++ Basics. Copyright 2014 Pearson Addison-Wesley. All rights reserved.

DEPARTMENT OF MATHS, MJ COLLEGE

Chapter 2: Basic Elements of C++ Objectives. Objectives (cont d.) A C++ Program. Introduction

Computer Programming, I. Laboratory Manual. Experiment #2. Elementary Programming

egrapher Language Reference Manual

Review: Exam 1. Your First C++ Program. Declaration Statements. Tells the compiler. Examples of declaration statements

GNU ccscript Scripting Guide IV

CSc 10200! Introduction to Computing. Lecture 2-3 Edgardo Molina Fall 2013 City College of New York

19 Much that I bound, I could not free; Much that I freed returned to me. Lee Wilson Dodd

BASIC COMPUTATION. public static void main(string [] args) Fundamentals of Computer Science I

Unit 6 - Software Design and Development LESSON 3 KEY FEATURES

Intro to Programming. Unit 7. What is Programming? What is Programming? Intro to Programming

Chapter 2: Using Data

Java provides a rich set of operators to manipulate variables. We can divide all the Java operators into the following groups:

GeoCode Language Reference Manual

LESSON 1. A C program is constructed as a sequence of characters. Among the characters that can be used in a program are:

Introduction. Following are the types of operators: Unary requires a single operand Binary requires two operands Ternary requires three operands

Lexical Considerations

Assoc. Prof. Dr. Marenglen Biba. (C) 2010 Pearson Education, Inc. All rights reserved.

Full file at

>>> * *(25**0.16) *10*(25**0.16)

Fundamentals of Programming

Slide 1 CS 170 Java Programming 1 Expressions Duration: 00:00:41 Advance mode: Auto

Expressions and Data Types CSC 121 Fall 2015 Howard Rosenthal

Overview: Programming Concepts. Programming Concepts. Names, Values, And Variables

Overview: Programming Concepts. Programming Concepts. Chapter 18: Get With the Program: Fundamental Concepts Expressed in JavaScript

Decisions, Decisions. Testing, testing C H A P T E R 7

Chapter Overview. C++ Basics. Variables and Assignments. Variables and Assignments. Keywords. Identifiers. 2.1 Variables and Assignments

Object-Oriented Programming

age = 23 age = age + 1 data types Integers Floating-point numbers Strings Booleans loosely typed age = In my 20s

\n is used in a string to indicate the newline character. An expression produces data. The simplest expression

1 Lexical Considerations

Full file at

Java Primer 1: Types, Classes and Operators

WEEK 4 OPERATORS, EXPRESSIONS AND STATEMENTS

Define a method vs. calling a method. Chapter Goals. Contents 1/21/13

C++ PROGRAMMING. For Industrial And Electrical Engineering Instructor: Ruba A. Salamh

Chapter 2. C++ Basics

Course Outline Introduction to C-Programming

SPARK-PL: Introduction

Java+- Language Reference Manual

I Internal Examination Sept Class: - BCA I Subject: - Principles of Programming Lang. (BCA 104) MM: 40 Set: A Time: 1 ½ Hrs.

CSC Web Programming. Introduction to JavaScript

In this chapter you ll learn:

Variables and Operators 2/20/01 Lecture #

Chapter 2 Using Data. Instructor s Manual Table of Contents. At a Glance. Overview. Objectives. Teaching Tips. Quick Quizzes. Class Discussion Topics

do fifty two: Language Reference Manual

Fundamentals. Fundamentals. Fundamentals. We build up instructions from three types of materials

VBScript: Math Functions

Transcription:

GET130 Intro to Engineering Technology Fall 2013

2 Programming is FUN! in addition to being a software package user, engineers and ETs can often benefit from being able to program computers for particular tasks solving special / newly discovered problems simplify your job function / responsibilities promotions! to do so, we need to learn a programming language rules, reserved words, syntax MANY computer programming languages / environments exist general purpose / special purpose mathematical/scientific, database/e-commerce, process control, artificial intelligence BASIC, C, C++, Java, COBOL, Matlab, LabVIEW, PLCs

3 BASIC Beginner s All-purpose Symbolic Instruction Code very easy to learn & use carefree formatting, data typing, syntax created in 1964 at Dartmouth College a family of general-purpose, high-level programming languages over 300 dialects (http://en.wikipedia.org/wiki/list_of_basic_dialects) has evolved through many incarnations over the years: Tiny-BASIC, Apple BASIC, Micro-Soft BASIC, IBM QuickBASIC, Microsoft Visual Basic, VB.NET and now: Parallax PBASIC, RobotBASIC

LANGUAGE SUMMARY 4

5 BASIC Programs BASIC is a line-oriented language Program = series of statements Statement Statement Statement statements may contain various language elements

6 Language Elements numbers variables operators expressions constants strings functions covered on the following slides

7 Numbers numeric values for computation, etc four types in RobotBASIC: : whole numbers between -2,147,483,648 +2,147,483,647 (32 bit representation) include a decimal point ±2.23E-308 ±1.79E+308 (32 bit) integers: start with 0% ex: n=0%110101 // same as n=53 (base 16) integers: start with 0x ex: n=0x1f // same as n=31 number of unique binary patterns with n bits = 2 n

8 Variables are programmer-defined names of storage locations goals = 2 variable naming rules // goals is the variable name must start with a letter, can then have any combination of letters & numbers; are case sensitive cannot be same as a command, function name, constant name or label RobotBASIC allows variables up to 255 characters RobotBASIC variables are typeless and do not require declaration before use

9 Operators quite similar to calculator operators including precedence rules ( ) overrides other precedence rules - unary negation ^ exponentiation *, / multiply, divide # modulus (remainder) % numeric percentage +, - add, subtract RobotBASIC operator summary (in precedence order) shown to right note: some operators are RobotBASIC-specific see Helpfile for examples $ substring test <, <=, >=, > less, less or equal, greater or equal, greater =, == equality <>, ><,!= inequality &&,, @@,! logical AND, OR, XOR, NOT &,, @, ~ bit-wise AND, OR, XOR, NOT >>, << bit shift left, right brotl, brotr bit rotate left, right ++, -- increment once, decrement once +=, -=, *=, /= add / sub / multiply / divide assign

10 Expressions a formula comprised of numbers, variables, strings, function calls, operators, and other expressions that yields a result used in variable assignments as well as parameters to commands and function calls Input "Radius: ", radius circumference = 2*pi()*radius print "Circumference = ", circumference print "Area = ", pi() * radius^2 function call operators numeric constant variable reference notice precedence rules in that last statement

11 Constants RobotBASIC provides many predefined names for certain numeric values always more meaningful compared to using number Circle 10,10,30,30,Red instead of: Circle 10,10,30,30,4 also useful in measure conversions: print Convert(212,cc_DFtoDC) cc = conversion constant

12 Strings textual content, arrays of characters delimited with quotation marks can apply certain operators to strings + performs string concatenation $ performs substring testing msg = "alive!" Print "Hello World," if "live" $ msg then Print "I m " + msg + "!"

13 Functions use to call a built-in or programmer-defined subprogram unit that returns a result can be used in expressions like pi() in previous example format: FunctionName(parameter1,parameter2 ) parameters separated by commas, may be optional note use of parentheses; Command statements do not use them Print "log(1000) = ", log(1000)

14 RobotBASIC Functions there are MANY functions built in to RobotBASIC categories: trig, logarithmic, exponential, coordinate, financial string manipulation scaling, weight & measure, number<->string & I/O,, chrono/calendar, system information refer to Helpfile for details

15 Statement Types Assignment: assign a value to a variable Command: built-in features that perform various tasks Flow Control: control the sequence of program execution Comment: provides documentation not actually statements Label: provides a name for a program location

16 Comments Line comments from // or to end of line // this is a line comment ' so is this count = 0 'initialize count to 0 Block comments everything between /* and */ /************************* this is an example of a block comment **************************/

17 Assignment Statements assigns value to a variable or array element value can be a constant or result of an expression formats: Var = expression Var[ ] = expression [ ] denotes index to an array variable radius = 3.5 diameter = 2*radius Speed[5] = 12

18 Command Statements perform built-in tasks input, output, drawing, robot actions, etc. format: CommandName parameter1,parameter2 commands are not case sensitive parameters separated by commas, may be optional Circle 20,20,40,40,red Print "Circle is drawn" End radius=10, center=30,30

19 Labels is a marker (think bookmark ) for a particular location in the program use by flow control statements to transfer execution to other than the next line includes a colon : where defined RobotBASIC: can be numeric or alphanumeric style Input "How old are you? ",age if age<0 then goto Alien Print "you must be human" end Alien: print "you must be alien" end

20 Flow Control Statements control flow of program execution unconditional conditional tests & program branching / / / iteration / repetition / / / / invoke subroutines / subprograms /

21 Conditional: IF evaluates a numeric expression and conditionally executes statement(s) based on result 2 formats : IF expressionn THEN statement IF expressionn statement {ELSEIF expressionn} statement {ELSE} statement ENDIF a=5 If (a-3)>0 Then Print "ok" 'check coffee temperature t = tempsensor() If t>190 Print "too high" ElseIf t<140 Print "too low" Else Print "ok" EndIf { } indicates optional content

22 Iteration: FOR used when number of loops needed is already known format: FOR var=expr1n TO expr2n statement NEXT may include optional "STEP" clause expression2 is generally > expression1; however, can also go in decreasing direction For i=1 To 5 Print "i=",i Next For i=5 To 20 Step 5 Print i Next For i=100 To 0 Step -1 Print i," bottles of beer" Next 'actually, this STEP is optional

23 Iteration: REPEAT used to repeat a loop until a condition is met format: REPEAT statement UNTIL expressionn statement(s) execute at least once Print "guessing game" n=random(100) Repeat Input "guess?",g If g<n print "too low" ElseIf g>n print "too high" Else print "that's it!" EndIf Until g=n

24 Iteration: WHILE used to repeat a loop as long as a condition is true format: WHILE expressionn statement WEND statement(s) may execute zero times! 'advance robot carefully 'get initial distance d=sensor_distance() While d > 5 rforward 5 'get new reading d=sensor_distance() Wend

25 Iteration: Alternative Loop Control used to handle special circumstances BREAK: abandons enclosing loop and continues with statement following loop CONTINUE: forces next iteration of enclosing loop

26 Subroutines: Gosub-Return used to organize a code sequence into a module, typically reusable formats: GOSUB label GOSUB expressionn statement code at label is executed until a RETURN is reached Input "enter N:",n Gosub Summation Print "summation=",total End Summation: total=0 For i=1 to n total = total + i Next Return

27 Subroutines: Call-Return a more advanced subroutine mechanism that supports parameters and local variables parameters are passed by value or by reference format: CALL label{(parameter list)} code at label is executed until a RETURN is reached Input "enter N:",n Call Summation(n,result) Print "summation=",result End Sub Summation(x,&total) total=0 For i=1 to x total = total + i Next Return

ROBOT SIMULATOR 28

29 Robot Simulator RobotBASIC includes a neat simulated robot environment with a collection of associated commands and functions some features: obstacle detection and abort robot sensors to detect & avoid obstacles full color support robot "tail" that can draw (if "down") invisible colors are not detected as obstacles simulated robot battery and charge state heading and position tracking via simulated compass & "GPS" simulated "slip" factor for motions

30 Robot Simulator Commands Summary creates & locates robot sets colors that will not be considered obstacles pixels defines floor color (default is WHITE) moves forward/backward some number of rotates robot CW (+) or CCW (-) sets robot's heading (0-359 degrees) sets a robot "slowdown" factor sets robot's pen UP or DOWN sets a motor slip factor

31 Heading Details and are based on directional compass measure as opposed to mathematical angle measures 0º 90º 135º 270º 90º 180º 0º 135º 180º 270º

32 Robot Simulator Functions Summary distance ahead to any obstacle distance to obstacle of particular color obstacle detection using bumper switches obstacle detection using infrared sensors get first color seen directly ahead reads a down-facing sensor looks down for a particular color gets robot's current compass heading gets robot's current X screen position gets robot's current Y screen position

33 rbumper() details the robot has 4 bump sensors (switches) front, rear, left, right each switch has an assigned bit position in the return value (bottom 4 bits): bit: 3 2 1 0 left front right rear each bit is 1 if bump sensor is active (object within 2 pixels) or 0 if not ex: return value of 4 (0100 2 ) means front bumper is active use bitwise Boolean operators to evaluate result ex: If (rbumper()&4) = 0 then 'front bumper inactive If (rbumper()&4)!= 0 then 'front bumper active

34 rfeel() details 0º the robot has 5 infrared sensors center, ±45º, ±90º each sensor has an assigned bit position in the return value (bottom 5 bits): -90º +90º bit: 4 3 2 1 0-90º -45º 0º +45º +90º each bit is 1 if object detected or 0 if not range distance is same as robot's radius ex: return value of 40 (11000 2 ) means objects are towards the left of robot use bitwise Boolean operators to evaluate result as with rbumper()

35 rground() details -10º 0º +10º the robot has 3 down-facing sensors center, ±10º each sensor has an assigned sensor number, one of which must be passed to rground as an argument 3=10º left, 2=center, 1=10º right rground() returns color seen directly under specified sensor and does not ignore any colors, even if invisible ex: move forward until robot is over something yellow Repeat rforward 1 Until rground(2)= YELLOW