Using the Inverse Kinematics Generator and Motion Planning Generator add-ons

by federico, 2023-04-05 10:30

coppeliasim inverse-kinematics motion-planning

Introduction

Since CoppeliaSim V4.5.1, some new add-ons have been introduced, to automate and simplify some tasks concerning the setup of inverse kinematics and motion planning for a generic robot.

Traditionally, these functionalities are exposed via plugins as functions that can be called by embedded scripts (or remote scripts as well).

Concepts

A robot can be viewed as a kinematic chain, extending from the robot's base to its tip. Specifically, the set of joints in a kinematic chain is of primary importance.

In general, we might be interested only in a subset of joints, so we can define a Joint Group to specify which joints of the robot model we want to use for a particular inverse kinematics or motion planning task.

For the inverse kinematics task, the add-on will generate a script that can run during simulation and/or outside simulation, solving IK in the traditional way, i.e. bringing the tip towards the target. The functionality can be used interactively via UI, by moving the target object around with the move tool.

For the motion planning task, the add-on will generate a script for the task, and also two Robot State objects, respectively for the start and the goal states, that are used both for storing the robot state (i.e. the joint configuration vector) and for visualizing it and editing it.

In the next section the usage of these add-ons will be demonstrated by example, adding IK and Motion Planning to a robot arm.

Preparation

Begin with an empty scene and add the ABB IRB 140 robot from the model library, located under (located in robots/non-mobile).

Right click IRB140 in the scene hierarchy and go to Edit > Remote > Associated child script

Define the Joint Group

With the robot selected, go to Modules > Kinematics > Define Joint Group.... By selecting the robot, we are including all the joints found in the robot model. Alternatively, individual joints can be selected, and then go to Modules > Kinematics > Define Joint Group..., and a Joint Group will be created containing only those selected joints.

A confirmation dialog shows the content of the Joint Group being created, and asks for the Joint Group name:

leave "JointGroup" as the name for the Joint Group.

If we inspect the content of the customization script associated with the newly created JointGroup object, we can see it is pretty simple:


sim = require 'sim'

function sysCall_init()
    self = sim.getObject '.'
end

function getJoints()
    return sim.getReferencedHandles(self)
end

function getConfig()
    return map(sim.getJointPosition, getJoints())
end

function setConfig(cfg)
    foreach(sim.setJointPosition, getJoints(), cfg)
end

It simply stores the joints as referenced handles, which could be seen with the Referenced Handles Explorer add-on, or with the Referenced handles highlight (which should be running by default), by simply selecting the JointGroup object:

Inverse Kinematics Generator

Now, to generate an inverse kinematics script, go to Modules > Kinematics > Inverse Kinematics Generator..., a dialog will appear to collect some information.

Select IRB 140 for the Robot model, this should also automatically select the Robot base, Robot tip, and Robot target values based on the first suitable value found in the robot model. If that is not correct, it can be changed.

Select the previously created joint group JointGroup.

The dialog should now look like this:

Click generate and a new IK object appears under the robot model.

Now, without starting the simulation, select the green manipulationSphere object, select the move tool and move the sphere around (make sure to select Translation step size to something else than None, or the movement of the sphere will be disabled.

If we inspect the customization script associated with the IK object, we see a basic IK setup in sysCall_init, and several getter and setter functions to interact with that IK task externally, e.g. from other embedded scripts, via sim.callScriptFunction / sim.getScriptFunctions.

Motion Planning Generator

Now, to add a motion planning task, go to Modules > Kinematics > Motion Planning Generator..., a dialog will appear to collect some information.

Select again the robot model in the combo box, choose an algorithm (PRM is ok), planning time, and select the JointGroup as before.

The dialog should now look like this:

Click generate and some new objects will appear as children of the robot model:

To edit the start state, double click the user config icon (), a clone of the robot appears in red color:

Double click the same icon again to exit the editing of the state.

Since the original robot model defines an IK task, it is possible to edit this robot state with IK as well (if "Handling: when not simulating" was previously selected). So double click the user config icon to enter the edit state. Note that the IK target is automatically selected. Now use the move tool to move the IK target.

Do the same for the GoalState. It is possible to view both the start and the end states at the same time:

Not in the commander (below the status bar), select the script "Customization Script of /IRB140/MotionPlanning", and type compute() and press enter. This will trigger the motion planning task to search for a solution, and if a solution is found, a Path object will be created:

Double clicking its user config icon shows a UI:

Select Show state and drag the State index control (with right mouse button) to get a preview of the robot path:

Or click Show tip path (cartesian) to visualize the path of the tip as a 3D path: