0% found this document useful (0 votes)
23 views30 pages

Internship Report

Uploaded by

KamleshKumar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views30 pages

Internship Report

Uploaded by

KamleshKumar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 30

Internship Report on

SERIAL MANIPULATOR:
SIMULATION AND CONTROL

Course: ME440 - Practical Training

Submitted by:
Ravikant Narayan (14ME157)
B.Tech, Mechanical Engineering

Submitted to:
Dr Prasad Krishna
Department of Mechanical Engineering
National Institute of Technology Karnataka, Surathkal

Indian Institute of Technology National Institute of Technology

Madras, Chennai Karnataka, Surathkal


Acknowledgments
The internship opportunity I had at Indian Institute of Technology Madras was a
great chance for learning and professional development. Therefore, I consider
myself as a very lucky individual as I was provided with an opportunity to be
here. I am also grateful for having a chance to meet so many wonderful people
and professionals who led me though this internship period.

Bearing in mind previous I am using this opportunity to express my deepest


gratitude and special thanks to the Dr. Somashekhar S Hiremath who in spite
of being extraordinarily busy with his duties, took time out to hear, guide and
keep me on the correct path and allowing me to carry out my project.

I perceive as this opportunity as a big milestone in my career development. I


will strive to use gained skills and knowledge in the best possible way, and I
will continue to work on their improvement, in order to attain desired career
objectives. Hope to continue cooperation with all of you in the future.
ABSTRACT
The report presents the work completed during summer internship at Indian
Institute of Technology Madras which are listed below:
1. Measuring coordinates by using Faro laser tracker.
2. Modelling and Simulation of path tracked by 4R Articulated serial robot
manipulator.
3. Control of 4R Articulated serial robot manipulator.
4. Measuring error in radius of circular path tracked by robot.
All these work will be completed and results will be checked. Modelling and
Simulation have to do for trajectory tracked by end effector of a 4R articulated
serial robot. Forward and Inverse kinematics will be used for modelling and
simulation is done using Matlab. Experiments will be conducted to track square
trajectory and circular trajectory. Matlab programming on Arduino will be used
for controlling the robot.
CONTENT
1. Introduction
2. Faro laser tracker
2.1. Working of Faro laser tracker
2.2. Coordinate Transformation
3. Measurement of coordinates
3.1. Cam2 Measure 10
4. Homogeneous Transformation Matrixes
4.1. Rotation Matrix
4.2. Displacement Matrix
4.3. D-H parameters
4.3.1.D-H Matrix
4.3.2.D-H parameters for 4R articulated robot
5. Forward and Inverse Kinematics
5.1. Forward Kinematics
5.2. Inverse Kinematics
5.3. Forward and Inverse Kinematics of 4R Articulated Robot
5.3.1.Forward Kinematics
5.3.2.Inverse Kinematics
6. Simulation of Robot in Matlab
7. Implementation of Electronic Circuit to control robot
8. Controlling robot using Arduino and Matlab
9. Results
10. Conclusion
11. Reference
Appendix-A
1. Introduction
Serial manipulators are the most common industrial robots. They are
designed as a series of links connected by motor-actuated joints that extend
from a base to an end-effector. Often they have an anthropomorphic arm
structure described as having a "shoulder", an "elbow", and a "wrist". In its
most general form, a serial robot consists of a number of rigid links
connected with joints. Robot kinematics applies geometry to the study of the
movement of multi-degree of freedom that form the structure of robotic
systems. The emphasis on geometry means that the links of the robot are
modelled as rigid bodies and its joints are assumed to provide pure rotation
or translation. A fundamental tool in robot kinematics is the kinematics
equations of the kinematic chains that form the robot. These non-linear
equations are used to map the joint parameters to the configuration of the
robot system.
Following are the goals of present work:

1. Knowing about working of Faro laser tracker.


2. Homogeneous transformation matrix and Understand the D-H parameters
and use them for forward and inverse kinematics of robot.
3. Calculation of Forward and Inverse kinematics of Robot.
4. Simulation of robot in Matlab for different profiles.
5. Implementation of Electronic Circuit for Robot.
6. Control of Robot by using Matlab and Arduino.
This internship report contains activities that have contributed to achieve a
number of stated goals. After this, a reflection on functioning, the
unexpected circumstances and the learning goals achieved during the
internship are described. Finally Report gives a conclusion on the internship
experience according to learning goals.

