Lab Robotics
Lab Robotics
Lab Manual
DEPARTMENT OF ARTIFICIAL
INTELLIGENCE AND DATA SCIENCE
LAB MANUAL
Semester: VI
Prepared by Approved by
VISION
“To be a centre of excellence for learning and research in engineering and technology, producing
intellectually well-equipped and socially committed citizens possessing an ethical value
system.”.
MISSION
1.Facilitate learning and innovative research in the frontier areas of AI & DS like Natural
language Processing, Robotics and Computer Vision.
2.Drive students for technology development and transfer to solve socially relevant problems.
3.Create socially responsible professionals.
engineering and management principles and apply these to one’s own work, as a member and
leader in a team, to manage projects and in multidisciplinary environments.
PO12. Life-long Learning: Recognize the need for, and have the preparation and ability to
engage in independent and life-long learning in the broadest context of technological change.
LIST OF EXPERIMENTS
PRECAUTIONS
EXPERIMENT 1
Familiarization of Arduino IDE, Arduino microcontroller, I/O interfacing (LED, LCD, Serial
Monitor)
THEORY :
Arduino Software (IDE):- Includes the built in support for the boards in the following list, all
based on the AVR Core. The Boards Manager included in the standard installation allows to add
support for the growing number of new boards based on different cores like Arduino Due,
Arduino Zero, Edison, Galileo and so on.
● Arduino Yún An ATmega32u4 running at 16 MHz with auto-reset, 12 Analog In, 20
Digital I/O and 7 PWM.
● Arduino Uno An ATmega328P running at 16 MHz with auto-reset, 6 Analog In, 14
Digital I/O and 6 PWM.
● Arduino Diecimila or Duemilanove w/ ATmega168 An ATmega168 running at 16 MHz
with auto-reset.
● Arduino Nano w/ ATmega328P An ATmega328P running at 16 MHz with auto-reset.
Has eight analog inputs.
● Arduino Mega 2560 An ATmega2560 running at 16 MHz with auto-reset, 16 Analog In,
54 Digital I/O and 15 PWM.
● Arduino Mega An ATmega1280 running at 16 MHz with auto-reset, 16 Analog In, 54
Digital I/O and 15 PWM.
● Arduino Mega ADK An ATmega2560 running at 16 MHz with auto-reset, 16 Analog In,
54 Digital I/O and 15 PWM.
● Arduino Leonardo An ATmega32u4 running at 16 MHz with auto-reset, 12 Analog In,
20 Digital I/O and 7 PWM.
● Arduino Micro An ATmega32u4 running at 16 MHz with auto-reset, 12 Analog In, 20
Digital I/O and 7 PWM.
● Arduino Esplora An ATmega32u4 running at 16 MHz with auto-reset.
● Arduino Mini w/ ATmega328P An ATmega328P running at 16 MHz with auto-reset, 8
Analog In, 14 Digital I/O and 6 PWM.
Interfacing LCD:- The LCDs have a parallel interface, meaning that the microcontroller has to
manipulate several interface pins at once to control the display. The interface consists of the
following pins:
● A register select (RS) pin that controls where in the LCD's memory you're writing data
to. You can select either the data register, which holds what goes on the screen, or an
instruction register, which is where the LCD's controller looks for instructions on what to
do next.
● A Read/Write (R/W) pin that selects reading mode or writing mode
● 8 data pins (D0 -D7). The states of these pins (high or low) are the bits that you're writing
to a register when you write, or the values you're reading when you read.
There's also a display contrast pin (Vo), power supply pins (+5V and GND) and LED Backlight
(Bklt+ and BKlt-) pins that you can use to power the LCD, control the display contrast, and turn
on and off the LED backlight, respectively.
The process of controlling the display involves putting the data that form the image of what you
want to display into the data registers, then putting instructions in the instruction register.
The Liquid Crystal Library simplifies this for you so you don't need to know the low-level
instructions.
The Hitachi-compatible LCDs can be controlled in two modes: 4-bit or 8-bit. The 4-bit mode
requires seven I/O pins from the Arduino, while the 8-bit mode requires 11 pins. For displaying
text on the screen, you can do most everything in 4-bit mode, so example shows how to control a
16x2 LCD in 4-bit mode.
Serial Monitor:- The Arduino IDE has a feature that can be a great help in debugging sketches
or controlling Arduino from your computer's keyboard.The Serial Monitor is a separate pop-up
window that acts as a separate terminal that communicates by receiving and sending Serial
Data.Serial Data is sent over a single wire (but usually travels over USB in our case) and consists
of a series of 1's and 0's sent over the wire. Data can be sent in both directions (In our case on
two wires). will use the Serial Monitor to debug Arduino Software Sketches or to view data sent
by a working Sketch. You must have an Arduino connected by USB to your computer to be able
to activate the Serial Monitor.To get familiar with using the Serial Monitor, Copy and Paste the
following example Sketch into a blank Arduino IE window. Then Verify it and if it's OK,
Upload it. The next step will show you what to expect.
PROGRAMS
Interfacing LED
void setup() {
// initialize digital pin LED_BUILTIN as an output.
pinMode(LED_BUILTIN, OUTPUT);
}
// the loop function runs over and over again forever
void loop() {
digitalWrite(LED_BUILTIN, HIGH); // turn the LED on (HIGH is the voltage level)
delay(1000); // wait for a second
digitalWrite(LED_BUILTIN, LOW); // turn the LED off by making the voltage LOW
delay(1000); // wait for a second
}
Interfacing LCD
#include <LiquidCrystal.h>
// initialize the library by associating any needed LCD interface pin
// with the arduino pin number it is connected to
const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
void setup() {
// set up the LCD's number of columns and rows:
lcd.begin(16, 2);
// Print a message to the LCD.
lcd.print("hello, world!");
}
void loop() {
// set the cursor to column 0, line 1
// (note: line 1 is the second row, since counting begins with 0):
lcd.setCursor(0, 1);
Interfacing LED
Interfacing LCD
RESULT
Familiarized Arduino IDE, Arduino microcontroller, I/O interfacing (LED, LCD, Serial
Monitor).
EXPERIMENT 2
THEORY :
Interfacing IR:- The sensor output pin is connected to the digital pin 3. The IR or obstacle
sensor gives logic HIGH (1) as output when there is no obstacle in front of it, and it will give
logic LOW (0) output when an obstacle is placed in front of it. We need to read these logical
changes on the Arduino. The LED is an indicator which is connected to Arduino digital pin 11.
Interfacing the IR sensor with Arduino works using simple Logic. That is If Arduino reads LOW
data from the sensor output pin, LED should turn ON. Else if Arduino reads HIGH data from the
sensor output pin, LED should turn OFF.
PROGRAMS
Interfacing IR
int trigpin = 3;
int echopin = 4;
long duration;
int distance;
void setup()
{
pinMode(trigpin,OUTPUT);
pinMode(echopin,INPUT);
Serial.begin (9600);
}
void loop()
{
digitalWrite(trigpin,LOW);
delayMicroseconds(2);
digitalWrite(trigpin,HIGH);
delayMicroseconds(10);
digitalWrite(trigpin,LOW);
duration = pulseIn(echopin,HIGH);
distance = duration*0.034/2;
Serial.print("distance:");
Serial.print(distance);
Serial.println(" cm");
delay(500);
}
SCHEMATIC
Interfacing IR
RESULT
Successfully interfaced IR and Ultrasonic sensor.
EXPERIMENT 3
Interfacing DC motors with Arduino - speed and direction control
AIM : To interface DC motors with Arduino - speed and direction control
THEORY:- DC motor converts electrical energy in the form of Direct Current into mechanical
energy in the form of rotational motion of the motor shaft.The DC motor speed can be controlled
by applying varying DC voltage; whereas the direction of rotation of the motor can be changed
by reversing the direction of current through it.For applying varying voltage, we can make use of
PWM technique.For reversing the current, we can make use of H-Bridge circuit or motor driver
ICs that employ the H-Bridge technique.For more information about DC motors and how to use
them, H-Bridge circuit configurations, and PWM technique.
PROGRAMS
SCHEMATIC
RESULT
Successfully interfaced DC motors with Arduino for speed and direction control.
EXPERIMENT 4
Interfacing Servo Motors with Arduino - angle of rotation
THEORY:- A servo motor is an electrical device used to rotate objects at certain specified
angles. It’s just a basic motor that runs through the mechanism of the servo. They are used in
numerous applications such as toy cars, robotics, machines etc. Servo motors are measured in kg
/ cm (kilogram per centimeter). Servo motors are rated 3kg / cm or 6kg / cm etc. This kg / cm tell
you how much weight your servo engine can lift at a given distance. Generally servo motor
9G SG90 is used.Servo motors have 3 wires coming out of them. Out of which 2 are used
as Power pins (positive and negative) and the third one is used for the signal that is to be sent
from the MCU.All Servo motors operate on the principle of PWM (Pulse Width Modulation),
meaning their angle of rotation is controlled by the length of the pulse applied to their Control
PIN. Essentially, the servo motor consists of a DC motor powered by a variable resistor
(potentiometer – POT) and some gears.
Servo motor SG90 can be rotated from 0 to 180 degree, but other servo motors can rotate
completely 360 degree depending upon manufacturer. By adding the correct width of the
Electrical Pulse to its control pin, this degree of rotation can be controlled.
PROGRAMS
SCHEMATIC
RESULT
Successfully interfaced Servo Motors with Arduino to vary angle of rotation.
EXPERIMENT 5
Writing a Simple Publisher and Subscriber, Simple Service and Client, Recording, and playing
back data, Reading messages from a bag file (Python)
AIM : To write a Simple Publisher and Subscriber, Simple Service and Client, Recording, and
playing back data, Reading messages from a bag file (Python)
Requirements :
THEORY:- A ROS Node can be a Publisher or a Subscriber. A Publisher is the one that puts the
messages of some standard Message Type to a particular Topic. The Subscriber on the other
hand subscribes to the Topic so that it receives the messages whenever any message is published
to the Topic
Services are another way to pass data between nodes in ROS. Services are just synchronous
remote procedure calls; they allow one node to call a function that executes in another node. We
define the inputs and outputs of this function similarly to the way we define new message types.
A ROS client library is a collection of code that eases the job of the ROS programmer. It takes
many of the ROS concepts and makes them accessible via code. In general, these libraries let you
write ROS nodes, publish and subscribe to topics, write and call services, and use the Parameter
Server.
A bag is a file format in ROS for storing ROS message data. Bags -- so named because of their
.bag extension -- have an important role in ROS, and a variety of tools have been written to allow
you to store, process, analyze, and visualize them.
The ROS Bag is a powerful tool for you to record and playback your simulation.
PROGRAMS
1 #!/usr/bin/env python
2 # license removed for brevity
3 import rospy
4 from std_msgs.msg import String
5
6 def talker():
7 pub = rospy.Publisher('chatter', String, queue_size=10)
8 rospy.init_node('talker', anonymous=True)
9 rate = rospy.Rate(10) # 10hz
10 while not rospy.is_shutdown():
1 #!/usr/bin/env python
2
3 from __future__ import print_function
4
5 from beginner_tutorials.srv import AddTwoInts,AddTwoIntsResponse
6 import rospy
7
8 def handle_add_two_ints(req):
9 print("Returning [%s + %s = %s]"%(req.a, req.b, (req.a + req.b)))
10 return AddTwoIntsResponse(req.a + req.b)
11
12 def add_two_ints_server():
13 rospy.init_node('add_two_ints_server')
14 s = rospy.Service('add_two_ints', AddTwoInts, handle_add_two_ints)
15 print("Ready to add two ints.")
16 rospy.spin()
17
18 if __name__ == "__main__":
19 add_two_ints_server()
1 #!/usr/bin/env python
2
3 from __future__ import print_function
4
5 import sys
6 import rospy
7 from beginner_tutorials.srv import *
8
9 def add_two_ints_client(x, y):
10 rospy.wait_for_service('add_two_ints')
11 try:
12 add_two_ints = rospy.ServiceProxy('add_two_ints', AddTwoInts)
13 resp1 = add_two_ints(x, y)
14 return resp1.sum
15 except rospy.ServiceException as e:
16 print("Service call failed: %s"%e)
17
18 def usage():
19 return "%s [x y]"%sys.argv[0]
20
21 if __name__ == "__main__":
22 if len(sys.argv) == 3:
23 x = int(sys.argv[1])
24 y = int(sys.argv[2])
25 else:
26 print(usage())
27 sys.exit(1)
28 print("Requesting %s+%s"%(x, y))
29 print("%s + %s = %s"%(x, y, add_two_ints_client(x, y)))
OUTPUT
Result
Successfully accomplished a Simple Publisher and Subscriber, Simple Service and Client,
Recording, and playing back data, Reading messages from a bag file (Python).
EXPERIMENT 6
Touch Sensors interfacing and feedback system
THEORY:-
PROGRAMS
void setup() {
// initialize serial communication at 9600 bits per second:
Serial.begin(9600);
// initialize the Arduino's pin as aninput
pinMode(SENSOR_PIN, INPUT);
}
void loop() {
// read the state of the the input pin:
currentState = digitalRead(SENSOR_PIN);
RESULT
Successfully executed Touch Sensor interfacing and feedback system.
EXPERIMENT 7
Line following Robot using IR sensor
Requirements :
THEORY:-
The concept of the line follower robot is related to the transmitting and receiving of light. The white
colour reflects all the light that falls on it whereas the black colour absorbs all the light.In this line
follower robot, we have used IR transmitters and receivers ( also known as photodiodes). When IR light
falls on a white surface, it gets reflected back towards the IR receiver, generating some voltage changes
that are analyzed by the Arduino.When IR light falls on a black surface, it gets absorbed by the black
surface, and no rays are reflected back thus, the IR receiver doesn’t receive any rays.In this project, when
the IR sensor senses a white surface, an Arduino gets HIGH as input, and when it senses a black line, an
Arduino gets LOW as input. Based on these inputs, an Arduino Uno provides the proper output to control
the line follower.
PROGRAMS
#define MOTOR_SPEED 60
int mot1=9;
int mot2=6;
int mot3=5;
int mot4=3;
int left=13;
int right=12;
int Left=0;
int Right=0;
void setup() {
pinMode(mot1,OUTPUT);
pinMode(mot2,OUTPUT);
pinMode(mot3,OUTPUT);
pinMode(mot4,OUTPUT);
pinMode(left,INPUT);
pinMode(right,INPUT);
digitalWrite(left,HIGH);
digitalWrite(right,HIGH);
void loop() {
analogWrite(mot1,MOTOR_SPEED);
analogWrite(mot2,0);
analogWrite(mot3,MOTOR_SPEED);
analogWrite(mot4,0);
while(1) {
Left=digitalRead(left);
Right=digitalRead(right);
LEFT();
RIGHT();
analogWrite(mot3,0);
analogWrite(mot4,30);
while(Left==0) {
Left=digitalRead(left);
Right=digitalRead(right);
if(Right==0) {
int lprev=Left;
int rprev=Right;
STOP();
while(((lprev==Left)&&(rprev==Right))==1) {
Left=digitalRead(left);
Right=digitalRead(right);
analogWrite(mot1,MOTOR_SPEED);
analogWrite(mot2,0);
analogWrite(mot3,MOTOR_SPEED);
analogWrite(mot4,0);
analogWrite(mot1,0);
analogWrite(mot2,30);
while(Right==0) {
Left=digitalRead(left);
Right=digitalRead(right);
if(Left==0) {
int lprev=Left;
int rprev=Right;
STOP();
while(((lprev==Left)&&(rprev==Right))==1) {
Left=digitalRead(left);
Right=digitalRead(right);
analogWrite(mot3,MOTOR_SPEED);
analogWrite(mot4,0);
analogWrite(mot1,MOTOR_SPEED);
analogWrite(mot2,0);
analogWrite(mot1,0);
analogWrite(mot2,0);
analogWrite(mot3,0);
analogWrite(mot4,0);
RESULT
Successfully developed a Line following Robot using IR sensor.
EXPERIMENT 8
Object detection using any one standard algorithm
AIM : To implement any one standard object detection algorithm
THEORY:-
Object detection is the task of finding and identifying objects in an image. Humans recognize a
multitude of objects in images with little effort, despite the fact that the image of the objects may
vary somewhat in different viewpoints and sizes. Shape is not only, but the most powerful
descriptor of image content. Shape is probably the most important property that is perceived
about objects. It allows predicting more facts about an object than other features, e.g. coloring.
Thus, recognizing shape is crucial for object recognition. Different types of edge detection
techniques are available. Canny-edge detection and sobel-edge detection are most common edge
detection techniques. In Sobel edge detector, the task of edge detection is fulfilled by performing
a 2D spatial gradient convolution operation on an image. This operator uses two convolution
masks Gx and Gy as given below.
Gx = -1z1+1z3-2z4+2z6-1z7+1z9
Gy = 1z1+2z2+1z3-1z7-2z8-1z9
Where Zi, i=1,2….9 are intensity levels of each pixel in the convolution window shown in fig
Sobel operator is a very simple and effective way for finding the edges in an image. The sobel
operator is used mostly for detecting horizontal and vertical edges.
PROGRAMS
import cv2
img = cv2.imread('E:\images\sss.png')
cv2.imshow('sss',img)
cv2.waitKey(0)
cv2.destroyAllWindows()
B, G, R = cv2.split(img)
cv2.imshow("blue", B)
cv2.waitKey(0)
cv2.imshow("Green", G)
cv2.waitKey(0)
cv2.imshow("red", R)
cv2.waitKey(0)
#Edge Detction
#SobelEEdge Yorder
sobelYedge = cv2.Sobel(img, cv2.CV_64F,0,1,ksize=5)
#Sobel EdgeXY
SobelXYedge = cv2.Sobel(img,cv2.CV_64F,1,1,ksize=5)
#Canny Edge
#edges = cv2.Canny(grayImg, threshold1=30, threshold2=100)
#edges1 = cv2.Canny(grayImg, threshold1=50, threshold2=150)
#edges2 = cv2.Canny(hsvImage, threshold1=70, threshold2=200)
cv2.imshow('Original image',img)
cv2.imshow('Gray image',grayImg)
cv2.imshow('HSV image', hsvImage)
cv2.imshow('YCR image', YCRImage)
cv2.imshow('LAB image', LabImage)
cv2.waitKey(0)
cv2.destroyAllWindows()
RESULT
Successfully implemented a standard object detection algorithm.