I wrote a code in the threaded script. The general situation is to let the robot arm move according to the trajectory. When the sensor detects this robot arm, I hope that the robot arm will immediately reduce the movement speed. My question is: the sensor senses the movement of the robotic arm, but the robotic arm still runs the entire trajectory after running at high speed; it can only run at low speed when it is refreshed next time.
Is it because "When a threaded child script's execution is still underway, it will not be launched a second time."?
In this scenario, the movement of the manipulator is controlled at different speeds, can it only pass through a non-threaded script?
Best Wishes
Shaoxiang
Code: Select all
function sysCall_threadmain()
-- Put some initialization code here
safetyStop= "0"
-- Get handles and postions of dummies
targetDummy = sim.getObjectHandle("Target")
idlePos = sim.getObjectPosition(targetDummy,-1)
idleOrient = sim.getObjectOrientation(targetDummy,-1)
pickupDummy = sim.getObjectHandle("pickupDummy")
dummyPos = sim.getObjectPosition(pickupDummy ,-1)
dummyOrient = sim.getObjectOrientation(pickupDummy ,-1)
-- Get release path handle
pickupPath = createPath(idlePos,idleOrient,dummyPos,dummyOrient)
-- Get handles and postions of dummies
releasePosHandle = sim.getObjectHandle("releasePos")
releasePos = sim.getObjectPosition(releasePosHandle,-1)
releaseOrient = sim.getObjectOrientation(releasePosHandle,-1)
-- Get release path handle
releasePath = createPath(idlePos,idleOrient,releasePos,releaseOrient)
-- Get handles and postions of dummies
putdown = sim.getObjectHandle("putdown")
putdownPos = sim.getObjectPosition(putdown,-1)
putdownOrient = sim.getObjectOrientation(putdown,-1)
-- Get release path handle
putdownPath = createPath(releasePos,releaseOrient,putdownPos,putdownOrient)
connector = sim.getObjectHandle("Connector")
manipVelocity=0.8
accel = 0.5
gripperActionTime = 1
-- Put your main loop here, e.g.:
while sim.getSimulationState()~=sim.simulation_advancing_abouttostop do
safetyStop = sim.getStringSignal("SafetyStop")
if safetyStop == "1" then
safetyStop=true
else
safetyStop=false
end
if not safetyStop then
sim.followPath(targetDummy,pickupPath,3,0,manipVelocity,accel)
sim.wait(1)
-- Connect the connector to pickupDummy
sim.setLinkDummy(connector,pickupDummy)
-- Set link type
sim.setObjectInt32Parameter(connector,sim.dummyintparam_link_type,sim.dummy_linktype_dynamics_loop_closure)
sim.followPath(targetDummy,pickupPath,3,1,-manipVelocity,-accel)
sim.followPath(targetDummy,releasePath,3,0,manipVelocity,accel)
sim.wait(gripperActionTime*1)
sim.followPath(targetDummy,putdownPath,3,0,manipVelocity,accel)
sim.wait(gripperActionTime*2)
-- Disconnect pickupDummy from connector
sim.setLinkDummy(connector,-1)
sim.wait(gripperActionTime*1)
sim.followPath(targetDummy,releasePath,3,1,-manipVelocity,-accel)
elseif safetyStop then
sim.followPath(targetDummy,releasePath,3,0,manipVelocity*0.1,accel*0.1)
sim.wait(gripperActionTime*1)
sim.followPath(targetDummy,putdownPath,3,0,manipVelocity*0.1,accel*0.1)
sim.wait(gripperActionTime*2)
-- Disconnect pickupDummy from connector
sim.setLinkDummy(connector,-1)
sim.wait(gripperActionTime*1)
sim.followPath(targetDummy,releasePath,3,1,-manipVelocity*0.1,-accel*0.1)
end
sim.switchThread()
end
end
function sysCall_cleanup()
-- Put some clean-up code here
end
-- See the user manual or the available code snippets for additional callback functions and details
function createPath(startPoint,startOrient,endPoint,endOrient)
-- Create Path Object
local path = sim.createPath(1)
-- Create buffer variables
local buffer = {startPoint[1],startPoint[2],startPoint[3],startOrient[1],startOrient[2],startOrient[3], 1,0,0,0,0,
endPoint[1],endPoint[2],endPoint[3],endOrient[1],endOrient[2],endOrient[3], 1,0,0,0,0}
-- Insert 2 control points (start and endpoint)
sim.insertPathCtrlPoints(path,0,0,2,buffer)
-- Return handle to path
return path
end