Tuesday, March 29, 2016

Introduction to Rapid Prototyping: Robotics - Part 3: Robot's Brain

Going back to the human-being analogy, the human body is the most known closed-loop control system to us, it has sensors (human senses of touch, feel, vision, listen…etc), actuators (muscles, tendons, and joints) and finally a decision-making unit, an organ that analyzes and organize the information acquired from different sensors and command the actuators in act in a certain desired way. Robots are the imitation of the human being in all of its details, and without the analysis and decision-making unit the robot is incomplete and most probably will be dysfunctional and thus useless, so, this section is dedicated to the “Brain’s” of the robot to be built.
Microprocessors are the piece of electronics that will replace the brain for robots, they are made of tens or hundreds of millions of transistors all engraved on a silicon die. The personal computer we use every day consists of the microprocessor unit connected to many other peripherals for data processing, storage, input and output using hard-disk drives, RAM memory units, sound cards, keyboards and mice, they are quite efficient for the business and personal activities they are involved in, but when it comes to a small and/or mobile robot they aren’t the best because they are:
  •  Power hungry, personal computers consume a lot of power.
  •  Expensive, they can cost anything between 250$ and more.
  • Physical profile, they are big in size which makes them not suitable to install in a robot, especially a mobile one. 

The Microcontroller:

So, engineers and scientists decided to go for a different version of the microprocessors that has less processing capabilities, yet still sufficient for the processing and analysis required building a decision-making unit for a robot. In the new version, they added a less power, low-power consumption processor with a relatively small amount of RAM memory, replaced the hard-disk drive with a flash EEPROM and a simple input/output system all on one chip and called it a “Microcontroller” or shortly as “MCU”, A simple microcontroller architecture is shown in figure 25.
Figure 25: An example of a microcontroller architecture and some of the peripherals that might be found inside.
Basic Input/Output Modules in Microcontrollers:
  •  Digital Input/output: the simplest way to communicate with a microcontroller or any microprocessor-based system is sending or receiving binary signals to and from it as 0’s and 1’s, a digital input simply is to send a “1” or “0” to the input module of the microcontroller, and the same for a digital output, it is the microcontroller response by outputting a “0” or “1”. In many digital systems, a logic “0” is 0v or ground, while a logic “1” is 5v or 3.3v, however, it’s not standard for all digital systems, some digital systems defines logic “0” with a negative voltage and logic “1” with a positive voltage or the opposite, there are many ways to represent 0’s and 1’s and we call this “Line coding”, but it’s not in the scope of this article.
  • Analog to Digital Converter (ADC): this module converts analog signals from sensors to a digital signal so the MCU can understand (don’t forget, digital systems don’t understand analog signals). An analog signal is continuous in time and amplitude (i.e. voltage level), which is hard for a digital system to interpret because it uses discrete signals in both time and amplitude, so first we have to convert this analog, continuous in amplitude signal to a discrete analog one using a process called “Sampling”, which is basically a process of cutting the analog signal into small pieces, then convert the amplitude of each piece to a binary number through a process called “Quantization”, figure 26 shows the flow of the analog to digital process.


Figure 26: Analog to digital conversion

“Nyquist Frequency”: to avoid any distortion or inaccurate analog to digital conversion, make sure the frequency of the input analog signal is less than half the sampling frequency of the ADC module in the microcontroller, this condition is called the “Nyquist frequency” which defines the maximum frequency of an input analog signal, this information can be found in the microcontroller‘s datasheet.
  • Pulse Width Modulation (PWM): a module that outputs a pulse modulated signal, PWM principle of operation is more explained in detail in my previous article “Introduction to Rapid Prototyping – Part 1: Motion Control”.
  • Serial communication (RS-232 or UART): this module allows the MCU to communicate with any other MCU or a computer serially using the legacy RS-232 serial interface. Serial data transmission means 0’s and 1’s are transmitted serially one after another using a single data line (either input or output).
