Robotic Coding

Robots are operator controlled, programmable, functional systems. Today’s robots are frequently used in places where humans cannot work, other than industry, because they can perform tasks that require power, without error and with great speed. In the process with the developing technology, robots are no longer just robot arms; they have become machines that can react to their surroundings, perceive their surroundings and move. Mobile robots have started to be used in many different applications in our daily lives.  An example is the robot named Pioneer, which was used to examine the plant after the explosion at the Chernobyl plant and to understand the effects of the explosion.

Robots are also used to detect problems in sewage pipes, maintenance and repair of air ducts in air conditioners. Alice, one of the smallest robots measuring 2x2x2, this independent robot also has a small camera and is used in problem detection, maintenance and repair work. Helpmate is a robot designed for transportation in hospitals. This robot had sensors to move independently of an operator in the hospital with the motion algorithm loaded into it.

Looking at the history of robotics, it can be seen that especially in the late 17th century, mechanical automata were built in Europe, which are considered to be the first robotic examples known to be imitating nature, generally for entertainment purposes and programmed to perform only one task without perception.  Later, with the addition of sensing to these mechanical automata, we can say that these automata started to gain robot characteristics.

In order to know the position of the robots and to make accurate and reliable mapping, the information that the robot perceives in its environment must be stable and reliable.

Commonly used sensors are:

  • Infrared sensors         
  • Laser sensors
  • Ultrasonic sensors     
  • Camera sensors         

Figure 1. Sensors

Infrared sensors: Infrared sensors are based on light sent from a source that is reflected back from a reflective mirror and detected by the receiver.

Laser sensors: Work on the same principle as optical sensors, using light from a high wavelength.

Ultrasonic sensors: It works by sending a sound wave to a specified point and obtaining the distance value measured according to the return time.

Camera sensors: The camera detects obstacles or objects in front of it with image processing techniques and draws a conclusion accordingly.

Microcontrollers are special microprocessors designed to perform control and automation operations in general. Microcontrollers are used in automatic washing machines, electronic clocks, cameras, biomedical devices, LCD displays and many electronic applications from industrial automation to electronic ticket applications.

There are ongoing debates about how to program a robot and which programming language is best for robotics programming. In fact, it always depends on your goal. If you know what you want and how to achieve it, any language can be suitable for you. There is a broad consensus that robotics programming mostly involves and should be based on languages like C/C++ and Python. C and C++ are the languages where robotics for beginners starts (Kenneth, 2019). Arduino is an open source physical programming platform.

Figure 2. Arduino programming elements

Arduino can be connected to software running on a computer, or it can be used to develop interactive objects that work on their own. The microprocessor on the Arduino development board is implemented using the Arduino programming language. For this, the program processing based Arduino software development environment is used as shown in figure 3.

Figure 3. Arduino software development environment

Arduino cards vary according to their usage areas. Arduino UNO, Arduino Nano, Arduino ADK, Arduino Leonardo, Arduino Mini, Arduino LILYPAD, Arduino MEGA and Arduino Yun are some of them.

Figure 4. Some arduino boards

The Arduino programming language is similar to C++. Two basic functions called setup() and loop() are used in all programs. The setup() function works when the power is applied or the reset button is pressed.

Basic Arduino Functions: When writing programs in the Arduino software development environment, some basic function structures should be known very well. Functions are very important in this context. Functions are the process of writing a function for that operation and calling it when necessary, instead of doing the same operation over and over again in a program. Figure 5 shows an example of Arduino function definition.

Figure 5. Arduino function definition example

# include function: When writing a program, this function is used to include the available libraries of the Arduino.

void setup() function: This is the first function that Arduino reads when the Arduino code starts running. It works only once after it is loaded on the board.

void loop() function: This is a main function. After the setup() function is read, the void loop() function is read. The tasks to be done are written here. The commands to be written between this function are repeated continuously throughout the program flow.

Figure 6.. Basic arduino functions

pinMode() function: This is the part that determines whether the legs on the board will be set as input or output. There are two parameters in the function. The first parameter is the pin and the second parameter is its value. This value is INPUT or OUTPUT. The usage of the PinMode() function is as follows:

pinMode(9, OUTPUT);

pinMode(3, INPUT);

digitalWrite() function: It is a command used to output voltage to a digital device. It is used to stop energizing or energize the pins defined as output. The use of the digitalWrite() function is as follows:

digitalWrite(2, LOW); // Energy output is stopped.

digitalWrite(6, HIGH); // Energy is output from pin 6.

Energy output is provided from pin 6, which was previously defined as output. If you want to stop the energy output, it is enough to write LOW instead of HIGH.

analogWrite() function: It allows the PWM signal to be generated on the selected pin. The use of the analogWrite() function is as follows:

analogWrite(5, 255); // Sends 5 volts to pin 5.

analogWrite(8, 0); // Sends 0 volts to pin 8.

digitalRead() function: It allows you to specify which pin to read from for reading a value from a digital pin. It is understood that the voltage at the input of a pin previously defined as input is low (close to 0 volts) or high (close to 5 volts). The use of the digitalRead() function is as follows:

deger = digitalRead (3);

 According to the ‘deger’ variable, if the voltage on pin 3 is close to 5 volts, the ‘deger’ variable is 0 (LOW) and if it is close to 1 volt (HIGH).

analogRead() function: The analogRead function is used to measure the exact value of the voltage between 0 and 5 volts. The analogRead() function cannot be used for all pins. There are special pins, i.e. analog pins, for which this function can be used. They generally start with the letter A: A0, A1, A2… etc. The number of these pins varies depending on the type of Arduino board used. The use of the AnalogRead() function is as follows:

analogDeger = analogRead(A0);

delay() function: It is a function that allows determining the running time of a code. The value written in the delay() function is in milliseconds. The usage of the delay() function is as follows:

delay(1000); // 1 second duration

Downloading and installing Arduino IDE Software: To perform Arduino IDE application, we perform the search process by typing Arduino IDE from the google search engine. As a result of the search, we reach the relevant web page by clicking on the link www.Arduino.cc. From the relevant page, click on the downloads command from the software menu. By clicking the Windows Installer, for Windows XP and up link in the Downloads the Arduino IDE section, we download the Arduino IDE file to our computer by clicking the Just download link from the incoming screen.

We start the installation by clicking on the arduino IDE file we downloaded to our computer. This way we complete the installation process. We run the Arduino IDE program installed on the desktop of our computer.    

Kaynaklar

Çakır, H., Tekedere, H. (2016). Güncel bilgi hizmetleri. Ankara: Sage Yayıncılık, ISBN 978-605-184-024-6.

Kenneth, (2019). How To Program A Robot: Beginner’s Guide, Kasım 2019, [Kullanılabilir Çevrim-içi: https://robots.net/robotics/how-to-program-a-robot/], Erişim tarihi: 14 Ağustos 2020.