-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathloadRobotBody.m
142 lines (131 loc) · 5.74 KB
/
loadRobotBody.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
function [robot, arm_eef_name, hand_name] = loadRobotBody(robotname, handType, handRanges)
if nargin<2
handType = zeros(1,6); % 0 - no dof, 1:dof at XYZXrYrZr axis
if nargin < 1
robotname = 'kukaIiwa14'; % universalUR5 % kukaIiwa14 % frankaEmikaPanda
end
end
switch robotname
case 'universalUR5'
robot = importrobot('universalUR5.urdf', 'DataFormat', 'row');
case 'universalUR10'
robot = importrobot('universalUR10.urdf', 'DataFormat', 'row');
case 'kinovaMicoM1N4S200'
robot = importrobot('kinovaMicoM1N4S200.urdf', 'DataFormat', 'row');
removeBody(robot, 'm1n4s200_link_finger_1'); % removing gripper finger 1 joint
removeBody(robot, 'm1n4s200_link_finger_2'); % removing gripper finger 2 joint
case 'wam7'
robot = importrobot('data/armConfigs data/WAM data/barrett_model/robots/wam7.urdf', 'DataFormat', 'row');
case 'wam4'
robot = importrobot('data/armConfigs data/WAM data/barrett_model/robots/wam7.urdf', 'DataFormat', 'row');
robot0 = copy(robot);
removeBody(robot0, 'wam/wrist_yaw_link');
newBody = rigidBody('wam/eef');
newBody.Joint = rigidBodyJoint('wam/eef_fix','fixed');
setFixedTransform(newBody.Joint, robot.Bodies{6}.Joint.JointToParentTransform);
addBody(robot0, newBody, robot.Bodies{5}.Name);
robot = copy(robot0);
otherwise
robot = loadrobot(robotname,'DataFormat','row');
end
robot0 = copy(robot);
%%% Returning robot_eef_name
if strcmp(robotname, 'frankaEmikaPanda')
arm_eef_name = robot.BodyNames{9};
else
arm_eef_name = robot.BodyNames{end};
end
hand_name = arm_eef_name;
hand_exist_flag = 0;
%%% Adding a hand based on handType
if handType(1)==1
newBody = rigidBody('handX');
newBody.Joint = rigidBodyJoint('hand_jointX','prismatic');
newBody.Joint.JointAxis = [1 0 0];
newBody.Joint.PositionLimits = [-handRanges(1), handRanges(1)];
if hand_exist_flag == 0
newJointTransform = eye(4);
newJointTransform(3,4) = 0.1; % hand is 0.1m above arm eef
setFixedTransform(newBody.Joint, newJointTransform);
hand_exist_flag = 1;
end
addBody(robot0, newBody, hand_name);
hand_name = newBody.Name;
end
if handType(2)==1
newBody = rigidBody('handY');
newBody.Joint = rigidBodyJoint('hand_jointY','prismatic');
newBody.Joint.JointAxis = [0 1 0];
newBody.Joint.PositionLimits = [-handRanges(2), handRanges(2)];
if hand_exist_flag == 0
newJointTransform = eye(4);
newJointTransform(3,4) = 0.1; % hand is 0.1m above arm eef
setFixedTransform(newBody.Joint, newJointTransform);
hand_exist_flag = 1;
end
addBody(robot0, newBody, hand_name);
hand_name = newBody.Name;
end
if handType(3)==1
newBody = rigidBody('handZ');
newBody.Joint = rigidBodyJoint('hand_jointZ','prismatic');
newBody.Joint.JointAxis = [0 0 1];
newBody.Joint.PositionLimits = [-handRanges(3), handRanges(3)];
if hand_exist_flag == 0
newJointTransform = eye(4);
newJointTransform(3,4) = 0.1; % hand is 0.1m above arm eef
setFixedTransform(newBody.Joint, newJointTransform);
hand_exist_flag = 1;
end
addBody(robot0, newBody, hand_name);
hand_name = newBody.Name;
end
if handType(4)==1
newBody = rigidBody('handXr');
newBody.Joint = rigidBodyJoint('hand_jointXR','revolute');
newBody.Joint.JointAxis = [1 0 0];
newBody.Joint.PositionLimits = [-handRanges(4), handRanges(4)];
if hand_exist_flag == 0
newJointTransform = eye(4);
newJointTransform(3,4) = 0.1; % hand is 0.1m above arm eef
setFixedTransform(newBody.Joint, newJointTransform);
hand_exist_flag = 1;
end
addBody(robot0, newBody, hand_name);
hand_name = newBody.Name;
end
if handType(5)==1
newBody = rigidBody('handYr');
newBody.Joint = rigidBodyJoint('hand_jointYR','revolute');
newBody.Joint.JointAxis = [0 1 0];
newBody.Joint.PositionLimits = [-handRanges(5), handRanges(5)];
if hand_exist_flag == 0
newJointTransform = eye(4);
newJointTransform(3,4) = 0.1; % hand is 0.1m above arm eef
setFixedTransform(newBody.Joint, newJointTransform);
hand_exist_flag = 1;
end
addBody(robot0, newBody, hand_name);
hand_name = newBody.Name;
end
if handType(6)==1
newBody = rigidBody('handZr');
newBody.Joint = rigidBodyJoint('hand_jointZR','revolute');
newBody.Joint.JointAxis = [0 0 1];
newBody.Joint.PositionLimits = [-handRanges(6), handRanges(6)];
if hand_exist_flag == 0
newJointTransform = eye(4);
newJointTransform(3,4) = 0.1; % hand is 0.1m above arm eef
setFixedTransform(newBody.Joint, newJointTransform);
end
addBody(robot0, newBody, hand_name);
hand_name = newBody.Name;
end
robot = copy(robot0);
robot.Gravity = [0 0 -9.81]; % need for torque calculations
env = {collisionBox(0.3, 0.3, 0.01)}; % default collision object (platform under robot)
env{1}.Pose(3, end) = -0.01;
show(robot, "Visuals","on", "Collisions","off");
hold on
show(env{1});
end