Thread closed - question answered

5 ビュー (過去 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 Center および File ExchangeCode Generation についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by