Two-Link Planar Robot Arm
20 views (last 30 days)
Show older comments
I'm currently trying to create a plot that shows the position and velocity for each segment of a 2-segment planar robot arm. My initial conditions for theta and the angular velocity have the arm starting at 90 degrees from the horizontal, with the second segment of the arm slightly bent so that gravity pulls the system down to -90 degrees. I expect the arm to swing around before settling down to zero. My current plot shows theta for the first arm segment going to negative infinity and theta for the second segment going to positive infinity. Any ideas on how I can make everything have an initial oscillation and then converge to zero like I know it's supposed to? I'm trying to make the multi-colored picture look like the black-and-red picture.
%% Robot Arm
tvec=[0 30]; %range of time values for the function to use
smoothout=300; %the larger this number is, the smoother the function will look
range=linspace(tvec(1),tvec(2),smoothout);
%these next lines establish the initial conditions
theta1=pi/2; %position of theta1 (angle of the first arm segment)
dtheta1=0; %first derivative of theta1 (angular velocity of the first arm segment)
theta2=0.001; %position of theta2 (angle of second arm segment)
dtheta2=0; %first derivative of theta2 (angular velocity of second arm segment)
initialtheta=[theta1 dtheta1 theta2 dtheta2]; %vector of initial conditions for thetas
solution=ode45(@robdyn,range,initialtheta); %use MATLAB's built-in ODE solver
bravo=deval(solution,range); %interpolates the solution to the specified time values
plot(range,bravo(1,:),range,bravo(2,:),range,bravo(3,:),range,bravo(4,:),'linewidth',2);
legend('1st arm segment position','1st arm segment angular velocity','2nd arm segment position','2nd arm segment angular velocity','location','north');
xlabel('time (sec)','fontsize',14); title('Arm Position and Angular Velocity','fontsize',14);
grid on;
function dydt=robdyn(t,y) %this is the function for the robot's dynamics
m1=5; m2=3; p1=0.5; p2=0.5; I1=2; I2=1; L1=1; %given dynamics parameters
g=10; %gravitational acceleration constant
B1=10; B2=5; %friction coefficients
angle1=y(1); dangle1=y(2); angle2=y(3); dangle2=y(4);
U=[0 0]'; %vector of torques applied to the arm.
%first entry is the torque applied to the first arm segment and the
%second entry is the torque applied to the second arm segment
H11=m1*p1^(2)+I1+m2*(L1^(2)+p2^(2)+2*L1*p2*cos(angle2))+I2;
H12=m2*(p2^(2)+L1*p2*cos(angle2))+I2;
H21=m2*(p2^(2)+L1*p2*cos(angle2))+I2;
H22=m2*p2^(2)+I2;
H=[H11 H12; H21 H22]; %invertible inertia matrix
cmat=[dangle2 dangle1+dangle2; -dangle1 0];
ccoef=-m2*L1*p2*sin(angle2);
C=ccoef*cmat; %coriolis matrix
B=[B1 0; 0 B2]; %friction coefficient matrix
G1=(m1*p1+m2*L1)*g*cos(angle1)+m2*p2*g*cos(angle1+angle2);
G2=m2*p2*g*cos(angle1+angle2);
G=[G1 G2]'; %gravity vector
danglemat=[dangle1; dangle2];
%second derivative of theta1 = derivative of dtheta1 = angular
%acceleration of the first arm segment
ddtheta=H\(-C*danglemat-B*danglemat-G+U); %this is going to return a 2x1 vector
%this is the output of the function
dydt=[dangle1; dangle2; ddtheta]; %the output is 4x1. 2 rows plus concatenating ddtheta, which is 2x1
end


13 Comments
Answers (0)
See Also
Categories
Find more on Numerical Integration and Differential Equations in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