2. Faro laser tracker:


The FARO laser tracker is an extremely accurate, portable coordinate
measuring machine that enables one to build products, optimize processes
and deliver solution by measuring quickly, simply and precisely.
2.1. Working of Faro laser tracker:
The operation of a laser tracker is easy to understand: It measures two angles
and a distance. The tracker sends a laser beam to a retro-reflective target held
against the object to be measured. Light reflected off the target retraces its
path, re-entering the tracker at the same position it left. Retro-reflective
targets vary, but the most popular is the spherically mounted retro-reflector
(SMR). As light re-enters the tracker, some of it goes to a distance meter that
measures the distance from the tracker to the SMR. The distance meter may
be either of two types, interferometer or absolute distance meter (ADM).
A laser tracker contains two angular encoders. These devices measure the
angular orientation of the tracker’s two mechanical axes: the azimuth axis
and the elevation (or zenith) axis. The angles from the encoders and the
distance from the distance meter are sufficient to precisely calculate the
centre of the SMR. Because of the spherical design of the SMR, its centre is
always at a fixed offset distance with respect to any surface being measured,
so the coordinates of surfaces or points measured with the SMR are easily
obtained. Distance measurement, an important function of the laser tracker,
can be either incremental or absolute. Incremental distance measurement is
made with an interferometer and a frequency-stabilised, helium-neon laser.

The laser light splits into two beams. One travels directly into the
interferometer. The other beam travels out of the tracker, reflects off the
SMR and, on the return path, passes into the interferometer. Inside the
interferometer, the two beams of light interfere, resulting in a cyclic change
each time the SMR moves closer to or farther from the tracker by a distance
equal to one quarter of the light’s wavelength. Electronic circuitry counts the
cyclic changes to determine the distance travelled.

2.2. Coordinate Transformation:


As show in Fig.-1 Spherical coordinates consist of the following three
quantities:
First there is r: This is the distance from the origin to the point and we will
require r>=0.
Next there is θ: It is the angle between the positive x-axis and the line above
denoted by R.
Finally there is ϕ: This is the angle between the positive z-axis and the line
from the origin to the point.
So, by using (ρ,θ,ϕ) and want to find (x,y,z).
X = r*cosθ*sinϕ, Y = r*sinθ*sinϕ, Z = r*cosϕ
Z

(x,y,z) = (r,θ,ϕ)

ϕ z

θ R

Fig.-1: Spherical coordinate system

3. Measurement of coordinates:
As proceeding to goals, First work is measurement of coordinates of a
circular profile taken by using Faro laser tracker. To complete the
measurement CAM2 Measure 10 software is used.
3.1. CAM2 Measure 10:
FARO CAM2 Measure 10 is all-in-one metrology software for complete
solution for all tactile measurement and non-contact 3D scanning
applications. The software is ideal for CAD and non-CAD inspection and
Geometric Dimensioning and Tolerancing.CAM2 Measure 10 features
image-guided measurement, automatic nominal association to various
features, Quick Tools and an intuitive user interface. Moreover, the software
is delivered with a reliable CAD import tool which increases the ability to
load a large amount of CAD data.
As proceed to measurement, measurement taken out by putting retro-
reflector on different points of a circular profile and around 600 points’
coordinate measure for more accuracy.
1. Homogeneous Transformation Matrixes:
To obtain transformation from one frame to another frame in 3D,
Homogeneous transformation matrixes are used. Homogeneous
transformation matrixes have these three types of matrixes:
1. Rotation Matrix
2. Displacement Matrix
3. D-H parameters
1.1. Rotation Matrix:
A basic rotation is a rotation about one of the axes of a Coordinate system.
The following three basic rotation matrices rotate vectors by an angle
θ about the x, y, or z axis, in three dimensions, using the right handed rule —
which codifies their alternating signs. (The same matrices can also represent
a clockwise rotation of the axes.)

For column vector, each of these basic vector rotations appears


