Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

this is forward: close all; clc; clear; global l 1 l 2 l 3 l 4 l 5 l 6 ; l 1 = 3

this is forward:
close all;
clc;
clear;
global l1 l2 l3 l4 l5 l6;
l1=3.0; % Length of link BC
l2=4.0; % Length of link AD
l3=4.0; % Length of link DE
l4=3.0; % Length of link CE
l5=2.0; % Length of link EP
l6=5.0; % Length of link AB
function [Px, Py]= forward(theta1_deg, theta2_deg)
global l1 l2 l3 l4 l5 l6
% Convert degrees to radians
theta1= deg2rad(theta1_deg);
theta2= deg2rad(theta2_deg);
% Calculate positions of joints
A =[0,0];
B =[l6,0];
D =[l2* cos(theta2), l2* sin(theta2)];
C =[l6+ l1* cos(theta1), l1* sin(theta1)];
% Calculate angle th4 using vector loop closure
R1=[l6; 0]+ l1*[cos(theta1); sin(theta1)];
R2= l2*[cos(theta2); sin(theta2)];
R3= l3*[cos(pi - theta2); sin(pi - theta2)];
E = R2+ R3;
% Calculate the position of the end-effector P
P = E + l5*[cos(pi - theta2); sin(pi - theta2)];
Px = P(1);
Py = P(2);
end
% Call the forward function
[Px, Py]= forward(156,76);
% Display the results
disp(['Px: ', num2str(Px)]);
disp(['Py: ', num2str(Py)]);
this is inverse code:
close all;
clc;
clear;
% Define global variables
global l1 l2 l3 l4 l5 l6
l1=3.0; % Length of link BC
l2=4.0; % Length of link AD
l3=4.0; % Length of link DE
l4=3.0; % Length of link CE
l5=2.0; % Length of link EP
l6=5.0; % Length of link AB
% Example usage for inverse kinematics
Xp =-0.48384;
Yp =9.703;
% Call the solve_angles function
[theta1_deg, theta2_deg]= solve_angles(Xp, Yp);
% Display the results
disp(['Theta1 in degrees: ', num2str(theta1_deg)]);
disp(['Theta2 in degrees: ', num2str(theta2_deg)]);
function [theta1_deg, theta2_deg]= solve_angles(Xp, Yp)
global l1 l2 l3 l4 l5 l6
initial_guess =[pi, pi];
options = optimoptions('lsqnonlin', 'Display', 'iter', 'MaxFunctionEvaluations', 1000, 'MaxIterations', 1000);
solution = lsqnonlin(@equations, initial_guess, [],[], options, Xp, Yp);
theta1= solution(1);
theta2= solution(2);
% Convert radians to degrees
theta1_deg = rad2deg(theta1);
theta2_deg = rad2deg(theta2);
function F = equations(vars, Xp, Yp)
theta1= vars(1);
theta2= vars(2);
% Calculate positions of joints
A =[0,0];
B =[l6,0];
D =[l2* cos(theta2), l2* sin(theta2)];
C =[l6+ l1* cos(theta1), l1* sin(theta1)];
% Calculate angle th4 using vector loop closure
R1=[l6; 0]+ l1*[cos(theta1); sin(theta1)];
R2= l2*[cos(theta2); sin(theta2)];
R3= l3*[cos(pi - theta2); sin(pi - theta2)];
E = R2+ R3;
% Calculate the position of the end-effector P
P = E + l5*[cos(pi - theta2); sin(pi - theta2)];
eq1= P(1)- Xp;
eq2= P(2)- Yp;
F =[eq1; eq2];
end
end
code inverse is wrong can't return as same as the 1 and the 2.
D
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Concepts

Authors: David M. Kroenke

1st Edition

0130086509, 978-0130086501

More Books

Students also viewed these Databases questions

Question

5. How many no responses did you make?_________?

Answered: 1 week ago