Lecture 1: Course Introduction Overview of Computers and their Applications in MAE BJ Furman 01SEP2012 The Plan for Today Welcome to ME 30 Learning objectives Roll call Highlights from the syllabus (aka, ‘greensheet’) Overview of computers and their applications in MAE Introduce structured programming, algorithms, pseudocode, and flowcharts Form of a C program Data types and variables Learning Objectives By the end of the lecture you should be able to: Explain the focus of the course Describe where and how computers are used by mechanical and aerospace engineers (MAEs) List some of the software commonly used by MAEs Describe what the major elements of a computer are and what they do conceptually Explain what is meant by ‘structured programming’ Describe the structure of a C program List and describe the important data types Declare a variable Roll Call Back Syllabus Highlights and Where to Find Things Available at www.engr.sjsu.edu/bjfurman/courses/ME30/ and sjsu.desire2learn.com My contact and office information My background Course information Course goals and learning objectives Textbook Policies and protocol Grading Resources Course schedule Back Focus of ME 30 Solving problems with computers Learn structured programming using the C language Learn the process for formulating a computational solution to a problem Practice the process Get prepared for learning about mechatronics Gain familiarity with other software used by MAEs for technical computing Matlab Excel Where and How are Computers Used in MAE? ?? Where and How are Computers Used in MAE? 1 Technical and Personal Communication Email Word processing (reports, procedures, etc.) Presentations Conferencing Computation and Analysis Arithmetic Equation solving Data analysis and visualization Multiphysics and numerical modeling sin(r)/r Where and How are Computers Used in MAE? 2 Design Solid modeling (ME 165) Finite Element Analysis (FEA) (ME 160) Dynamic modeling and simulation (ME 147, ME 187, ME 190) Design tradeoffs and analytical modeling of mechanical components and systems (ME 154, ME 157) Gathering Information Web searches Patent searches Databases Vendor and other websites Datasheets Where and How are Computers Used in MAE? 3 Testing and Experimental Work Data acquisition from sensors (ME 120) Laboratory and Factory Automation and Control Dynamic systems (ME 187, ME 190) Factory automation video Instrumentation and Product Design http://las.perkinelmer.com/Content/Images /smallImages/janusLabAuto.jpg Embedded controllers (ME 106, ME 190) MRP, Inventory, and Document Control Drawings Procedures Bill of Materials (BOM) Specifications Engineering change orders (ECOs) http://www.plm.automation.siemens.com/en_us/products/teamcent er/solutions_by_product/mechatronics_process_management.shtm What Software is Most Often Used? 1 Technical and Personal Communication Email (MS Outlook, Mozilla Thunderbird) Word processing (MS Word, Open Office) Presentations (MS Power Point, Open Office) Computation and Analysis Spreadsheets (MS Excel, Open Office Calc) Mathcad/Maple/Mathematica Matlab/Octave/Scilab TK Solver Maxima What Software is Most Often Used? 2 Design Solid modeling (Solidworks, ProE, Inventor, Unigraphics) Finite Element Analysis (Cosmos, ProMechanica, Nastran) Dynamic modeling and simulation (Matlab/Simulink, ) Design tradeoffs and analytical modeling of mechanical components and systems (Excel, Mathcad, Matlab, TK Solver) Gathering Information Web searches (Google, other search engines) Patent searches (Google Patent, USPTO website) Databases (see the SJSU Articles & Databases website: http://www.sjlibrary.org/research/databases/index.htm?getType=3 Vendor and other websites (Google, other search engines) Datasheets (Google, vendor websites) What Software is Most Often Used? 3 Testing and Experimental Work Lab View, C, Matlab Laboratory and Factory Automation and Control Lab View, C, Visual Basic Instrumentation and (Mechatronic) Product Design C, Matlab, Lab View (see “Real Men Program in C”) Product Data Management Siemens PLM Oracle Agile Dassault Enovia The Bottom Line Mechanical and aerospace engineers use computers widely You need to know how to use computers to help you be successful ME 30 will help you especially in the area of computation and analysis Focus will be on the C language Exposure to Matlab and Excel I hope it will also whet your appetite to learn about mechatronics Next --> Networking Introduce yourself to someone you DO NOT know Find out one thing about them that they like to do in their spare time Two minutes! Back What do computers actually do? Perform arithmetic operations Addition, subtraction, multiplication, division Compare two values And decide among alternative courses of action If a > b, then do action c Move data around internally (memory and peripherals) Input data (keyboard, mouse, sensors, etc.) Output data (display, I/O ports, etc.) And do all of this really fast …. Robot Programming Problem Write a program to make a robot follow a square course What’s Inside and How Does it Work? Personal Computer (PC) Anatomy Case or housing Power supply Motherboard CPU Memory Video and audio chipsets Networking I/O ports Hard disk Embedded computers likely not to have Solid state sometimes now Peripherals CD or DVD drive Computer Block Diagram Disk controller CPU Memory USB, Serial, Keyboard, Mouse, etc. Ports Video chipset Display Audio chipset Speakers Networking chipset Bus Hard drive, CD/DVD Internet Memory Stores program instructions and data Each location has an ‘address’ Each location stores the information as ‘bits’ Binary ____its Zero or one Memory (8-bit) Address 0x10FE 0 1 1 0 0 1 1 0 0x10FF 0 1 0 1 0 1 0 0 0x1100 0 0 0 0 0 0 0 0 0xFFFF Bit 7 6 5 4 3 2 1 0 8 bits is one byte Information is ‘coded’ Memory is ‘written’ or ‘read’ CPU The ‘brain’ of your computer Carries out the instructions of your program Essential components: Arithmetic Logic Unit (ALU) Does arithmetic and logic functions Controls the actions inside the CPU Registers Add and subtract (sometimes multiply and divide) Bit-wise logic: AND, OR, NOT, XOR Bit shift (left or right) ALU CU Control Unit (CU) CPU Temporary locations to store data, instructions, and addresses Clock Synchronizes operations in the CPU Clock Registers Instructions Data Memory Adapted from Fundamentals of Computer Organization and Architecture, M. Abd-El-Barr, H. El-Rewini, John Wiley and Sons, 2005 Ports Connection to the external world USB Serial Keyboard Monitor Pins on a microcontroller http://media.digikey.com/photos/Atmel %20Photos/453-64-TQFP.jpg Voltage level determines whether a 0 or a 1 Ex. 5 V logic: < 1.5 V = 0 > 3.5 V = 1 http://www.atmel.com/dyn/resources/prod_documents/doc2467.pdf Software The intermediary between you (the user) and the hardware Operating system (OS) see the next page Windows, OS X, Linux Application programs End-user applications Word processor, solid modeler, etc. Mathcad, Matlab, etc. Application development software (programming languages) C, Matlab (sort of), Lab View (sort of), Python, Java, FORTRAN, etc. Operating System (OS) A program that: Acts as an intermediary between hardware and application software Provides a consistent, stable way for applications to interact with hardware APIs, so you don’t have to do it all yourself Examples: Windows XP/Vista Linux OS X http://en.wikipedia.org/wiki/File:Operating_system_placement.svg Create/Edit source files (your program!) Program Development from Figure 1.11, p. 32 in HK note additions! Compile source files Link compiled files Load executable file Run your program! Test Repeat process Correct Not correct Review References http://www.karbosguide.com/ http://upload.wikimedia.org/wikipedia/commons/thumb/b/b4/Asus_a8n_VMCSM02.jpg /645px-Asus_a8n_VMCSM02.jpg Fir0002/Flagstaffotos. Retrieved 22MAY2009. http://en.wikipedia.org/wiki/Operating_system. Wikipedia. Retrieved 23MAY2009. http://www.embeddedsys.com/. Visited 23MAY2009. Embedded Computers and Microcontrollers Microcontrollers ATtiny10 microcontroller, with 1K bytes of programmable Flash memory, and 32 bytes of internal SRAM http://media.digikey.com/photos/Atmel %20Photos/313-64-TQFP.jpg http://media.digikey.com/photos/Atmel %20Photos/453-64-TQFP.jpg Single-board computer http://www.electropages.com/articl eImages/large/12813.jpg http://www.oxisso.com/Microcontrollers/At mega128TinyBoard_Show.jpg Back http://www.embeddedsys.com/subpages/products/images/pdf/microsys_sbc1586_datasheet.pdf Power Supply ATX power supply MFG: ECHO-STAR P/N: ES-450-24 STYLE: ATX-20/24 Input: 110/220 VAC 50-60Hz Output #1: +3.3V @ 28A #2:+5V @ 34A #3: +5VDCSB @ 2A #4: +12V @ 14A #5: -12V @ .8A #6: -5V @ .5A (450W Max combined output) http://www.mpja.com/prodinfo.asp?number=16581+PS Back Motherboard Asus a8n VMCSM02 - Supports AMD Socket 939 Athlon 64FX / Athlon 64 X2 / Athlon 64 - NVIDIA GeForce 6150 + nForce 430 - Dual-channel DDR400 - PCI Express architecture - Integrated GeForce6 GPU - Dual VGA Ouput:DVI-D & RGB - NVIDIA Gigabit LAN with NVIDIA ActiveArmor Firewall - 4 x SATA II (RAID 0, RAID 1, RAID 0+1, RAID 5) - 1394a Support - High Definition Audio http://en.wikipedia.org/wiki/File:Asus_a8n_VMCSM02.jpg Fir0002/Flagstaffotos Back My Background Almost native SJ Willow Glen High School class of ’76 Education – first round UC Davis Industry experience – first round IBM GPD – 1982 - 1986 Stanford University 1986-1991 IBM SSD 1991 – 1993 3390 product engineering Spindle motor development Academia Non-contact rotor balancing Industry experience – second round 3390 actuator development Education – second round BSME – 1980 MEME – 1982 SJSU MAE – 1994 to pres. Personal Married 13-year old daughter Hobbies: build things, fix things, garden, read, hike, amateur radio (ARES) Most significant: relationship to God through Jesus Christ www.leaderu.com Faculty Offices (under Academics) Back Robot Programming Problem Write a program to make a robot follow a square course How do you go about the programming task? Method for Developing a Program Note: these steps are to be done BEFORE you write any program code! 1. Define the problem: State the problem you are trying to solve in clear and concise terms. 2. List the inputs and the outputs Inputs: information needed to solve the problem Outputs: what the algorithm will produce as a result 3. Describe the steps needed to convert or manipulate the inputs to produce the outputs (develop the algorithm) Begin at a high-level first Refine (subdivide the high-level) steps until they are effectively computable operations. 4. Test the algorithm: choose data sets, and verify that your algorithm works! Structured Programming Sequence Selection IF IF – ELSE SWITCH Repetition WHILE DO – WHILE FOR Flowchart constructs Algorithm What is an algorithm? A recipe A procedure Definition: “well-ordered collection of unambiguous and effectively computable operations, that when executed, produces a result and halts in a finite amount of time.” definition from: An Invitation to Computer Science (Gersting/Schneider) via http://www.cs.xu.edu/csci170/08f/sect01/Overheads/WhatIsAnAlgorithm.html (visited 19JUN2009) Characteristics of an Algorithm Well-ordered: Unambiguous: the steps are in a clear order the operations described are understood by a computing agent without further simplification Effectively computable: the computing agent can actually carry out the operation Pseudocode natural language-like statements that precisely describe the steps of an algorithm Statements that describe actions Focuses on the logic of the algorithm Avoids language-specific elements Written at a level so that code can be generated almost automatically from each statement Steps are numbered Subordinate numbers and/or indentation are used for dependent statements in selection and repetition structures Pseudocode example Note: English-like statements that describe the actions of the algorithm, and indented to show the logical structure of the algorithm. Flowcharts - 1 Flowcharts A graphical tool that diagrammatically depicts the steps and structure of an algorithm or program Symbol Name/Meaning Symbol Meaning Process – Any type of internal operation: data transformation, data movement, logic operation, etc. Connector – connects sections of the flowchart, so that the diagram can maintain a smooth, linear flow Input/Output – input or output of data Terminal – indicates start or end of the program or algorithm Decision – evaluates a condition or statement and branches depending on whether the evaluation is true or false Flow lines – arrows that indicate the direction of the progression of the program Flowchart Constructs - Sequence and Selection Control Structures from Deitel & Deitel, 6th ed., p. 122 Flowchart Constructs - Repetition from Deitel & Deitel, 6th ed., p. 122 Control Structures Example: D&D 3.15c - 1 “Obtain a series of positive numbers from the keyboard, and determine and display their sum. Assume that the user types the sentinel value -1 to indicate "end of data entry" Define the problem Statement pretty well defines the problem List inputs and outputs inputs: number entered from keyboard outputs: sum of number Example: D&D 3.15c - 1 “Obtain a series of positive numbers from the keyboard, and determine and display their sum. Assume that the user types the sentinel value -1 to indicate "end of data entry" Develop the algorithm High-level first, then refine: 1. Start 2. Declare variables: ________ 3. Repeat while number not equal to -1 3.1. get number 3.2. add to sum 4. Display sum Does this work? Example: D&D 3.15c - 2 Develop the algorithm, cont. Refine 1. Start 2. Declare variables: ________ 3. Repeat while number not equal to -1 3.1. get number 3.2. add to sum 4. Display sum 1. Start 2. Declare variables: num, sum 3. while num not equal to -1, continue doing: 3.1. Display prompt “Enter positive number” 3.2. Read number from the keyboard 3.3. Display number entered 3.4. add to sum 4. Display sum Are we there yet? Example: D&D 3.15c - 3 Develop the algorithm, cont. Add a test to exclude negative numbers 1. Start 2. Declare variables: num, sum 3. while num not equal to -1, continue doing: 3.1. Display prompt “Enter positive number” 3.2. Read number from the keyboard 3.3. Display number entered 3.4. if num less than zero, then 3.4.1 continue 3.5. add to sum 4. Display sum Are we there now? Flowchart Start Declare variables: num, sum Intialize variables: num = 0, sum = 0 1. Start 2. Declare variables: num, sum 3. while num not equal to -1, continue doing: 3.1. Display prompt “Enter positive number” 3.2. Read number from the keyboard 3.3. Display number entered 3.4. if num less than zero, then 3.4.1 continue 3.5. add to sum 4. Display sum if num ! = -1 No Display sum Yes Display "Enter positive integer" Read num from keyboard Display num Stop Test the algorithm! if num < 0 No sum = sum + num Yes Structure of a C Program A formal letter has a structure So does a program in C Burford Furman Title Professor Dept. of Mech. and Aero. Eng San José State University San Jose, CA 95192-0087 block July 20, 2009 Date Dear Prof. Furman, Salutation I’m writing you to see if I can get into ME 30… … Body Sincerely, Closing Jane Student Signature C Code for D&D 3.15c Programmer’s block Pre-processor directive Main function (statements go between { } ) Declare and initialize variables While loop (repetition structure) return statement Programmer’s Block Include important information (comments) to document the program: Title Date Author Description Inputs/Outputs Algorithm Revision history Add comments using one of two methods: 1. /* put comment between */ (note: traditional C) 2. // comment (note: single line only) Full program # include (pre-processor directive) Includes a library file for ‘standard io’ functions for things like printing, etc. Full program main() function Your program needs a main() function Statements go between the braces { } main() ends with the return keyword and usually the value zero If main() runs successfully, it returns a value of zero Full program Declare and initialize variables Variables must be declared before you can use them Full program while() Repetition Structure while (condition) repeat statements between { } Full program