counter-clockwise when the axis about which they occur points toward the
observer, the coordinate system is right-handed, and the angle θ is
positive. Rz, for instance, would rotate toward the y-axis a vector aligned
with the x-axis, as can easily be checked by operating with Rz on the
vector (1,0,0).
4.2. Displacement Matrix:
Displacement in one frame to another frame given by displacement matrix-
Where:
tx- is displacement in the direction of x-axis and
ty- is displacement in the direction of y-axis and
tz- is displacement in the direction of z-axis and

4.3. D-H Parameters:


The Denavit–Hartenberg parameters (also called DH parameters) are the
four parameters associated with a particular convention for attaching
reference frames to the links of a spatial kinematic chain, or robot
manipulator. There are four parameters:
1. d= offset along previous Z to the common normal
2. θ= angle about previous Z,from old X to new X.
3. a= length of the common normal. Assuming a revolute joint, this is the
radius about previous Z.
4. α= angle about common normal, from old Z axis to new Z axis

4.3.1. D-H Matrix:


It is common to separate a screw displacement into the product of a pure
translation along a line and a pure rotation about the line, so that by using
these rotation and translation notation, each link can be described by
a coordinate transformation from the previous coordinate system to the next
coordinate system:
T = RotX(αi-1) TransX(ai-1) RotZ(θi) TransZ(di)
Note that this is the product of two screw displacements. The matrices
associated with these operations are:
Where R is the 3×3 sub-matrix describing rotation and T is the 3×1 sub-
matrix describing translation.

4.3.2. D-H parameters for 4R articulated robot:


4R articulated robot have all 4 revolute joints. Fig.-5 contains information
about all joint frames at each revolute joint and Table-1 has D-H parameters,
which are used for robot:

Table-1.D-H parameter of Robot

Link No. A θ d α

link1 0 θ1 0 Pi/2

link2 11.0 θ2 0 0

link3 6.5 θ3 0 0

link4 7.5 θ4 0 0
Fig.-5: Joint frames of Robot

5. Forward and Inverse Kinematics:


Kinematics is the branch of classical mechanics which describes
the motion of points, bodies, and systems of bodies without consideration of
the masses of neither those objects nor the forces that may have caused the
motion. Robot kinematics refers the analytical study of the motion of a robot
manipulator. There are two types of kinematic for manipulators:

5.1. Forward Kinematics:


Forward kinematics refers to the use of the kinematic equations of a robot to
compute the position of the end-effector from specified values for the joint
parameters.
The kinematics equations for the series chain of a robot are obtained using
a rigid transformation [Z] to characterize the relative movement allowed at
each joint and separate rigid transformation [X] to define the dimensions of
each link. The result is a sequence of rigid transformations alternating joint
and link transformations from the base of the chain to its end link, which is
equated to the specified position for the end link.
T = RotX(αi-1) TransX(ai-1) RotZ(θi) TransZ(di)
5.2. Inverse Kinematics:
Inverse kinematics refers to the use of the kinematics equations of a robot to
determine the joint parameters that provide a desired position of the end-
effector. Specification of the movement of a robot so that its end-effector
achieves a desired task is known as motion planning. Inverse kinematics
transforms the motion plan into joint actuator trajectories for the robot.
The movement of a kinematic chain whether it is a robot or an animated
character is modelled by the kinematics equations of the chain. These
equations define the configuration of the chain in terms of its joint
parameters. Forward kinematics uses the joint parameters to compute the
configuration of the chain, and inverse kinematics reverses this calculation to
determine the joint parameters that achieves a desired configuration.
Kinematic analysis is one of the first steps in the design of most industrial
robots. Kinematic analysis allows the designer to obtain information on the
position of each component within the mechanical system. This information
is necessary for subsequent dynamic analysis along with control paths.

5.3. Forward and Inverse Kinematics of 4R Articulated Robot:


Forward and Inverse kinematics for 4R articulated robot calculated as
follow:
5.3.1. Forward Kinematics:
Forward Kinematics of 4r articulated robot can be calculated by using by
homogeneous transformation matrixes. For D-H parameters calculated
above, transformation matrix can be written as follow:

