1 / 30

Intro to Programming

RoboRebels. Intro to Programming. Topics. Hardware and Machine Code The Building Blocks of Programs Program Design Object Oriented Programming Our Robot. Hardware. The two most important hardware components to a programmer are: The CPU RAM. The CPU.

edith
Download Presentation

Intro to Programming

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. RoboRebels Intro to Programming

  2. Topics • Hardware and Machine Code • The Building Blocks of Programs • Program Design • Object Oriented Programming • Our Robot

  3. Hardware • The two most important hardware components to a programmer are: • The CPU • RAM

  4. The CPU • The Central Processing Unit is the ‘brain’ of a computer. It is responsible for executing programs. • While a program is running, it uses a processor Thread.

  5. RAM • Random Access Memory gives a computer a place to store information quickly and temporarily. • Programs are stored in RAM they are running, and can use it to store information. • RAM is not long term storage.

  6. What is a Program? • A program is a list of instructions to tell a computer what to do. • The most basic form of computer instructions is called machine code. Machine code is very difficult for a human to read and understand. • For example: add eax, VariableX adds two numbers together • Programming in machine language is tedious and error prone. Programming today is usually done in a variety of high level programming languages

  7. High-Level Programming Languages • Most programs today are written in high-level programming languages, such as Java or C++ • Since these high-level programs’ purpose is to allow the programmer to understand and write programs more quickly, they cannot be understood directly by a computer. • In order to be executed, high-level code needs to be compiled into machine code. A compiler performs this translation.

  8. Java • Java code is compiled into bytecode, which can be interpreted and run by the JVM, or Java Virtual Machine, which allows programs written in Java to be completely platform-independent.

  9. The Building Blocks of Programs • Data and Instructions are the two basic components of a program.

  10. Data • Programs store data in variables. These variables are memory locations that can be accessed and modified. • Since a variable might need to represent several different types of information, several can be used: • Boolean (true/false) • Integers ( 42, 0 -1) • Floating Point (3.14, 0.0, -2.1) • Characters (‘h’, ‘z’ ‘5’, ‘<‘) • Strings (A group of characters): “Hello Programming”

  11. Variables • In computer programs data lives in memory • In order to access this data you must know specific location of the data (this is called an address) • It’s much easier to use a variable, which is named by you, than a computer memory address • Example:int Length = 24; float PI = 3.14; char MiddleInitial = ‘M’; string FirstName = “Derek”;

  12. Instructions • A program runs a sequence of instructions from the top down. • Control Structures are instructions that alter how the program executes certain commands. • Arithmetic instructions • Add, subtract, multiply and divide (+, -, *, /)

  13. Instruction Examples • int Area = 0, Length = 2, Width = 5; Area = Length * Width;Advanced users: Look up “Order of Operations in Programming”http://en.wikipedia.org/wiki/Order_of_operations#Programming_languages

  14. Control Structures • All control structures affect program flow • Branches – test a condition to decide between two or more courses of action. • Conditions evaluate either true or false • for example, a condition that tests if 5 is equal to 5 would evaluate to true. • Loops – repeat a group of instructions. • Subroutines (Functions) – Allow you to “jump” to a group of instructions, perform them and then “jump” back to where you were.

  15. Branches • Branches help us when we need to perform a group of instructions in one situation and another group of instructions in different situation • Example:If my gas tank is almost empty Then fill it up with gasOtherwise Keep driving • Example 2:If my car is red Then touch up with red paintIf my car is black Then touch up with black paint

  16. Loops • Loops perform a group of instructions repeatedly and will only stop when certain condition is met. • This helps with programming because you do not need to repeatedly write out instructions over and over. • Also, what if you don’t know when the loop should end when you are writing the program? • Example: For as long as I own my current car do the following Fill gas tank when it is near empty Change oil every 4000 miles Perform other maintenance when needed

  17. Nesting Loops and Branches • Our programs would be very limited if we couldn’t combine loops and branches with other loops and/or branches • Example:For each year that I have my car For every four months Get your wheels aligned

  18. Subroutines • When programs get larger and more complex it gets harder and harder manage code • One way to manage this complexity is to break the program down into “chunks”, these are called Subroutines, Functions or Methods • Subroutines allow you to reuse functionality in your programs

  19. Subroutine Example

  20. Code Reuse • Why would we want to create subroutines to foster the reuse of code? Programmers are LAZY!

  21. Code Reuse • Saves time • Less potential for error • Easier to find errors and test • Using subroutines or the idea of breaking code into chunks helps to simplify the process of programming a robot.

  22. Design • Software can become very complicated. Design is very important to the creation of a successful program. • Programmers must analyze the problem to be solved and design a program to solve it. Several concepts and tools become very useful in this process. • Top-down and bottom-up • Encapsulation • Object Oriented Programming

  23. Top-Down and Bottom-Up • A top-down approach to solving a problem starts with a general solution and breaks it down into small, easily solvable parts. • The bottom-up approach begins with solving the easiest problems, and works up to the complete solution. • In reality, a combination of these approaches is utilized.

  24. Encapsulation • Encapsulation refers to the reusability of a piece of a program. Ideally, a component should be “modular”. Modules interact with the rest of the program in a simple and straightforward manner. • How an encapsulated module works is not important to the whole program, as long as it works correctly. This is called information hiding.

  25. Object Oriented Programming • Object Oriented Programming, or OOP, focuses on encapsulation. • An object acts as a module that contains its own data and subroutines. • OOP begins with identifying the objects involved in the problem. • An OOP program uses a collection of objects that can interact with each other. • Object oriented programming is a very effective tool used in the structure and design of a program.

  26. Objects • Why use the concept of objects? • Easily model real-world objects • Reusable blocks of code and data • Easily test out concepts • Create complex concepts with object relationships • Object Data (Members) • Think of it as adjectives for objects • Example: Color, temperature, position • Object Actions (Methods) • Think of it as verbs for objects • Example: Move, kick, extend

  27. “has-a” Relationship • Not only can objects have Members and Methods, but they can contain other objects • The “has-a” relationship is defined as an object containing another object • Example: • We have a Robot object • This Robot object has 4 motor objects

  28. “is-a” Relationship • In OOP there is a concept called inheritance. This is where you can derive a new object from another object • This is best shown with an example • Example: • We have an object called SpeedController • Our robot uses two different types of speed controllers • Victor • Jaguar • So, we can create two new objects from the SpeedController object which contains the functionality of a SpeedController, but has special Members and/or Methods which are only necessary for a Victor or a Jaguar

  29. The Robot and OOP • Think of a robot just as you would a human. You can divide a human into 3 distinct parts:

  30. Our Robot • The robot that this club creates will need to perform certain tasks. The very basic requirements of the robot are: • Controlling actuators and motors • Receiving input data from sensors • Mapping the robot’s actions to joystick controls • Knowing what to do on its own (autonomous mode)

More Related