How to build the auxiliary shapes with certain API funcitons?

Typically: "How do I... ", "How can I... " questions
Post Reply
MaJiamu
Posts: 14
Joined: 19 Jan 2021, 03:52

How to build the auxiliary shapes with certain API funcitons?

Post by MaJiamu »

Hello, I was attracted by the video related to motion planning of serial manipulator in https://www.youtube.com/watch?v=Kkn4OkP ... TUB4-Eb6B_. Besides, I put my questions with comments below the video. Here I give my question again. "I was confused that how can I created the auxiliary shapes? Is there any API function that can do this ? Or any tutorial could found from the user manual?"
Thanks!

coppelia
Site Admin
Posts: 10336
Joined: 14 Dec 2012, 00:25

Re: How to build the auxiliary shapes with certain API funcitons?

Post by coppelia »

Hello,

You have several possibilities. One of them is:
  • add a dummy
  • attach the child script below
  • attach the dummy to the object/model you want to trace
  • run the simulation

Code: Select all

function sysCall_init()
    parentObjectHandle=sim.getObjectParent(sim.getObjectHandle(sim.handle_self))
    everyXseconds=1
    trailCount=4
    color={0,1,0}
    opacity=0.1
    trail={}
    lastTime=0
end

function sysCall_sensing()
    local t=sim.getSimulationTime()
    if t-lastTime>everyXseconds then
        lastTime=t
        if #trail>=trailCount then
            sim.removeObject(trail[1])
            table.remove(trail,1)
        end
        if parentObjectHandle>=0 then
            local s=createTrace(parentObjectHandle)
            if s then
                trail[#trail+1]=s
            end
        end
    end
end

function createTrace(o)
    local originalObjects={}
    if sim.getModelProperty(o)&sim.modelproperty_not_model==0 then
        originalObjects=sim.getObjectsInTree(o,sim.object_shape_type,0)
    else
        originalObjects={o}
    end
    local toCopy={}
    for i=1,#originalObjects,1 do
        local r0,r=sim.getObjectInt32Parameter(originalObjects[i],sim.objintparam_visible)
        if r~=0 then
            toCopy[#toCopy+1]=originalObjects[i]
        end
    end
    local copy=sim.copyPasteObjects(toCopy,0)--2+4+8+16+32)
    copy=sim.groupShapes(copy)
    local script=sim.getScriptAssociatedWithObject(copy)
    if script>=0 then
        sim.associateScriptWithObject(script,-1)
    end
    sim.setObjectProperty(copy,sim.objectproperty_selectinvisible)
    sim.setObjectInt32Param(copy,sim.shapeintparam_respondable,0)
    sim.setObjectInt32Param(copy,sim.shapeintparam_static,1)
    sim.setShapeColor(copy,nil,sim.colorcomponent_ambient_diffuse,color)
    sim.setShapeColor(copy,nil,sim.colorcomponent_transparency,{opacity})
    return copy
end
Cheers

MaJiamu
Posts: 14
Joined: 19 Jan 2021, 03:52

Re: How to build the auxiliary shapes with certain API funcitons?

Post by MaJiamu »

Thanks a lot! It works! :)

Post Reply