0% found this document useful (0 votes)
1 views

Unit3_introduction to Programming

The document is an introduction to programming within the context of robotics for a Digital Business degree course. It covers fundamental concepts such as the definition of programming, machine code, programming languages, and the use of Integrated Development Environments (IDEs) for writing and debugging code. Additionally, it explains how to obtain information from computers using the console and demonstrates basic arithmetic operations.

Uploaded by

moniserranita04
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
1 views

Unit3_introduction to Programming

The document is an introduction to programming within the context of robotics for a Digital Business degree course. It covers fundamental concepts such as the definition of programming, machine code, programming languages, and the use of Integrated Development Environments (IDEs) for writing and debugging code. Additionally, it explains how to obtain information from computers using the console and demonstrates basic arithmetic operations.

Uploaded by

moniserranita04
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 24

ROBOTICS & PROGRAMMING

2ND year DEGREE IN DIGITAL BUSINESS (DDB)


Academic year 2022/23
Instructor: María Flores

ROBOTICS
1
UNIT 3 – INTRODUCTION TO PROGRAMMING

ROBOTICS
I. CONTENT
3.1. Introduction to programming
3.2. How do we write code?
3.3. How do we get information from computers?
3.4. What can computers do?

Bibliography

ROBOTICS
3.1. Introduction to programmimg

PROGRAMMING (DICTIONARY)
The dictionary defines it as the process of preparing an instructional program for a device ( but that’s a really confusing definition)

PROGRAMMING
It is attempting to get a computer to complete a specific task without making mistakes.

ROBOTICS
3.1. Introduction to programmimg
PROGRAMMING
You want your friend to build a lego set, except he has lost the instructions and can only build based on your command.

If they are not given very specific instructions, there are many mistake he/she could make.

If he thinks like a computer, then if there is even one piece that you have not told him specifically where to place,
the entire lego set will be ruined and he will be left to suffer acomplete mental breakdown.

ROBOTICS
3.1. Introduction to programmimg
PROGRAMMING

Giving instructions to your friend is very similar to how programmers code. Instead a friend, you have a computer, and instead of
instructions, we are feeding it information on how to complete a program

Now, programming isn’t as simple as giving your friend instructions since in a programmers case, the computer doesn’t speak
the same language as you, the computer only understands machine code

ROBOTICS
3.1. Introduction to programmimg
PROGRAMMING – THE MACHINE CODE

The machine code is a numerical language known as binary, that is designed so that the computer can quickly read it and carry out
its instructions.
Every instruction fed to the computer is converted into a string of 1’s and 0’s and then interpreted by the computer to carry out a
task.

ROBOTICS
3.1. Introduction to programmimg
PROGRAMMING – THE MACHINE CODE

Directly translating what you want the computer o do into machine code is extremely difficult. almost impossible
Each program is composed of millions upon millions of those 1’s and 0’s,

How are we supposed to translate our instructions into machine code?

ROBOTICS
3.1. Introduction to programmimg
PROGRAMMING – THE MACHINE CODE

ACTIVITY – Write your name in ASCII and binary code

27 26 25 24 23 22 21 20

128 64 32 16 8 4 2 1

M 76 0 1 0 0 1 1 0 0

A 65 0 1 0 0 0 0 0 1
R 82 0 1 0 1 0 0 0 0
Í 73 0 1 0 0 1 0 0 1
A 65 0 1 0 0 1 1 0 0

ASCII BINARIO

ROBOTICS
3.1. Introduction to programmimg
PROGRAMMING – PROGRAMMING LANGUAGES

Programming languages are for translating a program into machine code.


These languages are much easier for humans to learn than machine code, and are thus very useful for programmers

ROBOTICS
3.1. Introduction to programmimg
PROGRAMMING – PROGRAMMING LANGUAGES

There are many different programming languages that each have their own unique uses.

Languages such as Python and Java act as general purpose languages that can perform a variety of computational tasks.

Robot C or HTML/CSS are languages designed for more specific purposes such as moving a robot or constructing a website.
Languages can also vary in how powerful they are.

o Java Script is a scripting language that is designed for smaller tasks while java
o Python can carry out much more computationally taxing processes

ROBOTICS
3.2. How do we write code?
Integrated Development Environment – IDE´s

It’s not like simply type words into a text document and automatically assume that the computer can translate it into machine
code, read it, and carry out a task like opening up a browser.

The answer is with an IDE. An IDE, which stands for Integrated Development Environment, allows the facilitation of code by a
computer.

IDE’s provide a graphic interface on your computer in which the programmer can easily write, run, and debug code

ROBOTICS
3.2. How do we write code?
Integrated Development Environment – An example of an IDE´s

In the center you can see the program that is currently being written, and right below it the console, which can print out useful
information for the programmer.

ROBOTICS
3.2. How do we write code?
How do we write code? Learning leanguages
• How do we write this code in the IDE?. This is where a programming language’s syntax comes into play.
• Programming languages have a set of rules that you must follow when writing code and at the fore front of those rules is grammar.
• Programming grammar is referred to as syntax and is very similar to real-world grammar.
• Each programming language has its own syntax, or rules, that you have to follow.
• Breaking programming rules Will be result in an error

ROBOTICS
3.2. How do we write code?
How do we write code? Syntax matters

• All these languages require that you follow this syntax because if you forget one semicolon or misplace a character, the entire
program will not run and send you back a syntax error.

“let’s eat, grandma”

“let’s eat grandma¡¡¡”

ROBOTICS
3.2. How do we write code?
How do we write code? Built-it error checks

• Another thing which makes IDE’s so useful is that they will let you know if and when there are syntax errors in your code.
• The IDE will tell you where in your code the error is, and also won’t let you run your program until the error has been fixed.

Int variable=3;

ROBOTICS
3.3. How do we get information from computers?
The console
• Now that we know HOW to write code, and WHERE to write code, we next need to cover what happens after we have typed
out our program and run our code.
• How will we know what’s happening, and whether it is working or not? Well, programmers do this by looking at the console.

The console is a text interface


within the computer that the
programmers can use for a
variety of purposes
ROBOTICS
3.3. How do we get information from computers?
How to use the console
• The main use of the console is to output text from the program.

• This is usually done using a print statement, that is a command that prints text to the console.

• This print statement is the first piece of ACTUAL CODE, and it’s one of the most important functions in programming and exists
in some form in just about every programming language.

The place where you print


(to write code)¡¡

ROBOTICS
3.3. How do we get information from computers?
USING THE PRINT STATEMENT
• In python the segment of code print (“Hello World”) will cause a message reading “Hello World” to appear onto the console.
Pretty neat.

THE CONSOLE

print (“Hello World”) Hello World

ROBOTICS
3.3. How do we get information from computers?
USING THE PRINT STATEMENT
• If you tell a computer to run a simple calculation, 4+3, it will run the program internally and compute an answer.

4+3

THE CONSOLE

what is the purpose of having the computer run this program if you will not be able to tell what the result is???
Instead of telling the computer to perform this calculation, instruct the computer to print the output of the program to the console

print (4+3) 7

ROBOTICS THE CONSOLE


3.4. What can computers do?
MATH
• The computer already knows how to do simple arithmetic (addition, subtraction, multiplication, and division).
• In any IDE that you may install, you’ll be able to print out the answer to simple math problems using the print statement.

+ -  /

• For example, if we wanted to build a basic calculator app,


we’d need to utilize this functionality in order to display
the answer to an arithmetic problem

ROBOTICS
3.4. What can computers do?
MODULUS
• Most programming languages include an additional operator known as modulus.
• Modulus allows us to get the remainder of a divisional operation.
%

print (10 % 3) 1

THE CONSOLE

print (50 % 2) 0

THE CONSOLE
ROBOTICS
3.4. What can computers do?
MODULUS
• This can be extremely useful if we want to determine whether or not a certain integer is even or odd.
o If a number modulus 2 is 0 the number is even
o If a number modulus 2 is 1 the number is odd

ROBOTICS
3.4. What can computers do?
MODULUS
• This can be extremely useful if we want to determine whether or not a certain integer is even or odd.
o If a number modulus 2 is 0 the number is even
o If a number modulus 2 is 1 the number is odd

ROBOTICS

You might also like