Showing multiple poses in one figure?

Typically: "How do I... ", "How can I... " questions
Post Reply
w1574587
Posts: 9
Joined: 25 Oct 2020, 03:42

Showing multiple poses in one figure?

Post by w1574587 »

I want to show multiple poses in one figure as a manipulator moving along a trajectory. I've seen someone did it by plotting translucent poses but I don't know how. Is it possible within CoppeliaSim? Any other suggestions?

Cheers

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

Re: Showing multiple poses in one figure?

Post by fferri »

Maybe sim.addGhost is what you are looking for.

w1574587
Posts: 9
Joined: 25 Oct 2020, 03:42

Re: Showing multiple poses in one figure?

Post by w1574587 »

Exactly! Thanks a lot!

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

Re: Showing multiple poses in one figure?

Post by coppelia »

I would rather prefer you to use something like following, to generate a trace instance for a shape:

Code: Select all

    local copy=sim.copyPasteObjects({originalObject},0)[1]
    local script=sim.getScriptAssociatedWithObject(copy)
    if script>=0 then
        sim.associateScriptWithObject(script,-1)
    end
    sim.setObjectInt32Parameter(copy,sim.shapeintparam_static,1)
    sim.setObjectInt32Parameter(copy,sim.shapeintparam_respondable,0)
    sim.setObjectProperty(copy,sim.objectproperty_selectinvisible)
    sim.setObjectSpecialProperty(copy,sim.objectspecialproperty_renderable)
    sim.setShapeColor(copy,'',sim.colorcomponent_ambient_diffuse,{0,1,0})
    sim.setShapeColor(copy,'',sim.colorcomponent_transparency,{0.2})
If you have several shapes, use above for each shape, then group them with sim.groupShapes.

Then you have more control than with ghosts, and ghosts might not be supported in the same way in future releases or deprecated.

Cheers

w1574587
Posts: 9
Joined: 25 Oct 2020, 03:42

Re: Showing multiple poses in one figure?

Post by w1574587 »

Thank you for the suggestion! Now I have two new questions.

1) Why does the

Code: Select all

sim.setShapeColor(copy,'',sim.colorcomponent_transparency,{0.5})
has no effect? The "fake" robot links are still not translucent.

2) I use MATLAB to control the robot. Anyway I followed your instruction and wrote a Lua script. Now I can only draw the initial pose. How can I draw the poses in the midterm?

FYI. Here is my Lua script.

Code: Select all


repeat until (simRemoteApi.start(19999,1300,false,true)~=-1)


function showPose(handleName)
originalObject=sim.getObjectHandle(handleName)
local copy=sim.copyPasteObjects({originalObject},0)[1]
local script=sim.getScriptAssociatedWithObject(copy)
if script>=0 then
    sim.associateScriptWithObject(script,-1)
end
sim.setObjectInt32Parameter(copy,sim.shapeintparam_static,1)
sim.setObjectInt32Parameter(copy,sim.shapeintparam_respondable,0)
sim.setObjectProperty(copy,sim.objectproperty_selectinvisible)
sim.setObjectSpecialProperty(copy,sim.objectspecialproperty_renderable)
sim.setShapeColor(copy,'',sim.colorcomponent_ambient_diffuse,{0,1,0})
sim.setShapeColor(copy,'',sim.colorcomponent_transparency,{0.5})
end



showPose('UR5_link1_visible')
showPose('UR5_link2_visible')
showPose('UR5_link3_visible')
showPose('UR5_link4_visible')
showPose('UR5_link5_visible')
showPose('UR5_link6_visible')
showPose('UR5_link7_visible')


w1574587
Posts: 9
Joined: 25 Oct 2020, 03:42

Re: Showing multiple poses in one figure?

Post by w1574587 »

Update:
Haven't figure out the transparency problem.
Here is my way to plot multiple poses. Looking forward to a more elegant solution...

Code: Select all

-- lua

repeat until (simRemoteApi.start(19999,1300,false,true)~=-1)


function showPose(handleName)
originalObject=sim.getObjectHandle(handleName)
local copy=sim.copyPasteObjects({originalObject},0)[1]
local script=sim.getScriptAssociatedWithObject(copy)
if script>=0 then
    sim.associateScriptWithObject(script,-1)
end
sim.setObjectInt32Parameter(copy,sim.shapeintparam_static,1)
sim.setObjectInt32Parameter(copy,sim.shapeintparam_respondable,0)
sim.setObjectProperty(copy,sim.objectproperty_selectinvisible)
sim.setObjectSpecialProperty(copy,sim.objectspecialproperty_renderable)
sim.setShapeColor(copy,'',sim.colorcomponent_ambient_diffuse,{0,1,0})
sim.setShapeColor(copy,'',sim.colorcomponent_transparency,{0.5})
end

