-
Notifications
You must be signed in to change notification settings - Fork 81
/
Copy pathinverse_algebraic_control.m
89 lines (64 loc) · 1.93 KB
/
inverse_algebraic_control.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
%%
% Author: Yash Bansod
%
% GitHub: <https://github.com/YashBansod>
%
% This is the main program.
%% Clear the environment and the command line
clear;
clc;
close all;
%% Define the input parameters and simulate
% Set the length of the links of the manipulator robot.
L1 = 10;
L2 = 10;
% Define the initial end-effector position (This should be reachable)
X = 20;
Y = 0;
%% Compute the inverse algebraic solution for the initial position
C2 = (X^2 + Y^2 - L1^2 -L2^2)/(2 * L1 * L2);
S2 = sqrt(1-C2^2);
theta2 = atan2(S2, C2);
K1 = L1 + L2* cos(theta2);
K2 = L2 * sin(theta2);
theta1 = atan2(Y, X) - atan2(K2, K1);
X1 = L1*cos(theta1);
Y1 = L1*sin(theta1);
X2 = L1*cos(theta1) + L2*cos(theta1 + theta2);
Y2 = L1*sin(theta1) + L2*sin(theta1 + theta2);
plot([0, X1], [0,Y1]);
hold on;
grid on;
plot([X1,X2], [Y1, Y2]);
title('2 DOF Planar Manipulator');
legend('1st Link of Arm - Initial', '2nd Link of Arm - Initial');
axis([-30 30 -30 30]);
% Take desired end-effector position from user via mouse pointer.
% [X,Y] = ginput;
% X = X(end);
% Y = Y(end);
% Alternatively, user can choose the desired end-effector position
% directly as absolute coordinates too.
X = 5;
Y = 7;
fprintf("The selected point for end effector is (%0.2f, %0.2f)\n", [X, Y])
if hypot(X, Y) > L1 + L2
error("Point out of reach");
end
%% Compute the inverse algebraic solution for the final position
C2 = (X^2 + Y^2 - L1^2 -L2^2)/(2 * L1 * L2);
S2 = sqrt(1-C2^2);
theta2 = atan2(S2, C2);
K1 = L1 + L2* cos(theta2);
K2 = L2 * sin(theta2);
theta1 = atan2(Y, X) - atan2(K2, K1);
X1 = L1*cos(theta1);
Y1 = L1*sin(theta1);
X2 = L1*cos(theta1) + L2*cos(theta1 + theta2);
Y2 = L1*sin(theta1) + L2*sin(theta1 + theta2);
plot([0, X1], [0,Y1]);
plot([X1,X2], [Y1, Y2]);
legend('1st Link of Arm - Initial', '2nd Link of Arm - Initial', ...
'1st Link of Arm - Final', '2nd Link of Arm - Final');
hold off;
fprintf("The final end effector position is (%0.2f, %0.2f)\n", [X2,Y2]);