Weston Schreiber & Joshua Gabrielse Robotics Summer Training Programming #3: Intro to Computational Thinking.

Slides:



Advertisements
Similar presentations
Introduction to Programming
Advertisements

Variables and Functions ROBOTC Software. Variables A variable is a space in your robots memory where data can be stored, including whole numbers, decimal.
08/2012Tanya Mishra1 EASYC for VEX Cortex Llano Estacado RoboRaiders FRC Team 1817.
Jason Howard. Agenda I. How to download robotc II. What is tele-op used for? III. How to build a basic tele-op program IV. Getting the robot to drive.
Team 5220 Roboknights. Outline  Getting Started  Hardware Setup/Wiring  Software Setup/Pragmas  Programming with RobotC  Grammar/Syntax  Basic Statements.
V EX C OACHES ' T RAINING October 12, Agenda for Today 9 – 10 AM : Tina Reeves and the Engineering Notebook 10 – Noon : Finish Building, Basic Robot.
Autonomy using Encoders Intro to Robotics. Goal Our new task is to navigate a labyrinth. But this time we will NOT use motor commands in conjunction with.
Programing Concept Ken Youssefi/Ping HsuIntroduction to Engineering – E10 1 ENGR 10 Introduction to Engineering (Part A)
Engineering H193 - Team Project Gateway Engineering Education Coalition P. 1 Spring Quarter 2008 Robot Programming Tips Week 4 Day 2 By Matt Gates and.
Programming Concepts (Part A) Ping Hsu. What is a program? WHITE CAKE RECIPE 1.Preheat oven to 350 degrees F (175 degrees C). 2.Grease and flour a 9x9.
COMP 14 Introduction to Programming Miguel A. Otaduy May 18, 2004.
© 2004 Pearson Addison-Wesley. All rights reserved5-1 Iterations/ Loops The while Statement Other Repetition Statements.
Programming Logic and Design, Introductory, Fourth Edition1 Understanding Computer Components and Operations (continued) A program must be free of syntax.
The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL Adrian Ilie COMP 14 Introduction to Programming Adrian Ilie June 30, 2005.
Programming – Touch Sensors Intro to Robotics. The Limit Switch When designing robotic arms there is always the chance the arm will move too far up or.
While Loops and Do Loops. Suppose you wanted to repeat the same code over and over again? System.out.println(“text”); System.out.println(“text”); System.out.println(“text”);
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.
ROBOTC for VEX Online Professional Development
PRINCIPLES OF PROGRAMMING Revision. A Computer  A useful tool for solving a great variety of problems.  To make a computer do anything (i.e. solve.
ROBOTC Software Introduction. ROBOTC Software ROBOTC developed specifically for classrooms and competitions Complete programming solution for VEX Cortex.
Variables in Java Part 2. ICS-3M1 - Mr. Martens - Variables Part 2 Recall the “int” Data Types When you divide one integer by another – you always get.
CIS Computer Programming Logic
Weston Schreiber & Joshua Gabrielse Robotics Summer Training Programming #1: EasyC Basics.
Chapter 5: Control Structures II (Repetition)
CHAPTER 5: CONTROL STRUCTURES II INSTRUCTOR: MOHAMMAD MOJADDAM.
EGR 2261 Unit 5 Control Structures II: Repetition  Read Malik, Chapter 5.  Homework #5 and Lab #5 due next week.  Quiz next week.
Programming with Alice Computing Institute for K-12 Teachers Summer 2011 Workshop.
Teacher/Mentor Institute Using easyC Joel Kirkland July 30-31, 2015.
Programing Concept Ken Youssefi/Ping HsuIntroduction to Engineering – E10 1 ENGR 10 Introduction to Engineering (Part A)
PYTHON: PART 2 Catherine and Annie. VARIABLES  That last program was a little simple. You probably want something a little more challenging.  Let’s.
Bug Session Four. Session description Objectives Session activities summary Resources Prior knowledge of sequencing instructions using Bug Bug website.
1 Conditions Logical Expressions Selection Control Structures Chapter 5.
Chapter 5: Control Structures II (Repetition). Objectives In this chapter, you will: – Learn about repetition (looping) control structures – Learn how.
Xtreme Robot Olympiad Programming Basics Dr. Peter Laz Associate Professor Department of Engineering University of Denver.
ICT Introduction to Programming Chapter 4 – Control Structures I.
Chapter 4 Literals, Variables and Constants. #Page2 4.1 Literals Any numeric literal starting with 0x specifies that the following is a hexadecimal value.
COIT29222 Structured Programming 1 COIT29222-Structured Programming Lecture Week 02  Reading: Textbook(4 th Ed.), Chapter 2 Textbook (6 th Ed.), Chapters.
Variables and Functions ROBOTC Software © 2012 Project Lead The Way, Inc.Principles of Engineering.
September 7, 2004ICP: Chapter 3: Control Structures1 Introduction to Computer Programming Chapter 3: Control Structures Michael Scherger Department of.
Midterm preview. double int = 2.0; True / FalseThe following is a syntactically correct variable declaration and assignment statement:
Decision Statements, Short- Circuit Evaluation, Errors.
Controlling Program Flow with Decision Structures.
BIT 115: Introduction To Programming Professor: Dr. Baba Kofi Weusijana (say Doc-tor Way-oo-see-jah-nah, Doc-tor, or Bah-bah)
Vex Robotics program three: using motors and sensors together.
C++ Programming: From Problem Analysis to Program Design, Fifth Edition Chapter 5: Control Structures II (Repetition)
Weston Schreiber Robotics Summer Training Programming #4: Autonomous Scoring.
Algorithms and Flowcharts
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.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Extended Prelude to Programming Concepts & Design, 3/e by Stewart Venit and.
Variables and Functions
INTRODUCTION TO ROBOTICS Part 5: Programming
Chapter 10 Programming Fundamentals with JavaScript
Variables and Functions
Robotics Programming Using Shaft Encoders
CS1001 Programming Fundamentals 3(3-0) Lecture 2
Computer Programming Methodology Introduction to Java
Variables and Functions
Movement using Shaft Encoders
Programming – Touch Sensors
Variables and Functions
Variables and Functions
Chapter 10 Programming Fundamentals with JavaScript
Unit 2 Programming.
Programming Autonomy By Joshua Shaw.
Robotics Programming Using Shaft Encoders
Robotics Programming Using Shaft Encoders
Chapter 3: Selection Structures: Making Decisions
Chapter 3: Selection Structures: Making Decisions
Presentation transcript:

Weston Schreiber & Joshua Gabrielse Robotics Summer Training Programming #3: Intro to Computational Thinking

Weston Schreiber & Joshua Gabrielse Objectives: Understand the 3 stages to programming Create an algorithm that accomplishes a programming task Understand the purpose of variables, if statements, loops, and functions in programs

Weston Schreiber & Joshua Gabrielse 1 st Rule of Programming Computers are stupid!!!! They do EXACTLY what they are told, nothing less, nothing more, and they never get the idea.

Weston Schreiber & Joshua Gabrielse Stage 1: Planning (Algorithm, Flowchart, Pseudocode) Stage 2: Coding (Variables, Functions, if statements, Loops) Stage 3: Error Analysis (Syntax Errors, Logic Errors, Readdress Plan) Stage 1: Planning (Algorithm, Flowchart, Pseudocode)

Weston Schreiber & Joshua Gabrielse Flowcharts & Algorithm Planning Two Types of Parts to a Programming Flowchart: Actions Decisions “Yes” “No” Robotics Examples “Turn on wheel motors”“Is the front bumper pushed?” “Lift Gripper Arm”“Has the robot turned 3 times?” “Stop all motors”“Has the encoder registered over 1000 counts?”

Weston Schreiber & Joshua Gabrielse Flowcharts Recap: If the answer to Question 1 is “yes,” and the answer to Question 2 is “no,” what order do the steps happen? Click the number corresponding to the correct answer on your clicker. A) Step 1, Step 2 B) Step 2, Step 3B C) Step 1, Step 2, Step 3A D) Step 1, Step 2, Step 3B

