-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathRobotModel.lua
More file actions
200 lines (173 loc) · 6.04 KB
/
RobotModel.lua
File metadata and controls
200 lines (173 loc) · 6.04 KB
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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
local ffi = require 'ffi'
local torch = require 'torch'
local moveit = require 'moveit.env'
local utils = require 'moveit.utils'
local ros = require 'ros'
local std = ros.std
--- LUA wrapper for moveit RobotModel environment
-- dependency to tourch.ros
-- @classmod RobotModel
local RobotModel = torch.class('moveit.RobotModel', moveit)
local f
function init()
local RobotModel_method_names = {
"new",
"delete",
"release",
"getName",
"getModelFrame",
"isEmpty",
"printModelInfo",
"getRootJointName",
"getEndEffectorNames",
"getEndEffectorParentGroups",
"getJointModelGroupNames",
"getJointModelSubGroupNames",
"getJointModelNames",
"getActiveJointNames",
"getVariableNames",
"getVariableIndex",
"getGroupJointNames",
"getAttachedEndEffectorNames",
"getGroupEndEffectorTipNames",
"getGroupEndEffectorName",
"getEndEffectorLinkName",
"getVariableBounds"
}
f = utils.create_method_table("moveit_RobotModel_", RobotModel_method_names)
end
init()
function RobotModel:__init()
self.o = f.new()
end
function RobotModel:cdata()
return self.o
end
function RobotModel:release()
f.release(self.o)
end
function RobotModel:getName()
return ffi.string(f.getName(self.o))
end
function RobotModel:getModelFrame()
return ffi.string(f.getModelFrame(self.o))
end
function RobotModel:isEmpty()
return f.isEmpty(self.o)
end
function RobotModel:printModelInfo()
local s = std.String()
f.printModelInfo(self.o, s:cdata())
return s
end
function RobotModel:getRootJointName()
return ffi.string(f.getRootJointName(self.o))
end
---Get complete set of End Effector names defined in srdf.
--@tparam[opt] moveit.Strings names
--@treturn moveit.Strings
function RobotModel:getEndEffectorNames(strings)
strings = strings or std.StringVector()
f.getEndEffectorNames(self.o, strings:cdata())
return strings
end
function RobotModel:getEndEffectorParentGroups()
local parent_move_group_names = std.StringVector()
local move_group_link_names = std.StringVector()
f.getEndEffectorParentGroups(self.o, parent_move_group_names:cdata(), move_group_link_names:cdata())
return parent_move_group_names, move_group_link_names
end
function RobotModel:getJointModelGroupNames(strings)
strings = strings or std.StringVector()
f.getJointModelGroupNames(self.o, strings:cdata())
return strings
end
function RobotModel:getJointModelSubGroupNames(group_name, strings)
assert(group_name, '[nil-error] group name needs to be set')
assert(torch.type(group_name) == 'string', string.format('[type-error] group name need to be a [string] but is type of [%s]', torch.type(group_name)))
strings = strings or std.StringVector()
f.getJointModelSubGroupNames(self.o, group_name, strings:cdata())
return strings
end
function RobotModel:getJointModelNames(strings)
strings = strings or std.StringVector()
f.getJointModelNames(self.o, strings:cdata())
return strings
end
---Get the joint names of the variables that make up this state without mimic or fixed joints.
--@tparam[opt] moveit.Strings names
--@treturn moveit.Strings
function RobotModel:getActiveJointNames(strings)
strings = strings or std.StringVector()
f.getActiveJointNames(self.o, strings:cdata())
return strings
end
---Get the joint names of the variables that make up this state with mimic.
--@tparam[opt] moveit.Strings names
--@treturn moveit.Strings
function RobotModel:getVariableNames(strings)
strings = strings or std.StringVector()
f.getVariableNames(self.o, strings:cdata())
return strings
end
function RobotModel:getVariableIndex(name)
return f.getVariableIndex(self.o,name) + 1 --compensate c++ vslua indexing
end
function RobotModel:getGroupJointNames(group_name, strings)
assert(group_name, '[nil-error] group name needs to be set')
assert(torch.type(group_name) == 'string', string.format('[type-error] group name need to be a [string] but is type of [%s]', torch.type(group_name)))
strings = strings or std.StringVector()
f.getGroupJointNames(self.o, group_name, strings:cdata())
return strings
end
function RobotModel:getEndEffectorNames(strings)
strings = strings or std.StringVector()
f.getEndEffectorNames(self.o, strings:cdata())
return strings
end
function RobotModel:getAttachedEndEffectorNames(group_name, strings)
strings = strings or std.StringVector()
assert(group_name, '[nil-error] group name needs to be set')
assert(torch.type(group_name) == 'string', string.format('[type-error] group name need to be a [string] but is type of [%s]', torch.type(group_name)))
f.getAttachedEndEffectorNames(self.o, group_name, strings:cdata())
print('debug: ', strings)
if strings then
return strings
else
return std.StringVector()
end
end
function RobotModel:getGroupEndEffectorTipNames(group_name, strings)
strings = strings or std.StringVector()
local suc = f.getGroupEndEffectorTipNames(self.o, group_name, strings:cdata())
return strings, suc
end
function RobotModel:getGroupEndEffectorName(group_name)
assert(group_name, '[nil-error] group name needs to be set')
assert(torch.type(group_name) == 'string', string.format('[type-error] group name need to be a [string] but is type of [%s]', torch.type(group_name)))
local output = std.String()
local suc = f.getGroupEndEffectorName(self.o, group_name, output:cdata())
if suc then
return output:get(), suc
else
return '', suc
end
end
function RobotModel:getEndEffectorLinkName(eef_name)
assert(eef_name, '[nil-error] group name needs to be set')
assert(torch.type(eef_name) == 'string', string.format('[type-error] eef_name need to be a [string] but is type of [%s]', torch.type(eef_name)))
local output = std.String()
local suc = f.getEndEffectorLinkName(self.o, eef_name, output:cdata())
if suc then
return output:get(), suc
else
return '', suc
end
end
function RobotModel:getVariableBounds()
local pos_lim = torch.DoubleTensor()
local vel_lim = torch.DoubleTensor()
local acc_lim = torch.DoubleTensor()
f.getVariableBounds(self.o, pos_lim:cdata(),vel_lim:cdata(), acc_lim:cdata())
return pos_lim, vel_lim, acc_lim
end