Software for Absolute Beginners
What is Software?
Before we talk about the type of things robot software involves, let’s talk about software in general. You use software everyday when you log onto a computer, listen to a song on your mP3 player or read a book on a tablet. Software, or computer programs, refers to instructions stored in memory that are processed by a computer. Chain enough simple instructions together and complex creations such as games and robots become possible. Let’s look at a few types of instructions that are useful when creating software.
Basic Math Instructions
Computer processors include electrical circuits to perform very fast math operations such as addition, subtraction, multiplication and division. Being able to do simple math becomes very powerful when you can do millions or billions of calculations per second. Suddenly you can calculate trajectories, process images and other useful things. For our discussion we will assume the math symbols we are familiar with (+, -, * and /) and the accepted order of operations.
1 + 2 is an example of a math instruction
Comparison instructions allow the relationship of two numbers to be determined. For example we can calculate which number is large, which number is smaller and which numbers are equal. Comparisons form a mathematical statement that is either true or false. Statements that are true comply with our convention or agreement on how numbers work. “1 is less than 3”, this is a true statement because it agrees with what we know the number 1 and 3 to mean. “4 is greater than 5”, this is a false statement because it conflicts with what we have agreed 4 and 5 to mean. In the order of operations, comparisons are evaluated after math instructions. In our examples we will use the symbols <, >, == to mean less than, greater than and equals, respectively.
1 < 2 is a comparison that evaluates to true
1 == 2 is a comparison that evaluates to false
Assignment instructions allow your software to keep the result of a calculation or comparison for use later in the program. We’ll use the equals sign (=) from math to symbolize assignment. Assignment happens after all calculations have been perform and comparisons evaluated.
answer = 1 + 2 is an example of assigning the result of 1 + 2 to a variable named answer. If a calculation accesses the variable, the last value assigned to the variable will be used.
Memory Access Instructions
Memory uses electricity to store numerical information that can be retrieved at a later time. Some memory can continue to store information without electricity and other memory requires electricity to retain information. Instructions that read and write memory allow information to used after a piece of software has run. Different pieces of hardware, such as sensors, can put information into memory that software can then read in when it executes. With this arrangement calculations can be run on information from the outside world. Our examples will only talk about memory in an abstract sense.
Conditional instructions allow computers to make decisions and perform different instructions based on the outcome of the decision. The simplest form of decision we will discuss is an if-else statement. If a condition is true, one set of instructions will be executed. Otherwise a different set of instructions will occur. We say
Do some instructions
Do some other instructions
Looping instructions allow operations to repeated until a condition is satisfied. This means that a few instructions can be entered put in a piece of software but repeated thousands or millions of time. Our examples will use a while statement. While performs instruction while a condition remains true.
Do some instructions
Simple Software Examples
Let’s use a few of the instructions we have mentioned to write some simple software. For simplicity we will assume our programs begin executing at the top and stop executing at the bottom.
Friday if-else example
Let’s do one thing if it is Friday and another on other days
if(today == friday)
Fun, fun, fun, fun, looking forward to the weekend
Cook some meat
Consider a robot that cooks meat. You ordered well done, so the meat needs to be cooked until it is fully cooked. Once it is cooked the food should be served.
while(food < well done)