T01 = [ ]

T12 = [ ]

T23 = [ ]
T34 = [ ]

So final Transformation Matrix will be:


T04 = T01*T12*T23*T34
And position of end-effector(X,Y,Z) will be the last column of each row of
T04 Transformation Matrix.
5.3.2. Inverse Kinematics:
To calculate the Inverse kinematics, the position and orientation of end-
effector should be known. For this 4r robot, by seeing the transformation
matrix, three equation of X,Y Z coordinate found as follow:
Here: a1 = 11, a2 = 6.5, a3 = 7.5

X = cosθ1(a1*cosθ2+a2*cosθ23+a3*cosθ234) (1)
Y = sinθ1(a1*cosθ2+a2*cosθ23+a3*cosθ234) (2)
Z = a1*sinθ2+a2*sinθ23+a3*sinθ234 (3)
Here: θ234 = θ2+θ3+θ4
θ23 = θ2+θ3
And Orientation of final position can be calculated by converting Cartesian
coordinate to Spherical coordinate. So orientation ϕ (angle of vector from
positive Z-axis) will be:
ϕ= atan2 (sqrt(X*X)+(Y*Y),Z)
and also: ϕ= θ2+θ3+θ4 (4)
Let’s start Inverse Kinematics:
By dividing equation(2) by equation(1), θ1 can be found:
θ1= atan2 (Y,X) (5)
By equating ahead θ2 can be found:
θ2= atan2(c,sqrt(r*r-c*c)) – atan2(a,b) (6)
Where: a= a2*sinθ3, b = a1+a2*cosθ3
c= Z – a3*sinϕ , r = sqrt(a*a-b*b)
by taking distance between Frame1 to frame3, θ3 can be found:
θ3= acos((A*A+B*B+C*C-a1*a1-a2*a2)/2*a1*a2) (7)
Where: A= (X-a3*cosθ1cosϕ), B = (Y-a3*sinθ1cosϕ)
C = (Z-a3*sinϕ)
Now by equating eq(4),eq(7) and eq(6), θ4 can be found:
θ4 = ϕ-θ2-θ3 (8)
So finally equation(5), equation(6), equation(7), equation(8) will give value
of θ1,θ2,θ3 and θ4.
6. Simulation of Robot in Matlab:
Simulation is done by using inverse kinematics of robot in Matlab. In this
Simulation there will be three links and one point as an end-effector of robot.
Simulation is carried out for showing links and end-effector point and it is
shown in fig.-6:

Fig.-6: Simulation of 4R Articulated robo


Simulation is carried out for generating square profile of side 10 and the
generated profile is shown in fig.-7:

Fig.-7: Simulation for generating a Square profile

Simulation is carried out for generating circular profile of radius 5 and the
generated profile is shown in fig.-8:

Fig.-8: Simulation for generating a Circular profile


7. Implementation of Electronic Circuit to control robot:
Robot manipulator has two types of servos:
1. HS-755HB
2. HS-422
Here are some important specification of Servo HS-422 that necessary to
keep in mind while making circuit :
1. Operating voltage= 4.8 to 6.0 volt
2. Max current = 500mAmp
For servo HS-722HB:
1. Operating voltage= 4.8 to 6.0 volt
2. Max current = 1.5Amp
Electronic circuit for controlling the robot have one Arduino but by arduino
we can’t run 4 servos so we need some external power supply.
12v power supply used to control robot but problem is 12v power supply
can’t apply to servos. To solve this problem, voltage regulator is used to
reduce voltage from 12v to 5v. There is a solution for this is 7805 voltage
regulator IC that can convert 12v to 5v and 5v can be applied to servos. But
again problem is current rating of 7805 ic. Max current of 7805 ic is 1Amp.
For servo HS755HB, current requirement is more so to come out from this
problem two 7805 voltage regulator ic need to connect in parallel to get
2Amp current and that will solve the problem.
This circuit have following components:
1. 6 - 7805 voltage regulator ic
2. 1 - Arduino uno
3. 1 – USB cable
4. 1 – Breadboard
5. Diodes
6. Some jumper wires
Fig.-9 shows the Connections of two 7805 in parallel. To connect two 7805
in parallel, give them same input and connect diodes on output to divide load
in equal part for both 7805.

