Contents
clc
clear
close all
RDK = Robolink;
path = RDK.getParam('PATH_LIBRARY');
RDK.AddFile([path, 'Example-06.b-Pick and place 2 tables.rdk']);
fprintf('Available items in the station:\n');
disp(RDK.ItemList(-1, 1));
program = RDK.Item('Pick and place', RDK.ITEM_TYPE_PROGRAM);
program.RunProgram();
Available items in the station:
Columns 1 through 3
{'Example 1 - Pic…'} {'ABB IRB 1600-8/…'} {'ABB IRB 1600-8/…'}
Columns 4 through 8
{'Tool'} {'Table 1'} {'Approach'} {'Target b1'} {'Target b2'}
Columns 9 through 13
{'Target b3'} {'Target b4'} {'Target b5'} {'base'} {'ball 1'}
Columns 14 through 18
{'ball 2'} {'ball 3'} {'ball 4'} {'ball 5'} {'Table 2'}
Columns 19 through 21
{'base'} {'Pick and place'} {'Replace objects'}
Retrieving objects from the station and modifying them
robot = RDK.Item('ABB IRB 1600-8/1.45', RDK.ITEM_TYPE_ROBOT);
fprintf('Robot selected:\t%s\n', robot.Name());
robot.setVisible(1);
frameref = robot.Parent();
fprintf('Robot reference selected:\t%s\n', frameref.Name());
object = RDK.Item('base', RDK.ITEM_TYPE_OBJECT);
fprintf('Object selected:\t%s\n', object.Name());
ball = RDK.Item('ball');
fprintf('Ball selected:\t%s\n', ball.Name());
frametable = RDK.Item('Table 1', RDK.ITEM_TYPE_FRAME);
fprintf('Table selected:\t%s\n', frametable.Name());
tool = RDK.Item('Tool', RDK.ITEM_TYPE_TOOL);
fprintf('Tool selected:\t%s\n', tool.Name());
target1 = RDK.Item('Target b1', RDK.ITEM_TYPE_TARGET);
fprintf('Target 1 selected:\t%s\n', target1.Name());
target2 = RDK.Item('Target b3', RDK.ITEM_TYPE_TARGET);
fprintf('Target 2 selected:\t%s\n', target2.Name());
Robot selected: ABB IRB 1600-8/1.45
Robot reference selected: ABB IRB 1600-8/1.45 Base
Object selected: base
Ball selected: ball 1
Table selected: Table 1
Tool selected: Tool
Target 1 selected: Target b1
Target 2 selected: Target b3
How to generate a robot program
tic()
while 1
item = RDK.Item('macro');
if item.Valid() == 0
break
end
item.Delete();
end
jhome = [0, 0, 0, 0, 30, 0];
robot.setJoints(jhome);
RDK.Render(0);
Htcp = tool.PoseTool();
ref = RDK.AddFrame('Frame macro', frameref);
Hframe = transl(750, 250, 500) * roty(pi / 2) * rotz(pi);
ref.setPose(Hframe);
robot.setPoseFrame(ref);
robot.setPoseTool(Htcp);
Hhome = inv(Hframe) * robot.SolveFK(jhome) * Htcp;
prog = RDK.AddProgram('Prog macro');
target = RDK.AddTarget('Home', ref, robot);
target.setAsJointTarget();
target.setJoints(jhome)
prog.MoveJ(target);
angleY = 0;
for dy = 600:-100:100
targetname = sprintf('Target TY=%i RY=%i', dy, angleY);
target = RDK.AddTarget(targetname, ref, robot);
pose = transl(0, dy, 0);
pose(1:3, 1:3) = Hhome(1:3, 1:3);
pose = pose * roty(angleY * pi / 180);
target.setPose(pose);
prog.MoveL(target);
angleY = angleY + 20;
end
RDK.Render(1);
prog.RunProgram();
while robot.Busy()
pause(1);
fprintf('Waiting for the robot to finish...\n');
end
fprintf('Running the program again...\n');
prog.RunProgram();
Waiting for the robot to finish...
Running the program again...
How to change the parent that an item is attached to
Htarget = target1.Pose();
target1.setParentStatic(frameref);
target1.setPose(Htarget);
target2.setParent(frameref);
childs = frametable.Childs();
for i = 1:numel(childs)
name = childs{i}.Name();
newname = [name, ' modified'];
visible = childs{i}.Visible();
childs{i}.setName(newname);
fprintf('%s %i\n', newname, visible);
end
Approach modified 1
Target b2 modified 1
Target b4 modified 1
Target b5 modified 1
base modified 1
ball 1 modified 1
ball 2 modified 1
ball 3 modified 1
How to Attach/Detach an object to the robot tool
attached = tool.AttachClosest();
if attached.Valid()
attachedname = attached.Name();
fprintf('Attached: %s\n', attachedname);
else
fprintf('No object is close enough\n');
end
pause(2);
tool.DetachAll();
fprintf('Detached all objects\n');
No object is close enough
Detached all objects
How to scale an object and how to detect collisions
RDK.Item('Replace objects', RDK.ITEM_TYPE_PROGRAM).RunProgram();
j1 = [-100, -50, -50, -50, -50, -50];
j2 = [100, 50, 50, 50, 50, 50];
collision = robot.MoveJ_Test(j1, j2, 1);
disp(collision)
pairs = RDK.Collisions();
fprintf('Pairs collided: %i\n', pairs);
object.Scale([10, 10, 0.5]);
p1 = [1000; 0; 8000];
p2 = [1000; 0; 0];
[collision, itempicked, xyz] = RDK.Collision_Line(p1, p2);
if collision
fprintf('Line from p1 to p2 collides with %s\n', itempicked.Name());
ball.Copy();
newball = RDK.Paste();
newball.setPose(transl(xyz(1), xyz(2), xyz(3)));
newball.Scale(0.5);
newball.Recolor([1 0 0]);
end
1
Pairs collided: 1
Line from p1 to p2 collides with base modified
How to move the robot programmaticall without creating a program
RDK.Item('Replace objects', RDK.ITEM_TYPE_PROGRAM).RunProgram();
fprintf('Moving by target item...\n');
robot.setPoseFrame(frametable);
RDK.setSimulationSpeed(10);
for i = 1:2
robot.setSpeed(10000, 1000);
robot.MoveJ(target1);
robot.setSpeed(100, 200);
robot.MoveL(target2);
end
fprintf('Moving by joints...\n');
J1 = [0, 0, 0, 0, 50, 0];
J2 = [40, 30, -30, 0, 50, 0];
for i = 1:2
robot.MoveJ(J1);
robot.MoveL(J2);
end
fprintf('Moving by pose...\n');
H1 = [-0.492404, -0.642788, -0.586824, -101.791308;
-0.413176, 0.766044, -0.492404, 1265.638417;
0.766044, 0.000000, -0.642788, 117.851733;
0.000000, 0.000000, 0.000000, 1.000000];
H2 = [-0.759717, -0.280123, -0.586823, -323.957442;
0.060192, 0.868282, -0.492405, 358.739694;
0.647462, -0.409410, -0.642787, 239.313006;
0.000000, 0.000000, 0.000000, 1.000000];
for i = 1:2
robot.MoveJ(H1);
robot.MoveL(H2);
end
Moving by target item...
Moving by joints...
Moving by pose...
Calculate forward and inverse kinematics of a robot
fprintf('Current robot joints:\n');
joints = robot.Joints();
disp(joints);
fprintf('Calculated pose for current joints:\n');
H_tcp_wrt_frame = robot.SolveFK(joints);
disp(H_tcp_wrt_frame);
fprintf('Calculated robot joints from pose:\n');
joints2 = robot.SolveIK(H_tcp_wrt_frame);
disp(joints2);
fprintf('All solutions available for the selected position:\n');
joints3_all = robot.SolveIK_All(H_tcp_wrt_frame);
disp(joints3_all);
RDK.ShowSequence(joints3_all);
pause(1);
joints4 = robot.SolveIK(H_tcp_wrt_frame * transl(0, 0, -100));
robot.setJoints(joints4);
Current robot joints:
-56.8091 -22.9201 33.5814 47.6220 54.6902 -104.7797
Calculated pose for current joints:
-0.5868 -0.2801 0.7597 305.0477
-0.4924 0.8683 -0.0602 -394.7465
-0.6428 -0.4094 -0.6475 978.1476
0 0 0 1.0000
Calculated robot joints from pose:
-56.8091 -22.9201 33.5814 47.6220 54.6902 -104.7797
All solutions available for the selected position:
Columns 1 through 7
-56.8091 -56.8091 123.1909 123.1909 -56.8091 -56.8091 123.1909
-22.9201 -22.9201 -3.2918 -3.2918 -22.9201 -22.9201 -3.2918
33.5814 33.5814 -192.6814 -192.6814 33.5814 33.5814 -192.6814
47.6220 -132.3780 -129.3428 50.6572 47.6220 -132.3780 -129.3428
54.6902 -54.6902 51.2124 -51.2124 54.6902 -54.6902 51.2124
-104.7797 75.2203 -109.8131 70.1869 255.2203 -284.7797 250.1869
10.0000 10.0000 10.0000 10.0000 0 0 0
0.0000 180.0000 226.2628 226.2628 360.0000 180.0000 354.9666
Column 8
123.1909
-3.2918
-192.6814
50.6572
-51.2124
-289.8131
0
226.2628
Example to add targets to a program and use circular motion
RDK = Robolink();
robot = RDK.Item('', RDK.ITEM_TYPE_ROBOT);
pose0 = robot.Pose();
prog = RDK.AddProgram('TestProgram');
target0 = RDK.AddTarget('First Point');
target0.setAsCartesianTarget();
target0.setPose(pose0);
prog.MoveL(target0);
pose1 = pose0 * transl(50, 0, 0);
pose2 = pose0 * transl(50, 50, 0);
target1 = RDK.AddTarget('Second Point');
target1.setAsCartesianTarget();
target1.setPose(pose1);
target2 = RDK.AddTarget('Third Point');
target2.setAsCartesianTarget();
target2.setPose(pose2);
prog.MoveC(target1, target2)
Rail tests:
RDK = Robolink();
robot = RDK.Item('', RDK.ITEM_TYPE_ROBOT);
robot = robot.getLink(RDK.ITEM_TYPE_ROBOT);
disp(robot.Name());
robot.setJointLimits([-180; -180; -180; -180; -180; -180; 0], [+180; +180; +180; +180; +180; +180; 5000]);
[lower_limit, upper_limit] = robot.JointLimits();
disp(lower_limit)
disp(upper_limit)
joints = robot.JointsHome();
config = robot.JointsConfig(joints);
disp(config)
all_solutions = robot.SolveIK_All(robot.SolveFK(robot.Joints()));
disp(all_solutions)
ABB IRB 1600-8/1.45
-180
-180
-180
-180
-180
-180
180
180
180
180
180
180
0
0
0
0
Columns 1 through 7
-64.9691 -64.9691 -64.9691 -64.9691 115.0309 115.0309 115.0309
-27.6557 -27.6557 76.9661 76.9661 -89.0434 -89.0434 1.3654
29.7138 29.7138 150.2862 150.2862 11.0876 11.0876 168.9124
46.2971 -133.7029 103.8452 -76.1548 -109.3352 70.6648 -130.9223
66.4849 -66.4849 136.9424 -136.9424 135.3704 -135.3704 61.3200
-103.9353 76.0647 27.3638 -152.6362 -17.5214 162.4786 -110.2446
10.0000 10.0000 10.0000 10.0000 10.0000 10.0000 10.0000
0.0000 180.0000 131.2992 203.4274 180.0000 266.4139 180.0000
Column 8
115.0309
1.3654
168.9124
49.0777
-61.3200
69.7554
10.0000
180.0000