Understanding Robotics With Python

Shiv Last Updated : 18 Mar, 2021
6 min read
This article was published as a part of the Data Science Blogathon.

Introduction

Robotics- the futuristic field of work in which machines can be mistaken for a man. Robotics is, and will for a very long time be, one of the most life-changing fields of information technology. The field of Robotics is thought to be one that will have the most severe impact on humans in the long run. The only uncertainty lingering in the air is whether this impact will bring a positive change to the world or inevitable regret. In the modern-day, there are more than five hundred programming languages that exist, however, when it comes to Robotics, there are only a few that possess the computational power.

The best programming languages that are used in present times are (these may be subject to change) Python, C++, and Java. This article will speak about using Python for Robotics in the fourth industrial revolution.

Will COVID-19 Accelerate Robotics in the Supply Chain? – IoT World Today

Source: IoT World Today

Overview- What is Python?

Python is a popular, high-level programming language that can be used for scripting the creation and development of applications for Computer Desktops, the World Wide Web, Machine Learning, Data Science, and much more. The father of Python is Guido Van Rossum. Python is a
versatile language and is used by many organizations and platforms worldwide.

Examples of Companies and Corporations that utilize Python include, but are not limited to, Google, Netflix, Instagram, Facebook.

 

Robotics And The Core Disciplines.

In simple terms, Robotics is a specialized study that involves the combination of techniques of science, engineering, electronics, and art. The impact of Robotics is becoming increasingly larger as more companies try to gain a competitive advantage in the workplace. The fields that makeup Robotics are referred to as the “Core Disciplines”. Robotics is said to be made up of four (4) main Disciplines. These are Electrical Engineering, Mechanical Engineering, Computer Science and Arts. Let us have a short discussion about each Core Discipline. It is crucial to know that to be involved in the Robotics field, one does not need to be an expert in all Core Disciplines- a basic understanding of Arts and Electrical Engineering will be sufficient.

1. Electrical Engineering: Electrical Engineering is the specialized study of active electronic circuits such as refrigerators, transistors, and so on along with other relevant electric interconnections. Electric Interconnections may refer to circuits, breadboards, Arduinos, and any electrical connection that when brought together form a functioning system. It is interesting to know that there is a difference between electrical systems and electronics.

You see, electrical systems utilize electrical current or electricity to power an output device such as a bulb or buzzer. Now, with electronics, the functionality of these electrical systems gets pushed one step further. That being said, with electronics, we may be allowed to alter the flow of current that the bulb receives hence granting us the ability to “dim” or “brighten” the bulb.

 

2. Mechanical Engineering: The Discipline of Mechanical Engineering at its’ most complex will combine knowledge of Physical Sciences (Physics), Mathematics, Material Science, and Designing. Mechanical Engineering focuses on taking the design plans of an object and turning it into a real product. Mechanical Engineering when combined with Electronics is referred to as “Mechatronics”. The main aim of Mechatronics is to make an operating system much more sophisticated and streamlined by integrating Artificial Intelligence into it.

 

3. Computer Science: Going by what we have discussed up to this point, we will be able to create a robot that has a physical form- however, the robot will not be functional. This is primarily because our robot is in a “static” form- It will remain so until an internal instruction is received. The Discipline of Computer Science is what provides each part of the robot with the instructions to perform a certain task. The instructions will have to be integrated into a microcontroller through programming.

 

4. Arts: Every object is attractive in its own way- and Robots must be no different if they are to live amongst human beings in the future. This Discipline focuses solely on creating an aesthetically pleasing Robot. The Robot needs to blend into the environment, and it needs to be entertaining. A Robot should not cease to attract an audience of few beings.

 

The Brain Of A Robot

The brain of a robot is what controls it. Robots may be controlled externally such as through a joystick or controller and are referred to as “Brainless Robots”. On the contrary, some robots may be controlled from within, using a microcontroller which is the hub of all activity.

A Microcontroller is like a Central Processing Unit in the sense that it also is responsible for monitoring and controlling all machine activity; and it differs in size, price, and processing power. Microcontrollers however are built to cater to lower-level hardware. When you are selecting a microcontroller for purchase, it is recommended you choose one that contains an internal flash or has EEPROM (Electrically Erasable Programmable Read-Only Memory). To maximize your knowledge of the Microcontroller, one must also identify which architecture it is based on- It may be based on the Von Neumann Architecture or the Harvard Architecture.

