Kinematics Plugin

The kinematics plugin for CoppeliaSim (simExtIK.dll or similar) wraps the Coppelia Kinematics Routines. It exports several API functions that can be recognized from their simIK-prefix; they allow to create, handle and solve forward/inverse kinematics tasks for any type of mechanism (redundant/non-redundant, containing nested loops, etc.) fully programmatically.

Kinematics tasks can very easily be set up from the scene's content like in following example:

-- set-up: function sysCall_init() simBase=sim.getObject('/base') simTip=sim.getObject('/tip') simTarget=sim.getObject('/target') ikEnv=simIK.createEnvironment() ikGroup=simIK.createIkGroup(ikEnv) local ikElement=simIK.addIkElementFromScene(ikEnv,ikGroup,simBase,simTip,simTarget,desiredConstraints) end -- IK calculation, and application to the scene: function sysCall_actuation() simIK.applyIkEnvironmentToScene(ikEnv,ikGroup) end

simIK.addIkElementFromScene will parse the scene given a base, tip and target object, and generate an IK element appropriately, with the given constraints. simIK.applyIkEnvironmentToScene on the other hand will compute IK, then apply the calculation results to the corresponding scene joints. One can of course also manually build the kinematic environment, for full control, as in following example:

-- set-up: function sysCall_init() simJoints={sim.getObject('/j1'),sim.getObject('/j2')} ikJoints={} ikBase=simIK.createDummy(ikEnv) -- create a dummy in the IK environemnt -- set that dummy into the same pose as its CoppeliaSim counterpart: simIK.setObjectMatrix(ikEnv,ikBase,-1,sim.getObjectMatrix(simBase,-1)) local parent=ikBase for i=1,#simJoints,1 do -- loop through all joints -- create a joint in the IK environment: ikJoints[i]=simIK.createJoint(ikEnv,simIK.jointtype_revolute) -- set it into IK mode: simIK.setJointMode(ikEnv,ikJoints[i],simIK.jointmode_ik) -- set the same joint limits as its CoppeliaSim counterpart joint: local cyclic,interv=sim.getJointInterval(simJoints[i]) simIK.setJointInterval(ikEnv,ikJoints[i],cyclic,interv) -- set the same lin./ang. joint position as its CoppeliaSim counterpart joint: simIK.setJointPosition(ikEnv,ikJoints[i],sim.getJointPosition(simJoints[i])) -- set the same object pose as its CoppeliaSim counterpart joint: simIK.setObjectMatrix(ikEnv,ikJoints[i],-1,sim.getObjectMatrix(simJoints[i],-1)) simIK.setObjectParent(ikEnv,ikJoints[i],parent) -- set its corresponding parent parent=ikJoints[i] end ikTip=simIK.createDummy(ikEnv) -- create the tip dummy in the IK environment -- set that dummy into the same pose as its CoppeliaSim counterpart: simIK.setObjectMatrix(ikEnv,ikTip,-1,sim.getObjectMatrix(simTip,-1)) simIK.setObjectParent(ikEnv,ikTip,parent) -- attach it to the kinematic chain ikTarget=simIK.createDummy(ikEnv) -- create the target dummy in the IK environment -- set that dummy into the same pose as its CoppeliaSim counterpart: simIK.setObjectMatrix(ikEnv,ikTarget,-1,sim.getObjectMatrix(simTip,-1)) simIK.setLinkedDummy(ikEnv,ikTip,ikTarget) -- link the two dummies ikGroup=simIK.createIkGroup(ikEnv) -- create an IK group -- set its resolution method to undamped: simIK.setIkGroupCalculation(ikEnv,ikGroup,simIK.method_pseudo_inverse,0,3) -- add an IK element to that IK group: local ikElement=simIK.addIkElement(ikEnv,ikGroup,ikTip) -- specify the base of that IK element: simIK.setIkElementBase(ikEnv,ikGroup,ikElement,ikBase) -- specify the constraints of that IK element: simIK.setIkElementConstraints(ikEnv,ikGroup,ikElement,simIK.constraint_x+simIK.constraint_y) end -- IK calculation, and application to the scene: function sysCall_actuation() -- reflect the pose of the target dummy in the IK environment: simIK.setObjectMatrix(ikEnv,ikTarget,ikBase,sim.getObjectMatrix(simTarget,simBase)) simIK.handleIkGroup(ikEnv,ikGroup) -- solve -- apply the calculated joint values: sim.setJointPosition(simJoints[1],simIK.getJointPosition(ikEnv,ikJoints[1])) sim.setJointPosition(simJoints[2],simIK.getJointPosition(ikEnv,ikJoints[2])) end

For examples on how to use above API functions, refer to the scenes in scenes/kinematics/, and make sure to inspect the attached scripts.