function showAllPose()
showPose('UR5_link1_visible')
showPose('UR5_link2_visible')
showPose('UR5_link3_visible')
showPose('UR5_link4_visible')
showPose('UR5_link5_visible')
showPose('UR5_link6_visible')
showPose('UR5_link7_visible')
end

while (true)
do
timeNow=sim.getSimulationTime()
--print(timeNow)
if timeNow>0 and timeNow<0.04
then
showAllPose()
end


if timeNow>1.2 and timeNow<1.21
then
showAllPose()
end

if timeNow>1.7 and timeNow<1.71
then
showAllPose()
end

if timeNow>2.9 and timeNow<2.91
then
showAllPose()
end
end

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

Re: Showing multiple poses in one figure?

Post by coppelia »

w1574587 wrote: 22 Mar 2021, 04:25 1) Why does the

Code: Select all

sim.setShapeColor(copy,'',sim.colorcomponent_transparency,{0.5})
has no effect? The "fake" robot links are still not translucent.
I cannot reproduce that. If I create a new shape in the scene, attach a child script to it and programmatically set its transparency, it appears transparent here. Maybe you can post a minimalistic, self-contained scene that illustrates that situation?

As to how to create a trace of a shape, at several time intervals: simply repeat to procedure each time x seconds have passed, e.g. from within a threaded child script:

Code: Select all

    sim.setThreadAutomaticSwitch(false)
    local shapesToTrack={...}
    local timeInterval=2
    while true do
        for i=1,#shapesToTrack,1 do$
            showPose(shapesToTrack[i])
        end
        sim.wait(timeInterval)
    end
Cheers

w1574587
Posts: 9
Joined: 25 Oct 2020, 03:42

Re: Showing multiple poses in one figure?

Post by w1574587 »

Thank you for the reply! Similarly, I added some shapes on the end-effector and the code worked. But for the UR5 manipulator, it doesn't work. The scene that illustrates that situation can be obtained by following steps:
1) open a new scene
2) drag and drop UR5.ttm into the scene
3) add threaded child script to UR5_link1_visible, the code:

Code: Select all

-- Lua
function sysCall_threadmain()



function showPose(handleName)
originalObject=sim.getObjectHandle(handleName)
local copy=sim.copyPasteObjects({originalObject},0)[1]
local script=sim.getScriptAssociatedWithObject(copy)
if script>=0 then
    sim.associateScriptWithObject(script,-1)
end
sim.setObjectInt32Parameter(copy,sim.shapeintparam_static,1)
sim.setObjectInt32Parameter(copy,sim.shapeintparam_respondable,0)
sim.setObjectProperty(copy,sim.objectproperty_selectinvisible)
sim.setObjectSpecialProperty(copy,sim.objectspecialproperty_renderable)
sim.setShapeColor(copy,'',sim.colorcomponent_ambient_diffuse,{0,1,0})
sim.setShapeColor(copy,'',sim.colorcomponent_transparency,{0.5})
end


sim.setThreadAutomaticSwitch(false)
    local shapesToTrack={"UR5_link1_visible","UR5_link2_visible","UR5_link3_visible","UR5_link4_visible","UR5_link5_visible","UR5_link6_visible","UR5_link7_visible"}
    local timeInterval=2
    while true do
        for i=1,#shapesToTrack,1 do
            showPose(shapesToTrack[i])
        end
        originalObject=sim.getObjectHandle("UR5_connection")
        local copy=sim.copyPasteObjects({originalObject},0)[1]
        sim.wait(timeInterval)
        end
end


function sysCall_cleanup()
    -- Put some clean-up code here
end

-- See the user manual or the available code snippets for additional callback functions and details

4) run the simulation

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

Re: Showing multiple poses in one figure?

Post by coppelia »

Ok,

the model you mention has named colors. So instead of:

Code: Select all

        sim.setShapeColor(copy,'',sim.colorcomponent_ambient_diffuse,{0,1,0})
        sim.setShapeColor(copy,'',sim.colorcomponent_transparency,{0.5})
do

Code: Select all

        sim.setShapeColor(copy,nil,sim.colorcomponent_ambient_diffuse,{0,1,0})
        sim.setShapeColor(copy,nil,sim.colorcomponent_transparency,{0.5})
Additionallyy it is probably a good idea to attach all created objects onto a dummy, so that the hierarchy keeps clean. And/or group those shapes on a regular interval, to avoid having too many of them. This should not be a problem since they are static anyway.

Cheers

w1574587
Posts: 9
Joined: 25 Oct 2020, 03:42

Re: Showing multiple poses in one figure?

Post by w1574587 »

Awesome! Many thanks!!

Post Reply