Arduino Programming Part 7: Flow charts and Top-down design ME 121 Gerald Recktenwald Portland State University

Slides:



Advertisements
Similar presentations
Control of Salinity EAS 199B Modifications of ENGR 121 living with the lab.
Advertisements

Control of salinity living with the lab © 2012 David Hall.
Chapter 1 - An Introduction to Computers and Problem Solving
Chapter 2 - Problem Solving
Chapter 2 - Problem Solving
Basics of Computer Programming Web Design Section 8-1.
Chapter 2- Visual Basic Schneider
Chapter 1 Program Design
Engineering H192 - Computer Programming The Ohio State University Gateway Engineering Education Coalition Lect 3P. 1Winter Quarter Structured Engineering.
Tips for fishtank programming living with the lab © 2013 David Hall.
Control of salinity living with the lab © 2012 David Hall.
Problem Solving using the Science of Computing MSE 2400 EaLiCaRA Spring 2015 Dr. Tom Way.
Chapter 2 - VB 2005 by Schneider- modified by S. Jane '081 Chapter 2 - Problem Solving 2.1 Program Development Cycle 2.2 Programming Tools.
Chapter 2- Visual Basic Schneider1 Chapter 2 Problem Solving.
CSCI 161 Lecture 3 Martin van Bommel. Operating System Program that acts as interface to other software and the underlying hardware Operating System Utilities.
CMSC 104, Section 301, Fall Lecture 18, 11/11/02 Functions, Part 1 of 3 Topics Using Predefined Functions Programmer-Defined Functions Using Input.
ME 120: Arduino Programming Arduino Programming Part II ME 120 Mechanical and Materials Engineering Portland State University
Fish Tank Project Introduction ME 121Portland State University Mechanical and Materials Engineering.
CSE 110: Programming Language I Matin Saad Abdullah UB 404.
Control of salinity living with the lab © 2012 David Hall.
Programming Languages
Basics of Computer Programming
DDC 1023 – Programming Technique
Chapter 2- Visual Basic Schneider
System Design.
Basics of Computer Programming
Basics of Computer Programming
Basics of Computer Programming
Using variables, for..loop and functions to help organize your code
Unit# 9: Computer Program Development
Lesson 2 Programming constructs – Algorithms – Scratch – Variables Intro.
Programming Fundamentals (750113) Ch1. Problem Solving
Global Challenge Fitness Friend Lesson 2.
Global Challenge Night Sensor Lesson 2.
Algorithm Discovery and Design
We’re moving on to more recap from other programming languages
Chapter 2- Visual Basic Schneider
Global Challenge Night Sensor Lesson 2.
Topics: Programming Constructs: loops & conditionals Digital Input
Chapter 2- Visual Basic Schneider
Global Challenge Night Sensor Lesson 2.
Global Challenge Night Sensor Lesson 2.
Global Challenge Fitness Friend Lesson 2.
Chapter 5 Loops Liang, Introduction to Java Programming, Tenth Edition, (c) 2015 Pearson Education, Inc. All rights reserved.
Global Challenge Fitness Friend Lesson 2.
Global Challenge Night Sensor Lesson 2.
Global Challenge Walking for Water Lesson 2.
Global Challenge Night Sensor Lesson 2.
Global Challenge Fitness Friend Lesson 2.
Programming Fundamentals (750113) Ch1. Problem Solving
Global Challenge Fitness Friend Lesson 2.
Global Challenge Walking for Water Lesson 2.
Global Challenge Walking for Water Lesson 2.
Global Challenge Night Sensor Lesson 2.
Global Challenge Fitness Friend Lesson 2.
Global Challenge Night Sensor Lesson 2.
Global Challenge Fitness Friend Lesson 2.
Global Challenge Night Sensor Lesson 2.
Programming Fundamentals (750113) Ch1. Problem Solving
Global Challenge Fitness Friend Lesson 2.
Global Challenge Walking for Water Lesson 2.
Global Challenge Walking for Water Lesson 2.
Global Challenge Walking for Water Lesson 2.
Global Challenge Night Sensor Lesson 2.
Global Challenge Night Sensor Lesson 2.
Global Challenge Walking for Water Lesson 2.
Global Challenge Fitness Friend Lesson 2.
Global Challenge Walking for Water Lesson 2.
Global Challenge Walking for Water Lesson 2.
Global Challenge Walking for Water Lesson 2.
Presentation transcript:

Arduino Programming Part 7: Flow charts and Top-down design ME 121 Gerald Recktenwald Portland State University

