Robotic Arm Trajectory Animation Using Robotic Toolbox
41 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
I am trying to simulate a 3DoF robot arm using MATLAB robotic toolbox. I have created the robot arm however when i try to move the arm with a trajectory i get an error. Can someone explain what i am doing wrong?
This is the error i am getting. Conversion to double from struct is not possible.
Error in PneumaticRoboticArm (line 80)
qs(i,:) = qSol;
%%Robotic Arm,
pneumatic Muscles
L1 = 0.05;
L2 = 0.11;
L3 = 0.5;
L4 = 0.27;
%% Adding Base Frame No rotation
body1 = rigidBody('link 1');
joint1 = rigidBodyJoint('BaseFrame', 'fixed');
setFixedTransform(joint1,trvec2tform([0 0 0]));
body1.Joint = joint1;
robot = rigidBodyTree;
addBody(robot, body1, 'base');
show(robot)
%% joint 2 Yaw Rotation
body2 = rigidBody('link 2');
joint2 = rigidBodyJoint('YawJoint','revolute');
setFixedTransform(joint2, trvec2tform([L1,0,0]));
body2.Joint = joint2;
addBody(robot, body2, 'link 1');
show(robot)
%% Link 2 Joint 3 Pitch Rotation
body3 = rigidBody('link 3');
joint3 = rigidBodyJoint('PitchJoint1','revolute');
setFixedTransform(joint3, trvec2tform([L2, 0, 0]));
body3.Joint = joint3;
addBody(robot, body3, 'link 2');
show(robot)
%% Link 3 Joint 4 Pitch Rotation
body4 = rigidBody('link 4');
joint4 = rigidBodyJoint('PitchJoint2','revolute');
setFixedTransform(joint4, trvec2tform([L3, 0, 0]));
body4.Joint = joint4;
addBody(robot, body4, 'link 3');
show(robot)
% Adding end effector
body5 = rigidBody('endeffector');
joint5 = rigidBodyJoint('EndEffector','fixed');
setFixedTransform(joint5, trvec2tform([L4, 0, 0]));
body5.Joint = joint5;
addBody(robot, body5, 'link 4');
show(robot)
config = randomConfiguration(robot); % random q1,q2
tform = getTransform(robot,config,'endeffector','base')
%% Define The Trajectory
% Define a circle to be traced over the course of 10 seconds. This circle
% is in the _xy_ plane with a radius of 0.15.
t = (0:0.2:10)'; % Time
count = length(t);
center = [0.3 0.1 0];
radius = 0.15;
theta = t*(2*pi/t(end));
points = center + radius*[cos(theta) sin(theta) zeros(size(theta))];
%% inverse kinematics and moving on trajectory step by step
q0 = homeConfiguration(robot);
ndof = length(q0); % 2
qs = zeros(count, ndof); % time:51 steps
ik = inverseKinematics('RigidBodyTree', robot);
weights = [0, 0, 0, 1, 1, 0]; % Wx,Wy,Wz, X,Y,Z
endEffector = 'endeffector';
qInitial = q0; % home configuration as initial guess
for i = 1:count
point = points(i,:); % trajectories
qSol = ik(endEffector,trvec2tform(point),weights,qInitial);
qs(i,:) = qSol;
qInitial = qSol;
end
%% Animate The Solution
figure
show(robot,qs(1,:)');
view(2)
ax = gca;
ax.Projection = 'orthographic';
hold on
plot(points(:,1),points(:,2),'k')
axis([-0.1 0.7 -0.3 0.5])
framesPerSecond = 15;
r = rateControl(framesPerSecond);
fo
n b
r i = 1:count
show(robot,qs(i,:)','PreservePlot',false);
drawnow
waitfor(r);
0 Kommentare
Antworten (1)
Cam Salzberger
am 21 Dez. 2020
Hello Ahmetcan,
The configuration solution output of calling the inverseKinematics object defaults to being a struct. If you want a row vector, you need to call it with "DataFormat","row" name-value pairs.
The error message is pretty clear about what is going on at that line. To debug, you can inspect your variables, see which ones aren't looking like what you would expect, and then go to where they were created to figure out why they are like that.
-Cam
0 Kommentare
Siehe auch
Kategorien
Mehr zu Inverse Kinematics finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!