Weston Schreiber & Joshua Gabrielse Stage 1: Planning (Algorithm, Flowchart, Pseudocode) Stage 2: Coding (Variables, Functions, if statements, Loops) Stage 3: Error Analysis (Syntax Errors, Logic Errors, Readdress Plan)

Weston Schreiber & Joshua Gabrielse Basics of Computer Programming Variables - place to store changeable information Functions - block of reusable code Conditional ( if ) Statements - code that only runs if a condition is TRUE Loops (while, for ) - section of code that repeats Variables - place to store changeable information

Weston Schreiber & Joshua Gabrielse Basics of Computer Programming Variables - place to store changeable information What are some variables in your everyday life? What are some variables PowerPoint is storing to run this presentation?

Weston Schreiber & Joshua Gabrielse Variables A place to store changeable information. BEGIN END int x Example: Create a variable (a place to store integers) called x. Assign x a value of 1. Assign x the value of the expression Assign x equal to the previous value of x plus 1. x = 1 x = x = x + 1

Weston Schreiber & Joshua Gabrielse What is the value of x after line 1? BEGIN END int x Example: Create a variable (a place to store integers) called x. Assign x a value of 1. Assign x the value of the expression Assign x equal to the previous value of x plus 1. x = 1 x = x = x + 1 line 0 line 1 line 2 line 3 Click the number corresponding to the correct answer on your clicker. A) 1B) 2C) 3D) 4E) 5F) 0G) a random number

