Simplifying OMPL for CoppeliaSim (because sifting through the tutorials and forums is hard enough). I pronounce it as "complement" without the "c" (i.e., "OM-plee-ment").
This is a simple script that you can add to your CoppeliaSim project to perform path planning. This is especially compatible with function calls through the remote API provided by CoppeliaSim.
-
You will need to create a dummy object with a child script (feel free to call it what you want). In this child script, you should add everything found in the file
OMPLement.py.- Alternatively, in this repository, I provide a blank scene with a dummy object called
OMPLement. You can simply copy this object and paste it into your scene.
- Alternatively, in this repository, I provide a blank scene with a dummy object called
-
From your code, you will need to call the path planning function from the script using
sim.callScriptFunction, which requires:- the name of the function you wish to call from the child script (i.e.,
path_planning) - a script handle (from
sim.getScript) - any number of arguments needed for the function.
- the name of the function you wish to call from the child script (i.e.,
-
The
path_planningfunction requires a single (Python) dictionary (or its Pythonic equivalent in whatever language you are using) as an argument. This dictionary must have the following entries:robot- the name of the base of the robot in the CoppeliaSim scenegoal- the object handle of the target for the robot (perhaps for grasping)algorithm- The name of the motion planning algorithm/solver to use (by default,RRTstarwill be used); CoppeliaSim has several OMPL algorithms available.arm_prefix(optional) - this is the name prefix given to joints and tip of the end-effector for which motion planning is being used.- By default, the joints use the format
<robot_name>_joint<i>, where<robot>is the same string given as therobotargument above and<i>refers to the cardinality of the joints. - By default, the end-effector tip uses the format
<robot_name>_tip. - For best use, you should make it that both the tip and joints of the arm share the same prefix!
- By default, the joints use the format
num_attempts(default: 5) - the maximum number of iterations given for the solver to find a path plan. Each iteration by default tries to find a solution within 5 seconds. You should tune the arguments for thesim.computefunction (line 162) as you need (e.g., increasing computation time).
-
The function will return a list of configurations (referred to as
pathin this documentation).- If successful,
pathwill beNxJmatrix (or 2D list), whereNis the number of points in the path andJis the total number of joints. You would then need to iterate through this list while setting the configuration of the robot usingsim.setJointPositionfor each joint. - If no solution was found,
pathwill be empty.
- If successful,
Your code in Python for instance may look like the following:
ompl_script = sim.getScript(sim.scripttype_childscript , sim.getObject('/OMPLement'))
path = sim.callScriptFunction(
'path_planning',
ompl_script,
{
"robot": <some_robot_name>,
"goal": <target_obj>,
"algorithm": <algorithm>,
"num_attempts": <num>,
},
)
To deeply understand what's happening in the code, I would recommend going through the tutorials (yes, I know...) that are available online. There may be specific things you require for your own planning problem, so you should definitely consult the forums.
Feel free to reach out to me via email!