Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

close all; clc; clear; % Define global variables global l 1 l 2 l 3 l 4 l 5 l 6 l 1 = 3

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);
end
function F = equations(vars, Xp, Yp)
global l1 l2 l3 l4 l5 l6
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
need to fix with theta1 pls, problem from initial_guess

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

Transact SQL Cookbook Help For Database Programmers

Authors: Ales Spetic, Jonathan Gennick

1st Edition

1565927567, 978-1565927568

More Books

Students also viewed these Databases questions