Microcontroller Wallpapers on WallpaperDog

Source: Cool Wallpapers- WallpaperDog

Understanding The Raspberry Pi

The Raspberry Pi is a small computer about the size of a bank card. This portable computer runs on a Raspbian build on top of a Linux operating system- It is interesting to know that “Raspbian” is a special version of the Linux operating system which was designed specifically for the Raspberry Pi. The Raspberry Pi is built on top of the Broadcom processor. There are several types or variants of the Broadcom processor that is available for purchase such as BCM2835, BCM2836, BCM2837, and so on. A Broadcom processor may be referred to as a “System-on-a-chip Processor”. One will find that from one generation to another, the specs will vary such as the number of ARM Processors onboard, the graphics card, the instruction set the chip follows, and much more.

The main aspect of the Raspberry Pi that will enable us to indulge in the field of Robotics, are the GPIO Pins that are located on the raspberry pi. GPIO stands for General Purpose Input Output Pins. These GPIO pins serve as the means for us to integrate components with the Raspberry Pi. In total, there are 40 (forty) General Purpose Input Output Pins, and all have different functionalities. A short explanation of the general purpose of these pins is as follows:

  • The red pins are used as power pins- these will power up any component or device to which a connection is made. The power from these pins comes directly from the Raspberry Pi itself.
  • The black pins possess the same functionality as that of the red pins, i.e., power pins.
  • The pink pins serve as serial peripheral pins. These pins may be utilized to connect the raspberry pi to external microcontrollers such as an Arduino.
  • The blue pins allow us to have multiple slave devices connected to the Raspberry Pi, hence establishing larger connections and communications.
  • The green pins are responsible for carrying out the instructions of the Raspberry Pi.

As we conclude this article, I shall now show you and discuss a short Python script that has the potential to blink an LED light on and off, ensuring that the bulb is connected to GPIO pins on the Raspberry Pi.

# First we will need to make sure that the Python Library is installed on our
# Raspberry Pi. We will also need to make sure that we have a secure Internet
# Connection established

$ sudo apt-get install python-rpi.gpio python3-rpi.gpio
# We begin by importing the necessary packages
# First we import the Raspberry Pu GPIO Package
# Thereafter we import the sleep method from the time package

import RPi.GPIO as GPIO
from time import sleep
# We configure our system and script to temporarily
ignore all warnings
GPIO.setwarnings(False)
# We configure the pins on our Raspberry Pi, hence utilizing the physical
# GPIO pin numbering

GPIO.setmode(GPIO.BOARD)
# We are using pin number 8 and we are setting it to be the output pin
# the initial current level in this pin is low

GPIO.setup(8, GPIO.OUT, initial=GPIO.LOW)
# Now, in order to blink a bulb, we will need to allow current to pass
# Temporarily and thereafter cut all current flow. This is done as follows
# The use of a while loop tells us that our program will run forever

while True:
# Step 1: Turn on the LED bulb
 GPIO.output(8, GPIO.HIGH) # We set output pin number 8 to high current

sleep(1.5) # We stop all activity for 1.5 seconds

# Step 2: Turn off the LED bulb
 GPIO.output(8, GPIO.LOW) # We set output pin number 8 to a low current
 sleep(1.5) # We stop all activity for 1.5 seconds
# Therefore through the constant running of this script, we will see the 
# LED bulb on the Raspberry Pi turning on and off itself, thereby blinking

This article provided on an Introduction to Robotics- There are several more concepts which I highly recommend one to read about. This concludes my article on “Understanding Robotics – With Python”.

Thank you for your time.

The media shown in this article are not owned by Analytics Vidhya and is used at the Author’s discretion.

Responses From Readers

Clear

Bansidhar kadiya
Bansidhar kadiya

This is the best article about robotics. I really like it.

We use cookies essential for this site to function well. Please click to help us improve its usefulness with additional cookies. Learn about our use of cookies in our Privacy Policy & Cookies Policy.

Show details