Fig.-9: Two 7805 IC in parallel


Final circuit for controlling robot is shown in Fig.-10:

JUMPER WIRES
7805 IC 7805 IC

USB CABLE DIODE ARDUINO BREADBOARD

Fig.-10: Electronic circuit for controlling the Robot

8. Controlling robot using Arduino and Matlab:


For controlling robot both Arduino and Matlab used because of Arduino
can’t solve mathematical equation. Inverse kinematics has to be solving for
controlling robot and that can be solve in Matlab. But Matlab code can’t run
direct on arduino so Arduino Support package need to install for Matlab
from Mathworks. First of all, add arduino support package to matlab path
and then run the code. Here is the code for controlling robot to make a
square profile.
Appendix-A contain matlab code to generate a square and circular profile by
end-effector of 4R articulated robot.
Fig.-10 shows the overall setup:

Power Supply
4R Articulated Robot
Faro laser Tracker

Electric Circuit

Fig.-10: Overall setup


9. Results:
After taking measurement of points on circular profile tracked by robot end-
effector, data is put in excel and obtained the graphs. By calculating the data,
obtained radius has 1.6% error of its original radius. Three graph plotted by
using data:
2. Y coordinates versus Z coordinates of discrete points measured on the
given circular profile as given in Fig 2.
3. X coordinates versus Z coordinates of discrete points measured on the
given circular profile as given in Fig 3.
4. X coordinates versus Y coordinates of discrete points measured on the
given circular profile as given in Fig 4.

Fig.-2: Graph of Y coordinates versus Z coordinates.


Z
280

270

260

250
-15 -10 -5 0 5 10 15

Fig.-3: Graph of X coordinates versus Z coordinates.

-300
250 300
X

Y
-310 X

-320

Fig.-4: Graph of Y coordinates versus X coordinates


10. Conclusion:
All work has been completed successfully. Modelling and Simulation are
carried out for trajectory tracked by end effector of a 4R articulated serial
robot. Forward and Inverse kinematics was used for modelling and
simulation is done using Matlab. Radius of a circular path is measured by
using coordinate measurement device and an average measurement error of
1.6% was observed. Experiments were conducted to track circular trajectory.
Matlab programming on Arduino was used for controlling the robotic arm.

11. Reference:
1. Robert J. Schilling, ―Fundamentals of Robotics: Analysis & Control‖,
Prentice Hall, Inc., 2011 edition.
2. John J. Craig, ―Introduction to Robotics: Mechanics & Control‖,
Pearson Publishing, 2008 edition.
3. ―Kinematic Modeling and Analysis of a 5 Axis Articulated Robot Arm
Model VRT-502‖, International Journal of Engineering Research &
Technology (IJERT), ISSN: 2278-0181, Vol. 4 Issue 07, July-2015
Appendix-A
Final matlab code to generate a square profile for 4r Articulated robot:

%Matlab-Arduino code for 4r robot

clc
clear all
global a;
a = arduino('com5');
a.servoAttach(8);
a.servoAttach(9);
a.servoAttach(10);
a.servoAttach(11);
a.servoWrite(8,0);
a.servoWrite(9,0);
a.servoWrite(10,0);
a.servoWrite(11,0);
a1 = 11;
a2 = 6.5;
a3 = 7.5;

for j = -5:0.5:5
x = 14;
z = 20;
y = j;
d = sqrt((x*x)+(y*y));
phai = atan2(d,z);
r = [1 0 0;0 cos(phai) -sin(phai); 0 sin(phai) cos(phai)];
t1 = atan2(y,x);
A = (x-(a3*cos(t1)*cos(phai)));
B = (y-(a3*sin(t1)*cos(phai)));
C = (z-(a3*sin(phai)));
v = sqrt((A*A)+(B*B)+(C*C));
f = (v^2)-(a1*a1)-(a2*a2);
t3 = acos(f/(2*a2*a1));
m = a2*sin(t3);
b = a1+a2*cos(t3);
c = z-a3*sin(phai);
e = sqrt((m*m)+(b*b));
g = sqrt((e*e)-(c*c));
t2 = atan2(c,g)-atan2(m,b);
t4 = phai-t2-t3;
if (t1<0 || t1>pi)
fprintf('try with another coordinates');
else
theta1 = (t1*180)/pi;
end

