function
sysCall_init()
corout=
coroutine.create
(coroutineMain)
end
function
sysCall_actuation()
if
coroutine.status
(corout)~=
'dead'
then
local
ok,errorMsg=
coroutine.resume
(corout)
if
errorMsg
then
error
(
debug.traceback
(corout,errorMsg),2)
end
else
corout=
coroutine.create
(coroutineMain)
end
end
function
movCallback(config,vel,accel,handles)
for
i=1,#handles,1
do
if
sim.getJointMode(handles[i])==sim.jointmode_force
and
sim.isDynamicallyEnabled(handles[i])
then
sim.setJointTargetPosition(handles[i],config[i])
else
sim.setJointPosition(handles[i],config[i])
end
end
end
function
moveToConfig(handles,maxVel,maxAccel,maxJerk,targetConf,enable)
local
currentConf={}
for
i=1,#handles,1
do
currentConf[i]=sim.getJointPosition(handles[i])
targetConf[i]=targetConf[i]*
math.pi
/180
end
sim.moveToConfig(-1,currentConf,
nil
,
nil
,maxVel,maxAccel,maxJerk,targetConf,
nil
,movCallback,handles)
if
enable
then
sim.writeCustomDataBlock(gripperHandle,
'activity'
,
'on'
)
else
sim.writeCustomDataBlock(gripperHandle,
'activity'
,
'off'
)
end
end
function
coroutineMain()
modelBase=sim.getObjectHandle(sim.handle_self)
gripperHandle=sim.getObjectHandle(
'suctionPad'
)
modelName=sim.getObjectName(modelBase)
motorHandles = {}
for
i=1,4,1
do
motorHandles[i]=sim.getObjectHandle(
'MTB_axis'
..i)
end
local
vel=60
local
accel=10
local
jerk=10
local
maxVel={vel*
math.pi
/180,vel*
math.pi
/180,vel*
math.pi
/180,vel*
math.pi
/180}
local
maxAccel={accel*
math.pi
/180,accel*
math.pi
/180,accel*
math.pi
/180,accel*
math.pi
/180}
local
maxJerk={jerk*
math.pi
/180,jerk*
math.pi
/180,jerk*
math.pi
/180,jerk*
math.pi
/180}
moveToConfig(motorHandles,maxVel,maxAccel,maxJerk,{0,0,0,0},
true
)
moveToConfig(motorHandles,maxVel,maxAccel,maxJerk,{0,0,1.9,0},
true
)
moveToConfig(motorHandles,maxVel,maxAccel,maxJerk,{0,0,-1.9,0},
true
)
moveToConfig(motorHandles,maxVel,maxAccel,maxJerk,{-160,-43.5,0,203.5},
false
)
moveToConfig(motorHandles,maxVel,maxAccel,maxJerk,{160,43.5,0,203.5},
false
)
moveToConfig(motorHandles,maxVel,maxAccel,maxJerk,{160,43.5,1.90,-203.5},
true
)
moveToConfig(motorHandles,maxVel,maxAccel,maxJerk,{160,43.5,-1.90,-203.5},
true
)
end