Weston Schreiber & Joshua Gabrielse What is the value of x after line 2? BEGIN END int x Example: Create a variable (a place to store integers) called x. Assign x a value of 1. Assign x the value of the expression Assign x equal to the previous value of x plus 1. x = 1 x = x = x + 1 line 0 line 1 line 2 line 3 Click the number corresponding to the correct answer on your clicker. A) 1B) 2C) 3D) 4E) 5F) 0G) a random number

Weston Schreiber & Joshua Gabrielse What is the value of x after line 3? BEGIN END int x Example: Create a variable (a place to store integers) called x. Assign x a value of 1. Assign x the value of the expression Assign x equal to the previous value of x plus 1. x = 1 x = x = x + 1 line 0 line 1 line 2 line 3 Click the number corresponding to the correct answer on your clicker. A) 1B) 2C) 3D) 4E) 5F) 0G) a random number

Weston Schreiber & Joshua Gabrielse What is the value of x after line 0? BEGIN END int x Example: Create a variable (a place to store integers) called x. Assign x a value of 1. Assign x the value of the expression Assign x equal to the previous value of x plus 1. x = 1 x = x = x + 1 line 0 line 1 line 2 line 3 Click the number corresponding to the correct answer on your clicker. A) 1B) 2C) 3D) 4E) 5F) 0G) a random number

Weston Schreiber & Joshua Gabrielse Declaring Variables Computers & robots need to know three things in order to create variables: 1.Type: how much memory to reserve, and how it is used Integers take less memory than floating point decimals. Example: 1 (int)  it takes less memory just to store the number 1.0 (float)  it takes extra memory to store the location of the decimal point 2.Name: how to refer to/locate the reserved memory Pick names that are logical and easy to remember 3.Value: what to store in that memory If you don’t give an initial value, whatever random value is left in that memory location will remain there Double click on the variables block in the flow chart of any function to declare (create) variables.

Weston Schreiber & Joshua Gabrielse Declaring Variables (simplified) Pick: 1.Type: what kind of information is being stored 2.Name: a descriptive identifier (you pick the name) 3.Value: the information initially stored in the variable Double click on the variables block

Weston Schreiber & Joshua Gabrielse Variable Types When in doubt, pick int! Need to use decimals? Use double!

Weston Schreiber & Joshua Gabrielse What are the key parts to a function? Click the number corresponding to the correct answer on your clicker. A) Name, Type, Value B) Name, Parameters, Description C) Name, Parameters, Action D) Name, Description, Value Functions Recap:

Weston Schreiber & Joshua Gabrielse Basics of Computer Programming Variables - place to store changeable information Functions - block of reusable code Conditional ( if ) Statements - code that only runs if a condition is TRUE Loops (while, for ) - section of code that repeats

Weston Schreiber & Joshua Gabrielse Basics of Computer Programming Functions - block of reusable code What are some “functions” in your daily life? What are some functions PowerPoint might use to run this presentation?

Weston Schreiber & Joshua Gabrielse EasyC Built-In Functions: All the tools we’ll need to control the flow of the program (or, which code to run and when to run it) Important Function: Wait( ms )

Weston Schreiber & Joshua Gabrielse Writing Your 1 st Program 1.Write a Plan for your Controller Setup 2.Start a New Program 3.Operator Control 4.Build & Download to Robot 5.Autonomous Program

Weston Schreiber & Joshua Gabrielse Objectives: Create a simple autonomous program Have your robot drive on its own! Create an autonomous program for your robot to score a goal.

Weston Schreiber & Joshua Gabrielse Autonomous Goal #1: Drive forward and stop.

Weston Schreiber & Joshua Gabrielse Stage 1: Planning (Algorithm, Flowchart, Pseudocode) Stage 2: Coding (Variables, Functions, if statements, Loops) Stage 3: Error Analysis (Syntax Errors, Logic Errors, Readdress Plan)