if (t2<0 || t2>pi/6)
fprintf('try with another coordinates');
else
theta2 = (t2*180)/pi;
end

if (t3<(pi/6) || t3>(pi-pi/6))
fprintf('try with another coordinates');
else
theta3 = (t3*180)/pi;
end

if (t4<pi/6 || t4>(pi-pi/6))
t44 = t4+(2*pi);
theta44 = (t4*180)/pi;
theta4 = (theta44*180)/360;
else
theta4 = (t4*180)/pi;
end

a.servoWrite(8,int64(theta1));
a.servoWrite(9,int64(theta2));
a.servoWrite(10,int64(theta3));
a.servoWrite(11,int64(theta4));
end

for j = 20:-0.5:10
x = 14;
z = j;
y = 5;
d = sqrt((x*x)+(y*y));
phai = atan2(d,z);
r = [1 0 0;0 cos(phai) -sin(phai); 0 sin(phai) cos(phai)];
t1 = atan2(y,x);
A = (x-(a3*cos(t1)*cos(phai)));
B = (y-(a3*sin(t1)*cos(phai)));
C = (z-(a3*sin(phai)));
v = sqrt((A*A)+(B*B)+(C*C));
f = (v^2)-(a1*a1)-(a2*a2);
t3 = acos(f/(2*a2*a1));
m = a2*sin(t3);
b = a1+a2*cos(t3);
c = z-a3*sin(phai);
e = sqrt((m*m)+(b*b));
g = sqrt((e*e)-(c*c));
t2 = atan2(c,g)-atan2(m,b);
t4 = phai-t2-t3;

if (t1<0 || t1>pi)
fprintf('try with another coordinates');
else
theta1 = (t1*180)/pi;
end

if (t2<0 || t2>pi/6)
fprintf('try with another coordinates');
else
theta2 = (t2*180)/pi;
end

if (t3<(pi/6) || t3>(pi-pi/6))
fprintf('try with another coordinates');
else
theta3 = (t3*180)/pi;
end

if (t4<pi/6 || t4>(pi-pi/6))
t44 = t4+(2*pi);
theta44 = (t4*180)/pi;
theta4 = (theta44*180)/360;
else
theta4 = (t4*180)/pi;
end

a.servoWrite(8,int64(theta1));
a.servoWrite(9,int64(theta2));
a.servoWrite(10,int64(theta3));
a.servoWrite(11,int64(theta4));
end
for j = 5:-0.5:-5
x = 14;
z = 10;
y = j;
d = sqrt((x*x)+(y*y));
phai = atan2(d,z);
r = [1 0 0;0 cos(phai) -sin(phai); 0 sin(phai) cos(phai)];
t1 = atan2(y,x);
A = (x-(a3*cos(t1)*cos(phai)));
B = (y-(a3*sin(t1)*cos(phai)));
C = (z-(a3*sin(phai)));
v = sqrt((A*A)+(B*B)+(C*C));
f = (v^2)-(a1*a1)-(a2*a2);
t3 = acos(f/(2*a2*a1));
m = a2*sin(t3);
b = a1+a2*cos(t3);
c = z-a3*sin(phai);
e = sqrt((m*m)+(b*b));
g = sqrt((e*e)-(c*c));
t2 = atan2(c,g)-atan2(m,b);
t4 = phai-t2-t3;

if (t1<0 || t1>pi)
fprintf('try with another coordinates');
else
theta1 = (t1*180)/pi;
end

if (t2<0 || t2>pi/6)
fprintf('try with another coordinates');
else
theta2 = (t2*180)/pi;
end

if (t3<(pi/6) || t3>(pi-pi/6))
fprintf('try with another coordinates');
else
theta3 = (t3*180)/pi;
end

if (t4<pi/6 || t4>(pi-pi/6))
t44 = t4+(2*pi);
theta44 = (t4*180)/pi;
theta4 = (theta44*180)/360;
else
theta4 = (t4*180)/pi;
end