More about microcontrollers:
  • Interrupts: a microcontroller can be programmed to respond quickly to a sudden event which we call “Interrupts”, when an interrupt occur the MCU stops any running operation and responds to this interrupt first then resumes its operation normally after the interrupt even is gone,  we can define two types of interrupt for an MCU
    • External interrupt: a change in the status of a digital input, or data received from the serial bus (UART).
    •  Internal interrupt: using a “timer”, a timer is a programmable counter module that counts CPU clock ticks and when it reaches the maximum count it issues an “overflow signal”; a CPU then is interrupted and has to respond to the timer’s interrupt signal before resuming its normal operation. Timers are useful to create accurate delay or perform a loop on a certain process in a timely precise manner.
  • Programming a microcontroller: a developer first develops the firmware code on a computer using a specific programming language, C language is the most common one for microcontrollers and embedded systems, compiles and debug it to confirm there are no errors or problems, then download the output file to the MCU internal EEPROM (or flash memory) using a special device called a “Programmer”, an “In-Circuit Programmer”, “In-System Programmer” or an “In-Circuit Debugger”. 
Figure 27: Programming a microcontroller
For more details about different low-cost microcontroller platforms please visit my previous article “Introduction to Rapid Prototyping” published in 2014.  

Introduction to Arduino:
Arduino is a low-cost family of microcontroller boards ranges from 5$ and up. The development software used to program it is called “Arduino IDE”, it is available for free from Arduino official website (https://www.arduino.cc/en/Main/Software). This tutorial is going to teach how to program Arduino boards and I’m using one of Arduino boards called “Arduino Uno” as an example.

Why Arduino?
Arduino platform is easy to understand from both hardware and software prespective compared to other microcontroller platforms that might require previous experience in electronics and programming:

  • Input/Output pins are marked with numbers or simple intuitive labels.
  • Easy to connect input/output pins to external components like sensors, LEDs or another microcontroller board.
  • Easy-to-use, a C-like programming language with fewer details that might confuse the developer.
The Arduino Uno board used in this tutorial is based on Atmega328P microcontroller from Atmel Corporation, a famous semiconductors company specialized in microcontrollers and electronic components. The Arduino Uno has an “In-Circuit Programmer” onboard that you can connect to your computer via USB, An Arduino Uno board is shown in figure 28.
Figure 28: Arduino Uno board

Table 1: Arduino Uno Pinout
Pin number
Function
0
DIO/Serial Tx
1
DIO/Serial Rx
2
DIO
3
DIO
4
DIO
5
DIO
6
DIO
7
DIO
8
DIO
9
DIO
10
DIO
11
DIO
12
DIO
13
DIO
A0
DIO/Analog input
A1
DIO/Analog input
A2
DIO/Analog input
A3
DIO/Analog input
A4
DIO/Analog input
A5
DIO/Analog input
5v
5v supply pin
3.3v
3.3v supply pin
GND
Ground
  • DIO: Digital input/output pin.
  • Tx: Transmit pin for serial communication module (UART).
  • Rx: Receive pin for serial communication module (UART).
  • Analog input: analog input pin to the Analog-to-Digital Converter module.
About Arduino Uno board:
  • General Purpose Inputs/Outputs are the input & output interface pins between the  Arduino board and outside world.
  • Any pin can be configured as either digital input or digital output.
  • The output of digital pins is either +5v or +3.3v for logic "1" or ground (0v) for logic "0".
  • Some pins can be configured to be “Analog Inputs”, i.e. you can input analog signals on these pins to the analog-to-digital converter module.
  • Analog signal: they can take any value between 0v and +5v, the Arduino board converts this analog voltage value to a number, such pins are commonly used with sensors. 
Arduino programming and interfacing is more explained in detail in these SlideShare slides:


--
Published on: March 29, 2016
Vancouver, Canada

No comments:

Post a Comment