Weston Schreiber & Joshua Gabrielse Which set of function calls would correctly accomplish our goal? Click the number corresponding to the correct answer on your clicker. A. B. C. DriveStraight() Stop() Wait() DriveStraight() Wait() Stop() DriveStraight() Wait() Stop()

Weston Schreiber & Joshua Gabrielse Stage 1: Planning (Algorithm, Flowchart, Pseudocode) Stage 2: Coding (Variables, Functions, if statements, Loops) Stage 3: Error Analysis (Syntax Errors, Logic Errors, Readdress Plan)

Weston Schreiber & Joshua Gabrielse Stage 2: Coding (Variables, Functions, if statements, Loops) Recall the functions we discussed the other day DriveStraight(), Stop() Write the code for those functions. Create your autonomous program!

Weston Schreiber & Joshua Gabrielse Stage 1: Planning (Algorithm, Flowchart, Pseudocode) Stage 2: Coding (Variables, Functions, if statements, Loops) Stage 3: Error Analysis (Syntax Errors, Logic Errors, Readdress Plan)

Weston Schreiber & Joshua Gabrielse Competition Switches Enable/Disable & Autonomous/Operator Control Hardware: plug the ethernet cable into the competition port on the joystick Software: the computer has to be connected directly to the robot controller or through VEXnet from the joystick (via the programming port)

Weston Schreiber & Joshua Gabrielse Basics of Program Complete Rest: Advanced Concepts

Weston Schreiber & Joshua Gabrielse Naming Conventions 1.Pick descriptive names. 2.Follow capitalization standards Variable names start with lower case letters. Function names start with capital letters. Constants are all capitals. 3.Use camel case for multi-word names. Example 1: camelCase Example 2: CamelCase

Weston Schreiber & Joshua Gabrielse What is DriveForward according to our naming convention? A)a variable B)a function C)a constant D)it doesn’t fit our naming convention

Weston Schreiber & Joshua Gabrielse What is PUSHED according to our naming convention? A)a variable B)a function C)a constant D)it doesn’t fit our naming convention I’m supposed to be pushing the button with my nose.

Weston Schreiber & Joshua Gabrielse What is frontBumper according to our naming convention? A)a variable B)a function C)a constant D)it doesn’t fit our naming convention

Weston Schreiber & Joshua Gabrielse Basics of Computer Programming Variables - place to store changeable information Functions - block of reusable code Conditional ( if ) Statements - code that only runs if a condition is TRUE Loops (while, for ) - section of code that repeats

Weston Schreiber & Joshua Gabrielse Basics of Computer Programming Conditional ( if ) Statements - code that only runs if a condition is TRUE

Weston Schreiber & Joshua Gabrielse If Conditions – Structure & Function Condition: any statement that can be evaluated as true or false. CONDITION ACTION IF the CONDITION is TRUE the ACTION happens and the program continues after the IF. IF the CONDITION is not true the ACTION never happens and the program continues after the IF.

Weston Schreiber & Joshua Gabrielse If Conditions – Structure & Function Condition: Compares two variables/values using a comparison operator SymbolDefinition ==equal !=not equal >greater than >= greater than or equal to <less than <= less than or equal to ( A [symbol] B ) Double equal signs (==) check to see if a statement is true. Ex: x == 4 Single equal signs (=) assign a value to a variable. Ex: x = 4 Assign is just programmer-talk for “set equal to.”

Weston Schreiber & Joshua Gabrielse If Conditions – Check Your Understanding Example If Condition: Based on variable values, what functions will run? Click the number corresponding to the correct answer on your clicker. A)DontVote() B)GoShopping() C)DontVote(), then GoShopping() D)No functions will run E)age < 18

Weston Schreiber & Joshua Gabrielse If Conditions – Check Your Understanding Example If Condition: Based on variable values, what functions will run? Click the number corresponding to the correct answer on your clicker. A)GetMoreSupplies() B)TeachArtProject() C)GetMoreSupplies(), TeachArtProject() D)TeachArtProject(), GetMoreSupplies() E)No functions will run numStudents = 22;

Weston Schreiber & Joshua Gabrielse If Conditions – Check Your Understanding Example If Condition: Based on variable values, what functions will run? Click the number corresponding to the correct answer on your clicker. A)TurnFor(), DriveStraightFor() B)DriveStraightFor(), TurnFor() C)frontBumper == PUSHED, DriveStraightFor() D)DriveStraightFor() E)TurnFor() F)No Functions will run frontBumper = 0;