a.servoWrite(8,int64(theta1));
a.servoWrite(9,int64(theta2));
a.servoWrite(10,int64(theta3));
a.servoWrite(11,int64(theta4));
end

for j = 10:0.5:20
x = 14;
z = j;
y = -5;
d = sqrt((x*x)+(y*y));
phai = atan2(d,z);
r = [1 0 0;0 cos(phai) -sin(phai); 0 sin(phai) cos(phai)];
t1 = atan2(y,x);
A = (x-(a3*cos(t1)*cos(phai)));
B = (y-(a3*sin(t1)*cos(phai)));
C = (z-(a3*sin(phai)));
v = sqrt((A*A)+(B*B)+(C*C));
f = (v^2)-(a1*a1)-(a2*a2);
t3 = acos(f/(2*a2*a1));
m = a2*sin(t3);
b = a1+a2*cos(t3);
c = z-a3*sin(phai);
e = sqrt((m*m)+(b*b));
g = sqrt((e*e)-(c*c));
t2 = atan2(c,g)-atan2(m,b);
t4 = phai-t2-t3;

if (t1<0 || t1>pi)
fprintf('try with another coordinates');
else
theta1 = (t1*180)/pi;
end

if (t2<0 || t2>pi/6)
fprintf('try with another coordinates');
else
theta2 = (t2*180)/pi;
end

if (t3<(pi/6) || t3>(pi-pi/6))
fprintf('try with another coordinates');
else
theta3 = (t3*180)/pi;
end

if (t4<pi/6 || t4>(pi-pi/6))
t44 = t4+(2*pi);
theta44 = (t4*180)/pi;
theta4 = (theta44*180)/360;
else
theta4 = (t4*180)/pi;
end

a.servoWrite(8,int64(theta1));
a.servoWrite(9,int64(theta2));
a.servoWrite(10,int64(theta3));
a.servoWrite(11,int64(theta4));
end

Final matlab code to generate a circular profile for 4r Articulated robot:

clc
clear all
global a;
a = arduino('com5');
a.servoAttach(8);
a.servoAttach(9);
a.servoAttach(10);
a.servoAttach(11);
a.servoWrite(8,0);
a.servoWrite(9,0);
a.servoWrite(10,0);
a.servoWrite(11,0);
a1 = 11;
a2 = 6.5;
a3 = 7.5;
for j = 0:3:360
R = 5;
x = 14;
z = R*sin(j);
y = R*cos(j);
d = sqrt((x*x)+(y*y));
phai = atan2(d,z);
r = [1 0 0;0 cos(phai) -sin(phai); 0 sin(phai) cos(phai)];
t1 = atan2(y,x);
A = (x-(a3*cos(t1)*cos(phai)));
B = (y-(a3*sin(t1)*cos(phai)));
C = (z-(a3*sin(phai)));
v = sqrt((A*A)+(B*B)+(C*C));
f = (v^2)-(a1*a1)-(a2*a2);
t3 = acos(f/(2*a2*a1));
m = a2*sin(t3);
b = a1+a2*cos(t3);
c = z-a3*sin(phai);
e = sqrt((m*m)+(b*b));
g = sqrt((e*e)-(c*c));
t2 = atan2(c,g)-atan2(m,b);
t4 = phai-t2-t3;
if (t1<0 || t1>pi)
fprintf('try with another coordinates');
else
theta1 = (t1*180)/pi;
end
if (t2<0 || t2>pi/6)
fprintf('try with another coordinates');
else
theta2 = (t2*180)/pi;
end
if (t3<(pi/6) || t3>(pi-pi/6))
fprintf('try with another coordinates');
else
theta3 = (t3*180)/pi;
end
if (t4<pi/6 || t4>(pi-pi/6))
t44 = t4+(2*pi);
theta44 = (t4*180)/pi;
theta4 = (theta44*180)/360;
else
theta4 = (t4*180)/pi;
end
a.servoWrite(8,int64(theta1));
a.servoWrite(9,int64(theta2));
a.servoWrite(10,int64(theta3));
a.servoWrite(11,int64(theta4));
end

You might also like