Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Aerospace Programming Fundamentals for Aerospace Engineers

  1. Dec 19, 2008 #1
    The point of this thread is to provide some basic information about computers and how they work. In the modern age of engineering, one will invariable have to write code and work with computers. As such, it's important to know some of the basic operations and blocks utilized. I was cleaning out my shelf when I found these old notes from an intro to computing class I took in C back in undergrad. Hopefully, they give some help and context to beginning undergraduates. :smile:

    1.1 How to begin your program?

    • the logical flow of instructions
    • the mathematical procedures
    • the appearance on the screen
    • the way information is presented to the user
    • the programs "user-friendliness"
    • manuals and other forms of written documentation

    The last point can't be emphasized enough. There will be times you write a code and will have to go back and reuse or modify it. It is critically important to comment your code so you (or others) can go back and read what you've done. There are times I have had to go back and relook over some code and figure out what I did. Were it not for the comments, it would have taken much more time.


    ****You should get in the habit us using these words and terms in your vernacular when you talk about your programs. It's good habit in engineering, and in life, to use precise wording so there is as little vagary in what your describing as possible.
     
    Last edited: Dec 19, 2008
  2. jcsd
  3. Dec 19, 2008 #2
    1.2 Computer Systems: Hardware and Software

    The hardware in a computer consists of (but is not limited to):

    1. Central Processing Unit (CPU)
    2. Main Memory
    3. Secondary Storage Devices
    4. Input Devices
    5. Output Devices

    The CPU follows the fetch, decode and execute cycle.

    Fetch: CPU's control unit fetches, from main memory, the next instruction in the sequence of instructions.

    Decode: The instructions are encoded in the form of numbers. The controls unit decodes the instructions and generates an electrical signal.

    Execute: The signal is routed to the appropriate component of the computer (Such as an ALU [Arithmetic and Logic Unit], disk drive, or some other device). The signal causes the device to perform an operation.
    __________________________________________________________________

    Terms:

    Main Memory

    Random Access Memory (RAM). Here, information is stored in an address. The address is ordered from lowest to highest.

    *Ram is a volatile form of memory that gets erased when the computer is turned off!

    Secondary Storage

    This type of memory can hold data for a long period of time, even when there is no power.

    Input Devices

    Any information the computer collects from the outside world

    Output Devices

    Information the computer sends to the outside world.

    Software

    There are two types of software, operating systems and application software.

    Operating Systems: There are single tasking and multi-tasking type systems. A single tasking system runs one user program at a time. A multi-tasking program allows multiple programs to be run at once, through a technique called time sharing.

    Furthermore, there is the option of single user and multi-user systems, which allow one or many people to access the computer, respectively.

    Time sharing is an important concept because if you are designing something that will go inside an airplane, there is a finite amount of instructions that can be sent to the on board flight computer. The flight computer will sample the outputs of the sensors on board the aircraft, look at a set of instructions, compare the desired values to the actual sensor values at that sampled point in time, and then perform the required tasks. All this happens in small time sharing blocks. So the computer might look at ailerons, elevators, throttle, cabin pressure, cabin temperature, etc etc etc in some set order. The response to the throttle will have to wait until the ailerons and elevators have first done their thing. Then the loop repeats itself at the next sampling interval of the computer. From a design perspective, you will be given a maximum allowable time delay your code will have to be able to deal with and still work. From a controls perspective, this is in the form (usually) of a time delay in the Laplace domain of [tex] e^{s\tau}[/tex], where [tex]\tau[/tex] is the time delay, found from the Phase Margin of the Nyquist or Bode Diagrams. (Don't worry about this if you haven’t had controls yet.)
     
    Last edited: Dec 19, 2008
  4. Dec 19, 2008 #3
    1.3 Programming and Programming Languages

    An algorithm is a set of well defined steps for performing a task or solving a problem.

    Low level machine language is a set of 1's and 0's (binary). High level machine language is letters, words, and numbers. A text editor saves the code in words.

    Statements written by the programmer are called source code. And the file is the source file.

    A preprocessor reads the source code and looks for special lines that begin with the # symbol (for C,C++ language).

    The complier translates the code into machine language (1's & 0's).

    Syntax is the form in which one writes the code. When there are no syntax errors, the complier stores the translated code as an object code in an object file.

    After a file is made into an object code, it is liked and becomes an executable program. Typically a ****.exe file.
     
    Last edited: Dec 19, 2008
  5. Dec 19, 2008 #4
    1.4 What is a Program made of?

    A program is made of:

    Key words: Words that have special meaning

    Programmer-Defined Symbols: words or names defined by the program

    Operators: Perform operations on one or more operands.

    Punctuation: characters that mark the or ending of a statement, or separate items in a list.

    Syntax: rules that must be followed when constructing a program.
     
  6. Dec 19, 2008 #5
    1.5 The Programming Process

    Steps to making a program:

    1. Clearly define what the problem is to do
    2. visualize the program running on the computer
    3. design a hierarchy chart and/or flow chart
    4. check the hierarchy chart for logical error
    5. write a pseudocode version of the program
    6. check the pseduocode for errors
    7. write the program on paper
    8. desk-check the program for errors
    9. enter the code and compile it
    10. correct any errors found
    11. run the program with test data
    12. correct any errors found when running the program

    Usually, number 9 is hardly ever done anymore. However, number 11 is critically important. After writting your code check the results with known analytic solutions to verify there are no syntax errors!

    Hierarchy, or top-down, design starts from the top "overall" problem and channels down to specific tasks.

    Flowcharting: The following symbols are used in flowcharts. You can find these symbols in MSOFFICE in the top menu bar. Now when you use them, you know the meaning behind them (yes, they actually mean something. There not just random squares and circles!)

    [​IMG]

    [​IMG]

    [​IMG]

    [​IMG]

    [​IMG]

    [​IMG]

    [​IMG]

    [​IMG]


    In general, there are four flowchart structures:
    1. sequence
    2. decision
    3. repitition
    4. case
     
  7. Dec 19, 2008 #6
    1.6 Integer Data Types

    • integers are whole numbers
    • floating point numbers have decimals
    • unassigned data types: hold positive numbers.

    Usually, you can also force one data type into another. For example, in matlab you can change from a format long to a format short to change the precision, or number of decimal places matlab uses to gain computational speed, but loose in accuracy.

    CAREFUL! Know exactly how the language you are using defines it's data types!

    See:

    Matlab

    Mathematica

    C++
     
  8. Dec 19, 2008 #7
    2.7 The Char Data Type

    Char is used to store a character. Strings (a series of characters) are usually stored with a null at the end. This is used so that the computer knows the string has reached its terminal point and continue performing computations.
     
  9. Dec 19, 2008 #8
    2.8 Floating Point Data Types

    [tex]\overbrace{4.728197}^{mantissa} \underbrace{x10^7}_{power}[/tex]

    Computers typically don't use the [tex]x10^7[/tex] notation. Instead, they use (e). In matlab, you can write 12,000 as 12e3, for example, and get the same result. It will also return results with the (e) notation.
     
  10. Dec 19, 2008 #9
    2.11 Focus on Software Engineering: variable assignments and initialization

    = is called an assign operator

    initialization is assigning values to variables as you declare them. For example,

    a = 12;

    declares the variable a, and assigns it the value 12.
     
  11. Dec 19, 2008 #10
    2.12 Focus on Software Engineering: Scope

    The scope of a variable is the part of the program where the variable may be used. For example, if I have a main program and define some variables in my main program as global, then it means these variables can be used anywhere else. Even if my program calls other programs inside of it, these other programs have access to the global variables in addition to any variables they normally take in.

    Remember, a function is exactly like that in mathematics.

    [​IMG]
    (Notice a function is typically called a 'black box'. Input arguments go into this black box, and outputs are returned. In fact this relationship is one-to-one. You can ONLY get one output for a distinct input.

    The function takes in a set of values or characters, performs an operation, and returns some outputs. So a function always has access to the values of the input variables. In the case of defining global variables, it can also use these global variables inside of it even though it does not normally take in these values.


    A static variable
    is one that gets erased after the function is done using it.
     
    Last edited: Dec 19, 2008
  12. Dec 19, 2008 #11
    2.13 Arithmetic Operators

    + addition
    - subtractio
    * multiplication
    / division
    % modulus (or the remainder) This is for C++ only! Check your program for exact syntax!

    CAREFUL! The order in which you write this will ALWAYS BE:

    • Parentheses
    • Exponents
    • Multiplication
    • Division
    • Addition
    • Subtraction

    For example:

    3+6/3 = 5
    (3+6)/3 = 3
     
  13. Dec 19, 2008 #12
    2.14 Comments

    USE THESE! Write them so you know whats going on in your code!

    In C style, the // or /*..........*/ are used for comments.

    In Matlab, it's % symbol.

    *see your computing langauge for the exact synatx.
     
  14. Dec 19, 2008 #13
    3.3 When you mix apples and Oranges: Type Conversion

    When you an operator on variables with two different data types, the lower ranking value is promoted to higher ranking type. The rank, in order of importance is:

    • Long Double
    • Double
    • float
    • unsigned long
    • long
    • unsigned int
    • int
     
  15. Dec 19, 2008 #14
    3.4 Overflow and Underflow

    Underflow or overflow will cause numbers to wrap around to the next value. I.e., the int data type can hold -32,767 to +32,767. Adding 1 to 32,767 will give you -32,767 NOT 32,768.

    This rule will change on the programming language you use. The above statement holds for C.
     
  16. Dec 19, 2008 #15
    4.1 Relational Operators

    > Greater than
    < Less than
    >= Greater than or equal to
    <= Less than or equal to
    == Equal to
    != Not equal to

    These are called relative expressions.

    True statements are stored as 1.
    False statements are stored as 0.
     
  17. Dec 19, 2008 #16
    4.4 The IF statement

    if(expression1)

    Computations go here

    elseif(expression1)
    .
    .
    .

    elseif(expressionN)

    else

    end

    If expression1 = 1 (i.e is true) then the statement performs the Computations, otherwise if will test expression2 to see if its true, moving all the way down to expressionN, where N is any number of these else if 'clauses' you want to include. If none of these are satisfied, it goes to the else statement.
     
  18. Dec 19, 2008 #17
    4.10 Logical Operators

    & -and operator
    || - or operator
    ! - not operator (sometimes ~ can be used)
     
  19. Dec 19, 2008 #18
    5.2 The While Loop

    The while loop, given below:

    while (expression)

    Computation

    end

    Will do the computation, over and over again, so long as the expression inside the while loop is true. Be careful, this can lead to whats known as an endless loop that will cause the program to 'hang up' or freeze once it gets inside this condition!
     
  20. Dec 19, 2008 #19
    END

    This concludes this basic infosession. I encourage you to find out more about the programming language you're using from the company website.

    I prefer to use MATLAB:

    www.mathworks.com

    which has a very nice section called the 'user community' if you need help, analagous to the physics forums.

    More basic programming can be found here:
    http://www.cyberciti.biz/howto/cookbook/

    The book I used, and got these notes from (but no longer have the book) is:
    [1] Starting Out with C++: From Control Structures Through Objects, Tony Gaddis

    Another one is:
    [2]The Indispensable Guide to C: Paul Davies

    END​
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Have something to add?



Similar Discussions: Programming Fundamentals for Aerospace Engineers
  1. Aerospace Engineering (Replies: 3)

Loading...