Thread closed - question answered

조회 수: 2 (최근 30일)
N/A
N/A 2016년 1월 16일
편집: Ashish 2021년 4월 21일
The question has been answered but here is the original:
Original question on 16th January 2016:
What is the problem in this code. I want the robot hand motion at every 5ms and will be looping with increment of every 5ms until desired angle of the 2 link but the graph is not showing anything.
if true
%Robot arm motion script
% Initial values, angles in degrees
clc
clf
hold off
theta10 = -19*pi/180;
theta1tf = 30*pi/180;
theta20 = 44*pi/180;
theta2tf = 90*pi/180;
tf = 0.005;
%
% Equations for a coefficients
T = [ tf^5 tf^4 tf^3
5*tf^4 4*tf^3 3*tf^2
20*tf^3 12*tf^2 6*tf ];
c = [theta10; 0; 0 ];
disp('Coefficients for theta1 motion:')
a = T\c
%
% Equations for bcoefficients
d = [theta20; 0; 0];
disp('Coefficients for theta2 motion:')
b= T\d
%
% Equations of motion
L1 = 5;
L2 = 2;
tq = [ t.^5; t.^4; t.^3 ];
t = linspace(0,2,401);
theta1 = theta10 + a'*tq;
theta2 = theta20 + b'*tq;
x1 = L1*cos(theta1) + L2*cos(theta1 + theta2);
x2 = L1*sin(theta1) + L2*sin(theta1 + theta2);
tf = tf + 0.005;
theta10 = theta10 + theta1;
theta20 = theta20 + theta2;
%
% Plot path of hand
plot(x1,x2),...
end
  댓글 수: 1
Stephen23
Stephen23 2021년 4월 15일
편집: Ashish 2021년 4월 21일
Original question on 16th January 2016:
What is the problem in this code. I want the robot hand motion at every 5ms and will be looping with increment of every 5ms until desired angle of the 2 link but the graph is not showing anything.
if true
%Robot arm motion script
% Initial values, angles in degrees
clc
clf
hold off
theta10 = -19*pi/180;
theta1tf = 30*pi/180;
theta20 = 44*pi/180;
theta2tf = 90*pi/180;
tf = 0.005;
%
% Equations for a coefficients
T = [ tf^5 tf^4 tf^3
5*tf^4 4*tf^3 3*tf^2
20*tf^3 12*tf^2 6*tf ];
c = [theta10; 0; 0 ];
disp('Coefficients for theta1 motion:')
a = T\c
%
% Equations for bcoefficients
d = [theta20; 0; 0];
disp('Coefficients for theta2 motion:')
b= T\d
%
% Equations of motion
L1 = 5;
L2 = 2;
tq = [ t.^5; t.^4; t.^3 ];
t = linspace(0,2,401);
theta1 = theta10 + a'*tq;
theta2 = theta20 + b'*tq;
x1 = L1*cos(theta1) + L2*cos(theta1 + theta2);
x2 = L1*sin(theta1) + L2*sin(theta1 + theta2);
tf = tf + 0.005;
theta10 = theta10 + theta1;
theta20 = theta20 + theta2;
%
% Plot path of hand
plot(x1,x2),...
end

댓글을 달려면 로그인하십시오.

답변 (1개)

Geoff Hayes
Geoff Hayes 2016년 1월 17일
편집: Ashish 2021년 4월 21일
When I try to run the above code, I observe the following error
Undefined function or variable "t".
tq = [ t.^5; t.^4; t.^3 ];
because t is not defined until the subsequent line. Presumably, the following order should be
t = linspace(0,2,401);
tq = [ t.^5; t.^4; t.^3 ];
As for the drawing of the motion (of the hand), you suggest that you want there to be a looping with increments of five milliseconds. Does this mean that you want to plot the individual elements of x1 and x2 every five milliseconds? If so, then you could try something like
figure;
h = plot(gca, NaN, NaN);
for k=1:length(x1)
set(h,'XData',x1(1:k),'YData',x2(1:k));
pause(0.005)
end
In the above, we create a graphics object with no data
h = plot(gca, NaN, NaN);
and then update its x and y data on each iteration of the for loop, pausing for five milliseconds.
  댓글 수: 5
N/A
N/A 2016년 1월 18일
Error using matlab.graphics.chart.primitive.Line/set Invalid or deleted object.
Error in Untitled (line 43) set(h,'XData',x1(1:k),'YData',x2(1:k));
Geoff Hayes
Geoff Hayes 2016년 1월 19일
편집: Ashish 2021년 4월 21일
Put a break point at the first line of your code and run it. Step through the code to see where it deviates from what you expect. If you do so, you should notice a problem with the following line
t = linspace(0,0.005,1);
The t that you create will be a 1x1 array with the value of 0.005. What should it be?

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Code Generation에 대해 자세히 알아보기

태그

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by