Could someone Explain these functions?

Typically: "How do I... ", "How can I... " questions
Post Reply
Fery64
Posts: 88
Joined: 02 Feb 2022, 15:58

Could someone Explain these functions?

Post by Fery64 »

Hi All

In an example code, I have these two functions. What I don't understand is the if clauses:

Code: Select all

if b==sim.handle_parent then
>> What does it mean? if b is parent of what??

Code: Select all

b=sim.getObjectParent(a)  
>>>> Then if we getObjectParent of a and put it in b? why ? what happens to b then?

What is this then? why is this line so vague? if b is not -1 and is a joint, then why

Code: Select all

 a=a+sim.handleflag_reljointbaseframe

Code: Select all

if (b~=-1) and (sim.getObjectType(b)==sim.object_joint_type) and (sim.getInt32Param(sim.intparam_program_version)>=40001) 
I need to take this code in Matlab, but it is not clear how I should rewrite it. It seems like that Matlab libraray, at least in remAPI has no getObjectQuaternion function

Code: Select all

function __getObjectPosition__(a,b)
    -- compatibility routine, wrong results could be returned in some situations, in CoppeliaSim <4.0.1
    if b==sim.handle_parent then
        b=sim.getObjectParent(a)
    end
    if (b~=-1) and (sim.getObjectType(b)==sim.object_joint_type) and (sim.getInt32Param(sim.intparam_program_version)>=40001) then
        a=a+sim.handleflag_reljointbaseframe
    end
    return sim.getObjectPosition(a,b)
end
function __getObjectQuaternion__(a,b)
    -- compatibility routine, wrong results could be returned in some situations, in CoppeliaSim <4.0.1
    if b==sim.handle_parent then
        b=sim.getObjectParent(a)
    end
    if (b~=-1) and (sim.getObjectType(b)==sim.object_joint_type) and (sim.getInt32Param(sim.intparam_program_version)>=40001) then
        a=a+sim.handleflag_reljointbaseframe
    end
    return sim.getObjectQuaternion(a,b)
end

fferri
Posts: 1187
Joined: 09 Sep 2013, 19:28

Re: Could someone Explain these functions?

Post by fferri »

Fery64 wrote: 21 Nov 2022, 22:11

Code: Select all

if b==sim.handle_parent then
>> What does it mean? if b is parent of what??
Hard to tell with this code out of context.

Better to read the docs and understand things top down:

from the docs of sim.getObjectPose, sim.getObjectPosition, sim.getObjectOrientation, etc...:
relativeToObjectHandle: indicates relative to which reference frame we want the pose. Specify sim.handle_world to retrieve the absolute pose, sim.handle_inverse to retrieve the inverse of the absolute pose, sim.handle_parent to retrieve the pose relative to the object's parent, or an object handle relative to whose reference frame we want the pose. If this handle is the handle of a joint, then the pose relative to the joint's moving frame will be returned (unless objectHandle is combined with sim.handleflag_reljointbaseframe, in which case the pose relative to the joint's base frame will be returned).
Fery64 wrote: 21 Nov 2022, 22:11

Code: Select all

b=sim.getObjectParent(a)  
>>>> Then if we getObjectParent of a and put it in b? why ? what happens to b then?
b gets the parent of object a.

Fery64 wrote: 21 Nov 2022, 22:11 What is this then? why is this line so vague? if b is not -1 and is a joint, then why

Code: Select all

 a=a+sim.handleflag_reljointbaseframe
This is also answered in the API docs of the functions I mentioned above. See also: Joints.

Post Reply