Presentation is loading. Please wait.

Presentation is loading. Please wait.

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

Similar presentations


Presentation on theme: "Weston Schreiber & Joshua Gabrielse Robotics Summer Training Programming #3: Intro to Computational Thinking."— Presentation transcript:

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

2 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

3 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.

4 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)

5 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?”

6 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

7 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)

8 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

9 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?

10 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 1 + 2. Assign x equal to the previous value of x plus 1. x = 1 x = 1 + 2 x = x + 1

11 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 1 + 2. Assign x equal to the previous value of x plus 1. x = 1 x = 1 + 2 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

12 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 1 + 2. Assign x equal to the previous value of x plus 1. x = 1 x = 1 + 2 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

13 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 1 + 2. Assign x equal to the previous value of x plus 1. x = 1 x = 1 + 2 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

14 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 1 + 2. Assign x equal to the previous value of x plus 1. x = 1 x = 1 + 2 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

15 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.

16 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

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

18 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:

19 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

20 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?

21 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 )

22 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

23 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.

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

25 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)

26 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()

27 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)

28 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!

29 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)

30 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)

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

32 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

33 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

34 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.

35 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

36 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

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

38 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.

39 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.”

40 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

41 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;

42 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;

43 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

44 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;

45 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;

46 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

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

48 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

49 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

50 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

51 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.

52 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.

53 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()

54 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()

55 Weston Schreiber & Joshua Gabrielse One Possible Algorithm

56 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.

57 Weston Schreiber & Joshua Gabrielse Aids for Teaching Programming Stratch – Intro Programming Tool designed at MIT –http://scratch.mit.edu/http://scratch.mit.edu/ Code Academy – Online Instruction/Challenges –http://www.codecademy.comhttp://www.codecademy.com Lucid Charts – Nice web-based Flowchart Creator –http://www.lucidchart.com/http://www.lucidchart.com/ Flow Chart Practice –http://www.cimt.plymouth.ac.uk/projects/mepres/book8/bk8i1/bk8_1i2.htmhttp://www.cimt.plymouth.ac.uk/projects/mepres/book8/bk8i1/bk8_1i2.htm


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

Similar presentations


Ads by Google