Weston Schreiber & Joshua Gabrielse If Else Conditions – Structure & Function IF the CONDITION is TRUE, ACTION #1 happens and the program continues after the IF. IF the CONDITION is FALSE, ACTION #2 happens and the program continues after the IF. CONDITION ACTION #1 ACTION #2

Weston Schreiber & Joshua Gabrielse If Else Conditions – Check Your Understanding Based on variable values, what functions will run? Click the number corresponding to the correct answer on your clicker. A)BuyVideoGame() B)BuyBook() C)BuyLunch() D)BuyVideoGame(), BuyBook() E)BuyVideoGame(), BuyLunch() F)BuyBook(), BuyLunch() G)All 3 functions will run H)No functions will run money = 100;

Weston Schreiber & Joshua Gabrielse If Else Conditions – Check Your Understanding Based on variable values, what functions will run? Click the number corresponding to the correct answer on your clicker. A)DriveStraight() B)Stop() C)FlashLEDS() D)DriveStraight(), Stop() E)DriveStraight(), FlashLEDS() F)Stop(), FlashLEDS() G)All 3 functions will run H)No functions will run backBumper = 1;

Weston Schreiber & Joshua Gabrielse Basics of Computer Programming Variables - place to store changeable information Functions - block of reusable code Conditional ( if ) Statements - code that only runs if a condition is TRUE Loops (while, for ) - section of code that repeats

Weston Schreiber & Joshua Gabrielse Basics of Computer Programming Loops (while, for ) - section of code that repeats

Weston Schreiber & Joshua Gabrielse While Loops – Structure & Function Condition: any statement that can be evaluated as true or false. WHILE the CONDITION is TRUE, keep doing the ACTION(S) repeatedly. Once the CONDITION is FALSE, the ACTION stops happening and the program continues after the WHILE. CONDITION ACTION

Weston Schreiber & Joshua Gabrielse While Loops – Structure & Function 3 Outcomes for a While Loop CONDITION ACTION In the C Programming Language: 1 = TRUE 0 = FALSE – So – While (1) is always true and the program is stuck in an endless loop Loop runs foreverLoop runs a number of times and stops Loop is skipped and never runs Loop runs foreverLoop runs a number of times and stops Loop is skipped and never runs The condition stays TRUE forever The condition starts TRUE, but eventually evaluates as FALSE The condition is FALSE initially

Weston Schreiber & Joshua Gabrielse While Loops – Check Your Understanding Example: Based on variable values, how many times will the loop repeat before running GoToATM()? Click the number corresponding to the correct answer on your clicker. A)The loop will never run. B)1 time C)4 times D)5 times E)The loop will never stop

Weston Schreiber & Joshua Gabrielse While Loops – Check Your Understanding Example: Based on variable values, what actions will the robot take? Click the number corresponding to the correct answer on your clicker. A)The robot will drive straight ahead. B)The robot won’t move. C)The robot will turn for a bit, then drive straight ahead. D)The robot will turn in a circle continuously, never stopping.

Weston Schreiber & Joshua Gabrielse While Loops – Check Your Understanding Example: Based on variable values, what actions will the robot take? Click the number corresponding to the correct answer on your clicker. A)Drive straight, then Turn continuously. B)Drive straight forever. C)Drive straight, Turn, then Stop. D)Drive straight, then Stop.

Weston Schreiber & Joshua Gabrielse Autonomous Flowchart (Easier) Make a flow chart for a robot with a bumper switch in the front. The robot drives forward, stopping when it hits something. Function Hints DriveForward() CheckFrontBumper()

Weston Schreiber & Joshua Gabrielse Autonomous Flowchart (Harder) Make a flow chart for a robot with a bumper switch in the front and the back. Every time the robot runs into something it changes direction. Function Hints DriveForward() DriveBackward() CheckFrontBumper() CheckBackBumper()

Weston Schreiber & Joshua Gabrielse One Possible Algorithm

Weston Schreiber & Joshua Gabrielse One Possible Algorithm Equivalent C-Code Generated by EasyC Go to Window  Block & C Programming in EasyC to see both the flowchart and the C code.

Weston Schreiber & Joshua Gabrielse Aids for Teaching Programming Stratch – Intro Programming Tool designed at MIT – Code Academy – Online Instruction/Challenges – Lucid Charts – Nice web-based Flowchart Creator – Flow Chart Practice –