Goals Introduce flow charts  A tool for developing algorithms  A tool for documenting algorithms  A visual method of communicating about any sequential or iterative process  Great for visual learners! Top-down design  One technique for creating a plan for large, multi-step problems  Not tied to flow charts, but can be used effectively with flow charts 2

Flow chart symbols 3

Exercise 1 Draw the flow chart to read and display the salinity value on the LCD monitor Keep it simple  5 or so symbols (not counting arrows)  Describe only the high level actions 4

Exercise 1 5 Your answer goes here.

Exercise 1 6

Exercise 2 Expand the “Read salinity” step in another flow chart  Keep it simple  “analog data” is an external input 7 analog input

Exercise 2 8 Your answer goes here.

Exercise 2 9

Exercise 3 Expand the “Read analog input” step in another flow chart  Compute the average of n readings  “analog data” is an external input 10

Exercise 3 11 Your answer goes here.

Exercise 3 12

Top-down design 1.Start with a general statement of the solution  List the main steps  Don’t worry yet about details 2.Pick one of the steps  Break this step into a manageable number of sub-steps  Don’t worry about too many of the details  Apply step 2 to one of steps just generated 13

Top-down design 14 Recursive refinement: from general to specific

Top-down design 15 Recursive refinement: from general to specific

Top-down design 16 Recursive refinement: from general to specific

Top-down design 17 Repeat refinement until individual steps can be translated in to concrete actions or lines of code Recursive refinement: from general to specific

Extending top-down design to salinity control of the fish tank Main tasks  Measure salinity  Display salinity on the LCD panel  Check: Are we in the deadtime?  If yes, skip to next loop iteration  If no, check for out of deadband condition If salinity is above UCL, add fresh water If salinity is below LCL, add salty water Each of the tasks could (should!) be decomposed into smaller steps with a top-down design process 18

Core control algorithm 19 // File: wait_for_deadtime.ino // // Structure of salinity control code to implement a deadtime during which // no salinity correction is made. This code is incomplete and will not compile. unsigned long last_salinity_update; // Time of last correction void setup() { Serial.begin(9600); last_salinity_update = millis(); // Initial value; change later } void loop() { float LCL, UCL, salinity; int deadtime =... ; salinity = salinity_reading(... ); update_LCD(... ); // -- Check for deadtime if ( ( millis() – last_salinity_update ) > deadtime ) { if ( salinity>UCL ) { // add DI water: several missing steps last_salinity_update = millis(); } if ( salinity<LCL ) { // add salty water: several missing steps last_salinity_update = millis(); }

// File: wait_for_deadtime.ino // // Structure of salinity control code to implement a deadtime during which // no salinity correction is made. This code is incomplete and will not compile. unsigned long last_salinity_update; void setup() { Serial.begin(9600); last_salinity_update = millis(); } void loop() { float LCL, UCL, salinity; int deadtime =... ; salinity = salinity_reading(... ); update_LCD(... ); // -- Check for deadtime if ( ( millis() – last_salinity_update ) > deadtime ) { if ( salinity>UCL ) { // add DI water: several missing steps last_salinity_update = millis(); } if ( salinity<LCL ) { // add salty water: several missing steps last_salinity_update = millis(); } Core control algorithm: managing deadtime 20 Global (and persistent) value to remember time of last change to the system Set initial value. Update again later Don’t even consider making changes while we are in the deadtime. “In the deadtime” means “current time minus time of last system change” is greater than deadtime Update the “time of last system change” every time the salinity is changed

// File: wait_for_deadtime.ino // // Structure of salinity control code to implement a deadtime during which // no salinity correction is made. This code is incomplete and will not compile. unsigned long last_salinity_update; void setup() { Serial.begin(9600); last_salinity_update = millis(); } void loop() { float LCL, UCL, salinity; int deadtime =... ; salinity = salinity_reading(... ); update_LCD(... ); // -- Check for deadtime if ( ( millis() – last_salinity_update ) > deadtime ) { if ( salinity>UCL ) { // add DI water: several missing steps last_salinity_update = millis(); } if ( salinity<LCL ) { // add salty water: several missing steps last_salinity_update = millis(); } Core control algorithm: task decomposition 21 1.Function to read salinity sensor and convert reading to mass fraction. 2.Function to update LCD 3.Function to determine size of the correction and open the valve. One function could handle both corrections if you design it to use the right input arguments

Recommendations Work in small increments  Identify a task, build the code to test that task independently of the entire control algorithm Write functions to do specific tasks  Read salinity sensor and convert to mass fraction  Update display  Determine size duration of valve opening, and open it Document your code as you write it Save backups of working code and testing codes Use Auto Format to clean up code 22