Skip to content

Commit 6963ae2

Browse files
committed
use more robust tagged ref handles to reference objects
1 parent ee248ed commit 6963ae2

File tree

2 files changed

+22
-16
lines changed

2 files changed

+22
-16
lines changed

Inverse Kinematics generator.lua

+10-6
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,12 @@ function generate()
314314
sim.setObjectPose(ikScript, {0, 0, 0, 0, 0, 0, 1}, robotModel)
315315
sim.setObjectInt32Param(ikScript, sim.objintparam_visibility_layer, 0)
316316
sim.setObjectInt32Param(ikScript, sim.objintparam_manipulation_permissions, 0)
317+
sim.setReferencedHandles(ikScript, {simBase}, 'ik.base')
318+
sim.setReferencedHandles(ikScript, {simTip}, 'ik.tip')
319+
sim.setReferencedHandles(ikScript, {simTarget}, 'ik.target')
320+
if jointGroup then
321+
sim.setReferencedHandles(ikScript, {jointGroup}, 'jointGroup')
322+
end
317323

318324
local scriptText = ''
319325
local function appendLine(...)
@@ -326,13 +332,11 @@ function generate()
326332
appendLine("function sysCall_init()")
327333
appendLine(" self = sim.getObject '.'")
328334
appendLine("")
329-
appendLine(" simBase = sim.getObject '%s'", sim.getObjectAliasRelative(simBase, ikScript, 1))
330-
appendLine(" simTip = sim.getObject '%s'", sim.getObjectAliasRelative(simTip, ikScript, 1))
331-
appendLine(" simTarget = sim.getObject '%s'", sim.getObjectAliasRelative(simTarget, ikScript, 1))
335+
appendLine(" simBase = sim.getReferencedHandle(self, 'ik.base')")
336+
appendLine(" simTip = sim.getReferencedHandle(self, 'ik.tip')")
337+
appendLine(" simTarget = sim.getReferencedHandle(self, 'ik.target')")
332338
if jointGroup then
333-
appendLine(
334-
" jointGroup = sim.getObject '%s'", sim.getObjectAliasRelative(jointGroup, ikScript, 1)
335-
)
339+
appendLine(" jointGroup = sim.getReferencedHandle(self, 'jointGroup')")
336340
appendLine(" simJoints = sim.getReferencedHandles(jointGroup)")
337341
end
338342
appendLine("")

Motion Planning generator.lua

+12-10
Original file line numberDiff line numberDiff line change
@@ -147,19 +147,18 @@ function generate()
147147
sim.removeObjects {existingMotionPlanning}
148148
end
149149

150-
local jointGroupPath = sim.getObjectAliasRelative(jointGroup, robotModel, 1)
151-
152150
local scriptText = ''
153151
local function appendLine(...)
154152
scriptText = scriptText .. string.format(...) .. '\n'
155153
end
156154
appendLine("sim = require 'sim'")
157155
appendLine("simOMPL = require 'simOMPL'")
158-
appendLine("robotConfigPath = require 'models.robotConfigPath-2'")
156+
appendLine("robotConfigPath = require 'models.robotConfigPath-3'")
159157
appendLine("")
160158
appendLine("function sysCall_init()")
159+
appendLine(" self = sim.getObject '.'")
161160
appendLine(" model = sim.getObject '::'")
162-
appendLine(" jointGroup = sim.getObject('%s', {proxy = model})", jointGroupPath)
161+
appendLine(" jointGroup = sim.getReferencedHandle(self, 'jointGroup')")
163162
appendLine(" joints = sim.getReferencedHandles(jointGroup)")
164163
appendLine("")
165164
appendLine(" robotCollection = sim.createCollection()")
@@ -205,7 +204,7 @@ function generate()
205204
appendLine('%s', " printf('solved: %s (%s)', solved, hasApproximateSolution() and 'approximate' or 'exact')")
206205
appendLine('%s', " printf('path: %d states', #path)")
207206
appendLine(" if solved then")
208-
appendLine(" robotConfigPath.create(path, model, '%s')", jointGroupPath)
207+
appendLine(" robotConfigPath.create(path, model, jointGroup)")
209208
appendLine(" end")
210209
appendLine("end")
211210

@@ -216,24 +215,27 @@ function generate()
216215
sim.setObjectPose(motionPlanningScript, {0, 0, 0, 0, 0, 0, 1}, robotModel)
217216
sim.setObjectInt32Param(motionPlanningScript, sim.objintparam_visibility_layer, 0)
218217
sim.setObjectInt32Param(motionPlanningScript, sim.objintparam_manipulation_permissions, 0)
218+
sim.setReferencedHandles(motionPlanningScript, {jointGroup}, 'jointGroup')
219219

220-
local startStateScript = sim.createScript(sim.scripttype_customization, [[require 'models.robotConfig_customization-2'
220+
local startStateScript = sim.createScript(sim.scripttype_customization, [[require 'models.robotConfig_customization-3'
221221
model = sim.getObject '::'
222-
jointGroupPath = ']] .. jointGroupPath .. "'")
222+
]])
223223
sim.setObjectAlias(startStateScript, 'StartState')
224224
sim.setObjectParent(startStateScript, motionPlanningScript, false)
225225
sim.setObjectPose(startStateScript, {0, 0, 0, 0, 0, 0, 1}, motionPlanningScript)
226226
sim.setObjectInt32Param(startStateScript, sim.objintparam_visibility_layer, 0)
227227
sim.setObjectInt32Param(startStateScript, sim.objintparam_manipulation_permissions, 0)
228-
local goalStateScript = sim.createScript(sim.scripttype_customization, [[require 'models.robotConfig_customization-2'
228+
sim.setReferencedHandles(startStateScript, {jointGroup}, 'jointGroup')
229+
local goalStateScript = sim.createScript(sim.scripttype_customization, [[require 'models.robotConfig_customization-3'
229230
model = sim.getObject'::'
230-
jointGroupPath = ']] .. jointGroupPath .. [['
231-
color = {0, 1, 0}]])
231+
color = {0, 1, 0}
232+
]])
232233
sim.setObjectAlias(goalStateScript, 'GoalState')
233234
sim.setObjectParent(goalStateScript, motionPlanningScript, false)
234235
sim.setObjectPose(goalStateScript, {0, 0, 0, 0, 0, 0, 1}, motionPlanningScript)
235236
sim.setObjectInt32Param(goalStateScript, sim.objintparam_visibility_layer, 0)
236237
sim.setObjectInt32Param(goalStateScript, sim.objintparam_manipulation_permissions, 0)
238+
sim.setReferencedHandles(goalStateScript, {jointGroup}, 'jointGroup')
237239

238240
sim.announceSceneContentChange()
239241

0 commit comments

Comments
 (0)