Using Joint Groups
by federico, 2023-04-06 12:35
Although there is no such concept of joint group in CoppeliaSim, often it is possible to implement more sophisticated concepts using the primitives available in CoppeliaSim, such as models, add-ons, drawing objects, etc...
Formally, a joint group is a logical grouping of joints belonging to a model, ordered.
In practice, an add-on is used to define a joint group. A joint group is created in the form of a scene object (a dummy) that references other objects (the joints members of the group) using the referenced handles feature of CoppeliaSim. That feature is particularly useful for defining relationships between objects, as it can keep track of objects being renamed or removed.
Defining a Joint Group
To define a new joint group, select several joints and then go to Modules > Kinematics > Define joint group....

Tip: if a joint group containing all models' joints is wanted, then it is possible to select the model instead of all the individual joints.
Working with joint groups
The joint group object also defines an API, exposed via a customization script, that allows to:
- retrieve the set of joints (function
getJoints()
); - retrieve the joint configuration vector (function
getConfig()
); - apply a new joint configuration vector (function
setConfig(config)
);
Here's the typical script contained in a joint group's customization script:
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
To use those functions, we can use the convenience API function sim.getScriptFunctions()
in the following way:
-- e.g. if the joint group path is /MyRobot/JointGroup:
jointGroupHandle = sim.getObject('/MyRobot/JointGroup')
jointGroupScript = sim.getScript(sim.scripttype_customizationscript, jointGroupHandle)
-- object-like wrapper to JointGroup's script functions:
jointGroup = sim.getScriptFunctions(jointGroupScript)
-- get the joints of the joint group:
local joints = jointGroup:getJoints()
-- get the config:
local q0 = jointGroup:getConfig()
-- e.g.: q0 = {0.0, 0.0, 0.0, 0.0, 0.0, 0.0}
-- set a new config:
local q1 = {0.1, 0.0, 0.3, 0.0, 1.34, 0.0}
jointGroup:setConfig(q1)