Contents
clc
clear
close all
RL = Robolink;
path = RL.getParam('PATH_LIBRARY');
RL.AddFile([path,'Example 1 - Pick and place.rdk']);
RL.ItemList();
program = RL.Item('Pick and place');
program.RunProgram();
1 -> Example 1 - Pick and place
2 -> ABB IRB 1600-8/1.45 Base
3 -> ABB IRB 1600-8/1.45
4 -> Tool
5 -> Table 1
6 -> Approach
7 -> Target b1
8 -> Target b2
9 -> Target b3
10 -> Target b4
11 -> Target b5
12 -> base
13 -> ball 1
14 -> ball 2
15 -> ball 3
16 -> ball 4
17 -> ball 5
18 -> Table 2
19 -> base
20 -> Pick and place
21 -> Replace objects
Retrieving objects from the station and modifying them
robot = RL.Item('ABB IRB 1600-8/1.45');
fprintf('Robot selected:\t%s\n', robot.Name());
robot.setVisible(1);
frameref = robot.Parent();
fprintf('Robot reference selected:\t%s\n', frameref.Name());
object = RL.Item('base');
fprintf('Object selected:\t%s\n', object.Name());
ball = RL.Item('ball');
fprintf('Ball selected:\t%s\n', ball.Name());
frametable = RL.Item('Table 1');
fprintf('Table selected:\t%s\n', frametable.Name());
tool = RL.Item('Tool');
fprintf('Tool selected:\t%s\n', tool.Name());
target1 = RL.Item('Target b1');
fprintf('Target 1 selected:\t%s\n', target1.Name());
target2 = RL.Item('Target b3');
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 = RL.Item('macro');
if item.Valid() == 0
break
end
item.Delete();
end
jhome = [ 0, 0, 0, 0, 30, 0];
robot.setJoints(jhome);
RL.Render(0);
Htcp = tool.Htool();
ref = RL.AddFrame('Frame macro', frameref);
Hframe = transl(750,250,500)*roty(pi/2)*rotz(pi);
ref.setPose(Hframe);
robot.setFrame(ref);
robot.setTool(tool);
Hhome = inv(Hframe)*robot.SolveFK(jhome)*Htcp;
prog = RL.AddProgram('Prog macro');
target = RL.AddTarget('Home', ref, robot);
target.setAsJointTarget();
target.setJoints(jhome)
prog.addMoveJ(target);
angleY = 0;
for dy=600:-100:100
targetname = sprintf('Target TY=%i RY=%i',dy,angleY);
target = RL.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.addMoveL(target);
angleY = angleY + 20;
end
RL.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...
Waiting for the robot to finish...
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
ball 4 modified 1
ball 5 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');
Attached: base modified
Detached all objects
How to scale an object and how to detect collisions
RL.Item('Replace objects').RunProgram();
j1 = [-100, -50, -50, -50, -50, -50];
j2 = [100, 50, 50, 50, 50, 50];
collision = robot.MoveJ_Collision(j1, j2, 1);
disp(collision)
pairs = RL.Collision();
fprintf('Pairs collided: %i\n', pairs);
object.Scale([10, 10, 0.5]);
p1 = [1000; 0; 8000];
p2 = [1000; 0; 0];
[collision, itempicked, xyz] = RL.Collision_Line(p1, p2);
if itempicked.Valid()
fprintf('Line from p1 to p2 collides with %s\n', itempicked.Name());
ball.Copy();
newball = RL.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
RL.Item('Replace objects').RunProgram();
fprintf('Moving by target item...\n');
robot.setFrame(frametable);
RL.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);
RL.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.9202
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.9202
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.9202 -22.9202 -3.2918 -3.2918 -22.9202 -22.9202 -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
Column 8
123.1909
-3.2918
-192.6814
50.6572
-51.2124
-289.8131