Thread closed - question answered

3 Ansichten (letzte 30 Tage)
N/A
N/A am 16 Jan. 2016
Bearbeitet: Ashish am 21 Apr. 2021
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 Kommentar
Stephen23
Stephen23 am 15 Apr. 2021
Bearbeitet: Ashish am 21 Apr. 2021
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

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Geoff Hayes
Geoff Hayes am 17 Jan. 2016
Bearbeitet: Ashish am 21 Apr. 2021
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 Kommentare
N/A
N/A am 18 Jan. 2016
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 am 19 Jan. 2016
Bearbeitet: Ashish am 21 Apr. 2021
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?

Melden Sie sich an, um zu kommentieren.

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by