Hi!
So I am doing a final year project and I have been asked to integrate my simulation with Python somewhat. My simulation is a pretty basic pick and place experiment using IK.
I'm sorry, I know this is a very broad question but I'm just looking for some relatively simple suggestions on what I could do with Python? Any suggestions would be welcome!
Thanks a mill!
Python API Recommendations
Re: Python API Recommendations
Did you read about Remote API?
Re: Python API Recommendations
Hi,
Sorry i didn't see the reply until now!
Yes, so this is what I have so far:
From my python script I connect to CoppeliaSim, start the simulation, and import a set of fingers and attach them to the robot.
The below threaded child script controlls my robots movements:
(I am moving an object 100 times and using a force sensor to measure the number of successful movements)
However, I now need to be fit to start this movement from a call in my python script as my robot must remain still when the simulation starts and await attachment of the fingers, then complete this movement and the final step is to send the number of SUCCESSES (successCnt) to python so it can determine whether a second set of fingers is needed? Does this make sense?
So my question now is how can I start, or is it possible to start, a function sysCall_threadmain() from a python script?
Thank you very much!
Sorry i didn't see the reply until now!
Yes, so this is what I have so far:
From my python script I connect to CoppeliaSim, start the simulation, and import a set of fingers and attach them to the robot.
The below threaded child script controlls my robots movements:
(I am moving an object 100 times and using a force sensor to measure the number of successful movements)
However, I now need to be fit to start this movement from a call in my python script as my robot must remain still when the simulation starts and await attachment of the fingers, then complete this movement and the final step is to send the number of SUCCESSES (successCnt) to python so it can determine whether a second set of fingers is needed? Does this make sense?
So my question now is how can I start, or is it possible to start, a function sysCall_threadmain() from a python script?
Thank you very much!
Code: Select all
function sysCall_threadmain()
for loop=1,100,1 do
-- Make sure gripper is open
setGripperData(true)
-- Follow the InterimPickupPath
sim.followPath(targetDummy,InterimPickupPath,3,0,vel,accel)
-- Follow the PickupPath
sim.followPath(targetDummy,pickupPath,3,0,vel,accel)
-- Get the force on the LH Force Sensor and print it
r,f,torque=sim.readForceSensor(LHForceSensor)
print(f[2])
-- Connection Process
sim.wait(2)
setGripperData(false)
sim.wait(5)
-- Follow back the pickup path
sim.followPath(targetDummy,pickupPath,3,1,-vel,-accel)
-- Follow CentrePath
sim.followPath(targetDummy,CentrePath,3,0,vel,accel)
sim.wait(0.5)
r,f,torque=sim.readForceSensor(LHForceSensor)
print(f[2])
-- Follow releasePath
sim.followPath(targetDummy,releasePath,3,0,vel,accel)
-- Wait 2 seconds
sim.wait(2)
-- Get the force on the LH Force Sensor and print it
r,f,torque=sim.readForceSensor(LHForceSensor)
r1,f1,torque1=sim.readForceSensor(RHForceSensor)
print(f[2])
print(f1[2])
AbsoluteYForce = math.abs(f1[2])
-- If the force in the y direction is greater than 1 (signifies successful grip)
-- Count as a successful grip
if AbsoluteYForce>1 then
successCnt=successCnt+1
end
print(successCnt, loop)
-- Disconnect / open the gripper
sim.wait(1)
setGripperData(true)
-- Wait 2 seconds
sim.wait(5)
-- Follow releasePath
sim.followPath(targetDummy,releasePath,3,1,-vel,-accel)
sim.wait(1)
-- Return the ObjectToBePicked to the starting position to run again
sim.setObjectPosition(ObjectToBePicked,-1,ObjectStartingPosition)
sim.setObjectOrientation(ObjectToBePicked,-1,ObjectStartingOrientation)
-- Follow InterimReleasePath
sim.followPath(targetDummy,InterimReleasePath,3,1,-vel,-accel)
end
sim.stopSimulation()
end
Re: Python API Recommendations
Hi,
I put a
This is working for me anyway, but if you have any better suggestions, that would be great, but I think this should do.
Thanks!
I put a
sim.waitForSignal
at the start of the function sysCall_threadmain() and then set this signal elsewhere so I can give it this signal when it suits me.This is working for me anyway, but if you have any better suggestions, that would be great, but I think this should do.
Thanks!