Programming Merit Badge

Slides:



Advertisements
Similar presentations
Introduction to Programming
Advertisements

Programing Concept Ken Youssefi/Ping HsuIntroduction to Engineering – E10 1 ENGR 10 Introduction to Engineering (Part A)
Homework Any Questions?. Statements / Blocks, Section 3.1 An expression becomes a statement when it is followed by a semicolon x = 0; Braces are used.
Copyright © 2012 Pearson Education, Inc. Chapter 1: Introduction to Computers and Programming.
Program Design and Development
CSCE 121, Sec 200, 507, 508 Fall 2010 Prof. Jennifer L. Welch.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Java Software Solutions Foundations of Program Design Sixth Edition by Lewis.
Working with Arduino: Lesson #1: Getting Acquainted with the Kit EGN1007.
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.
Copyright © 2012 Pearson Education, Inc. Chapter 1: Introduction to Computers and Programming.
CHAPTER 4: INTRODUCTION TO COMPUTER ORGANIZATION AND PROGRAMMING DESIGN Lec. Ghader Kurdi.
Imperative Programming
Introduction to Python
Chapter 1: Introduction to Computers and Programming.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 1: Introduction to Computers and Programming.
Fundamentals of C and C++ Programming Control Structures and Functions.
IT253: Computer Organization Lecture 4: Instruction Set Architecture Tonga Institute of Higher Education.
Programing Concept Ken Youssefi/Ping HsuIntroduction to Engineering – E10 1 ENGR 10 Introduction to Engineering (Part A)
Introduction to Computer Systems and the Java Programming Language.
Chapter 8 High-Level Programming Languages. 8-2 Chapter Goals Describe the translation process and distinguish between assembly, compilation, interpretation,
CPS120: Introduction to Computer Science Decision Making in Programs.
Lecture 2b Dr. Robert D. Kent.  Structured program development  Program control.
BEGINNING PROGRAMMING.  Literally – giving instructions to a computer so that it does what you want  Practically – using a programming language (such.
Programming in C++ Dale/Weems/Headington Chapter 1 Overview of Programming and Problem Solving.
Introduction to Python Dr. José M. Reyes Álamo. 2 Three Rules of Programming Rule 1: Think before you program Rule 2: A program is a human-readable set.
 Control Flow statements ◦ Selection statements ◦ Iteration statements ◦ Jump statements.
CPS120: Introduction to Computer Science Variables and Constants.
Brief Version of Starting Out with C++ Chapter 1 Introduction to Computers and Programming.
Introduction to Computer Programming using Fortran 77.
Review A program is… a set of instructions that tell a computer what to do. Programs can also be called… software. Hardware refers to… the physical components.
7-Nov Fall 2001: copyright ©T. Pearce, D. Hutchinson, L. Marshall Oct lecture23-24-hll-interrupts 1 High Level Language vs. Assembly.
Python Programming Module 4 Sensors and Loops Python Programming, 2/e1.
Computer Basics.
GCSE Computing - The CPU
INTRODUCTION TO ROBOTICS Part 5: Programming
Computers’ Basic Organization
Information and Computer Sciences University of Hawaii, Manoa
The Machine Model Memory
Prof: Dr. Shu-Ching Chen TA: Samira Pouyanfar Spring 2017
Val Manes Department of Math & Computer Science
Chapter 7: Expressions and Assignment Statements
Topics Introduction Hardware and Software How Computers Store Data
Chapter 7: Expressions and Assignment Statements
Introduction to Gobbit Programming
Primitive Data, Variables, Loops (Maybe)
Introduction of microprocessor
Application Development Theory
Chapter 8: Control Structures
Engineering Innovation Center
Using Encoders to go Straight
11/10/2018.
Chapter 10 Programming Fundamentals with JavaScript
Computers: Hardware and Software
Working with Arduino: Lesson #1: Getting Acquainted with the Kit
CSCE Fall 2013 Prof. Jennifer L. Welch.
An Introduction to Java – Part I, language basics
CSCE 121: Simple Computer Model Spring 2015
Topics Introduction Hardware and Software How Computers Store Data
Other ISAs Next, we’ll first we look at a longer example program, starting with some C code and translating it into our assembly language. Then we discuss.
Homework Any Questions?.
CSCE Fall 2012 Prof. Jennifer L. Welch.
The Java switch Statement
Introduction Level Gobbit Assembly and Programming
PROGRAMMING.
Chapter 2 Programming Basics.
ECE 103 Engineering Programming Chapter 18 Iteration
Just Enough Java 17-May-19.
GCSE Computing - The CPU
Programming for Business Computing Introduction
Presentation transcript:

Programming Merit Badge SCOUTBOTICS Programming Merit Badge

Ada Lovelace

FORTRAN

Alan Turing

Colossus

ENIAC

COBOL Grace Hopper

IBM 350 3.75 MB $3200 / Month

SQL Edgar Codd

C Dennis Ritchie

C++ Bjarne Stroustrup

Apple LaserWriter PostScript

Python Guido van Rossum

Java James Gosling

CAREER OPPORTUNITIES

SAFETY

CYBER CHIP

Intellectual Property

IP Patents and Copyrights Licensing vs. Owning software Types of Software: Freeware Shareware Open source software Commercial software Patent Troll

Programming

Variables Integer – 1, 2, 3231 Float – 98.6, 3.14159 Fixed – 42.99 Character – “C”, “H”, “3” String – “Bobcat” “First Class” Array – [1, 2, 3, 32, 11]

Variables Loops For While Until Logical If-Then-Else

Python python.org

Find the sum: 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + 15 + 16 + 17 + 18 + 19 + 20 + 21 + 22 + 23 + 24 + 25 + 26 + 27 + 28 + 29 + 30 + 31 + 32 + 33 + 34 + 35 + 36 + 37 + 38 + 39 + 40 + 41 + 42 + 43 + 44 + 45 + 46 + 47 + 48 + 49 + 50 + 51 + 52 + 53 + 54 + 55 + 56 + 57 + 58 + 59 + 60 + 61 + 62 + 63 + 64 + 65 + 66 + 67 + 68 + 69 + 70 + 71 + 72 + 73 + 74 + 75 + 76 + 77 + 78 + 79 + 80 + 81 + 82 + 83 + 84 + 85 + 86 + 87 + 88 + 89 + 90 + 91 + 92 + 93 + 94 + 95 + 96 + 97 + 98 + 99 + 100 = ???

How many ways can you shuffle a deck of cards?

Find the product: 52 * 51 * 50 * 49 * … * 4 * 3 * 2 * 1 = 52! = ???

The Legend of the Chessboard

HTML/Javascript

GW-BASIC

Circle 100 CLS 110 LINE(200, 390) - (200, 390) 120 FOR A = 0 to 1000 STEP 0.01 130 LET X = 200 + 190 * SIN(A) 140 LET Y = 200 + 190 * COS(A) 150 LINE -(X, Y) 160 NEXT A 170 GOTO 170

SIRDS - STEP 1 100 CLS 110 FOR Y = 1 to 200 120 LET CN = INT(RND * 3) 130 FOR I = 1 TO 50 140 LET C = CN 150 LET CN = INT(RND * 3) 160 FOR X = I TO 50 STEP 50 170 PSET (X, Y), C 180 NEXT X 190 NEXT I 200 NEXT Y 210 GOTO 210

SIRDS - STEP 2 100 CLS 110 FOR Y = 1 to 200 120 LET CN = INT(RND * 3) 130 FOR I = 1 TO 50 140 LET C = CN 150 LET CN = INT(RND * 3) 160 FOR X = I TO 400 STEP 50 170 PSET (X, Y), C 180 NEXT X 190 NEXT I 200 NEXT Y 210 GOTO 210

SIRDS - STEP 3 162 LET DX = X - 200 164 LET DY = Y - 100 100 CLS 110 FOR Y = 1 to 200 120 LET CN = INT(RND * 3) 130 FOR I = 1 TO 50 140 LET C = CN 150 LET CN = INT(RND * 3) 160 FOR X = I TO 400 STEP 50 162 LET DX = X - 200 164 LET DY = Y - 100 166 LET R = SQR( DX * DX + DY * DY) 168 IF R < 20 THEN C = CN 170 PSET (X, Y), C 180 NEXT X 190 NEXT I 200 NEXT Y 210 GOTO 210

Introduction to Gobbit Programming SCOUTBOTICS Introduction to Gobbit Programming

Hardware The two most important hardware components to a programmer are: CPU RAM

The CPU The Central Processing Unit is the ‘brain’ of a computer. It is responsible for executing programs. While a program is running, it uses a processor Thread.

The RAM Random Access Memory gives a computer a place to store information quickly and temporarily. A running program stores its data in RAM RAM loses the stored data when the computer is shut down RAM is not long term storage

What is a Program? A program is a list of instructions to tell a computer what to do. The most basic form of computer instructions is called machine code. Machine code is very difficult for a human to read and understand. Programming in machine language is tedious and error prone. Programming today is usually done in a variety of high level programming languages (e.g. Java, C#, Python, Perl, Erlang, Clojure, ….)

The Building Blocks of Programs Data and Instructions are the two basic components of a program

Data Programs store data in variables. These variables are memory locations that can be accessed and modified. Since a variable might need to represent several different types of information, several can be used: Boolean (true/false) Integers ( 42, 0, -1) Floating Point (3.14, 0.0, -2.1) Characters (‘h’, ‘z’ ‘5’, ‘<‘) Strings (A group of characters): “Hello Programming”

Variables In a computer program its data lives in memory In order to access data you must know its location, or address, in memory It’s much easier to use a variable, which is named by you, than a computer memory address Example: int length = 24; float PI = 3.14; char middleInitial = ‘M’; string firstName = “Jason”;

Instructions A program runs a sequence of instructions from the top down. Control Structures are instructions that alter how the program executes certain commands. Arithmetic instructions Add, subtract, multiply and divide (+, -, *, /)

Instructions Example int area = 0, length = 2, width = 5; area = length * width; Advanced users: Look up “Order of Operations in Programming” http://en.wikipedia.org/wiki/Order_of_operations#Programming_languages

Control Structures All control structures affect program flow Branches – test a condition to decide between two or more courses of action. Conditions evaluate either true or false for example, a condition that tests if 5 is equal to 5 would evaluate to true. Loops – repeat a group of instructions. Subroutines (Functions) – Allow you to “jump” to a group of instructions, perform them and then “jump” back to where you were.

Programming Your Robot We will use an Arduino IDE (Integrated Development Environment) installed on your computer Launch the Arduino IDE from your new desktop icon The programming language used by the Arduino IDE is C/C++

Programming Your Robot (cont.) The other supplied programs you will be working with today: From the menu bar, select File > Examples > GobbitLineCommand MotorDirTest QTRTest GLC_BasicLine GLC_DriveCompetition GLC_Functions

Basics of an Arduino Program Place where we put our robot set-up code or any instructions you only want to run once void setup() { // put your setup code here, to run once: } void loop() { // put your main code here, to run repeatedly: Place where we put our main robot code that will run repeatedly

Basic Line Follower Program // If you are using either an Ardumoto version 14 or 20, or an Adafruit v2.3, uncomment // only the following motor driver define that matches to load the proper default values // If none are uncommented, Ardumoto v14 values will be used. //#define ARDUMOTO_14 //#define ARDUMOTO_20  //#define ADAFRUIT_MS #include <GobbitLineCommand.h> GobbitLineCommand MyBot; void setup() { MyBot.setBatteryVolts(9); MyBot.beginGobbit(); MyBot.calibrateLineSensor(0); } void loop() { MyBot.followLine(0); Uncomment one to set the proper motor defaults Includes the GobbitLineCommand library (pre-made functions) into your program Declare a GobbitLineCommand object with the name “MyBot” Sets the battery voltage Initializes the sensor Calibrate the line sensor using the specified calibration speed Line follow with modes 0) follow with no return, 1) follow one motor adjust and return, 2) follow one motor adjust and check for intersection then return, 3) follow until an intersection is found then return

Alternate Basic Line Follower Program #include <GobbitLineCommand.h> GobbitLineCommand MyBot; void setup() {   // kits with Ardumoto v14 will use this while newer kits with v20 use (5, 6, 7, 8, 9, 10, 12, 13)   MyBot.setQTRpins(2, 4, 5, 6, 7, 8, 9, 10);      // kits with Ardumoto v14 will use this while newer kits with v20 use (2, 3)   MyBot.setLeftMotorPinsDirPWM(12, 3);       // kits with Ardumoto v14 will use this while newer kits with v20 use (4, 11)   MyBot.setRightMotorPinsDirPWM(13, 11);   MyBot.setBatteryVolts(9);   MyBot.beginGobbit();   MyBot.calibrateLineSensor(); } void loop() {     MyBot.followLine(0);   } Set the pins based on the version of Ardumoto being used.

Useful Functions in the GobbitLineCommand Library // Run a calibration of the line sensor by sweeping back and forth // over a line at the called speed between 0-100. // Speed must be a 0 or positive value // 0 will load the default values based upon voltage if declared. void calibrateLineSensor(int calSpeed) Examples: MyBot.drive('F'); MyBot.drive('L'); MyBot.drive('R'); MyBot.drive('S');

Useful Functions in the GobbitLineCommand Library (cont.) // Drive will start driving/following the line and continue following // until it is able to complete the requested direction at the next // found intersection or end. If it cannot make the requested // direction, it will spin around fast and stop performing all other commands. // Turn direction value of ('L')eft, ('R')ight, ('F')orward, ('S')top, // or ('U')turn. // The U-turn will be evaluated by the found intersection turns available to // achieve a 180 degree turn. void drive(char turn) Examples: MyBot.drive('F'); MyBot.drive('L'); MyBot.drive('R'); MyBot.drive('S');

Useful Functions in the GobbitLineCommand Library (cont.) // Turns the robot using the line sensor on a lined course. // Uses the 'turnSpeedHigh' and 'turnSpeedLow' motor values while turning. // Turn direction values of ('L')eft, ('R')ight, or ('U')turn // Left turns left until the next line is found, regardless of 90 or 180 degree. // Right turns right until the next line is found, regardless of 90 or 180 degree. // U-turn turns left and assumes a 180 degree turn is requested where one line is // to be passed then stop at next. This is actually the same as running two // turn('L') commands, therefore, if there was no line at 90 degree to the left, // the turn will pass the 180 mark and stop at the next line, wherever it may be. // If that was the case, a single Left or Right turn request would have been // better. void turn(char turnDir) Examples: MyBot.turn(‘L'); MyBot.turn(‘R');

Useful Functions in the GobbitLineCommand Library (cont.) // Follow the line in called Mode: // Mode 0, along the line and never exit so it will not do anything else outside // of the function. // Mode 1, do 1 thing... run through the followLine function one time and make // only one motor adjustment then exit. // Mode 2, do 2 things... run through the followLine function one time and make // only one motor adjustment while checking if an intersection is // present then exit. // Mode 3, follow along the line until an intersection is found, update // intersection turn flags, then exit. void followLine(byte followMode) Examples: MyBot.followLine(0);

Useful Functions in the GobbitLineCommand Library (cont.) // Catch the Line by calling detectLine('A') until any sensor sees the line, // then calling followLine(1) enough times to align the robot with the line. // This assumes there was already some move or other motor command prior that // has the robot moving towards a line. // The function does not exit until it has caught the line. void catchLine(void) Examples: MyBot.catchLine();

Useful Functions in the GobbitLineCommand Library (cont.) // Detect if a line is found in the called part of the QTR sensor, then return a // byte of 1 if found, 0 if not. // Sensor location value of far ('L')eft, far ('R')ight, the two in ('C')enter, // or ('A')ny sensor. byte detectLine(char sensorLRCA) Examples: byte isItFound6 = MyBot.detectLine('L')

Useful Functions in the GobbitLineCommand Library (cont.) // Simple moves without any line following. Typically used with delay // statements as sensorless control. // First float value is the Speed/Velocity, value of -100 to 100. // -100 moveSpeed = reverse full speed // 100 = forward full speed // 0 = stopped; // Second float value is the Turn, value of -100 to 100. // -100 moveTurn = full left // 100 = full right // 0 = straight void move(float moveSpeed, float moveTurn) Examples: MyBot.move(80,65); // move forward at 80% speed and turn to the right MyBot.move(0,0); // stop the robot

Useful Functions in the GobbitLineCommand Library (cont.) // Set the speed and direction of the motors for both motor // shield/driver types. // Receives Left motor velocity/speed, Right motor velocity/speed. // Both are float values: // -100 full reverse // 100 full forward // 0 stopped void setMotors(float leftVelocity, float rightVelocity) Examples: MyBot.setMotors(100, 100);

Useful Variables in the GobbitLineCommand Library // These variables are byte "flags" to indicate if the robot has seen a line to the // left, forward (straight ahead), or right. Also "flags" to indicate if an // end or if a marker was found. // 1 if found // 0 if not found // Calling the drive (not when drive('S')), move, turn, and backup will reset // the flags. byte isItFound1 = MyBot.foundLeft; byte isItFound2 = MyBot.foundRight; byte isItFound3 = MyBot.foundForward; byte isItFound4 = MyBot.foundEnd; byte isItFound5 = MyBot.foundMark; Examples: if(MyBot.foundForward){…} if(MyBot.foundLeft){…}