Restore components to their original state

Typically: "How do I... ", "How can I... " questions
Post Reply
vh6033813
Posts: 5
Joined: 07 Oct 2017, 01:16

Restore components to their original state

Post by vh6033813 » 14 Nov 2017, 18:54

Hello.

I am working with some e-pucks, I have been able to obtain their position and orientation and also change them using the functions simxGetObjectPosition, simxSetObjectPosition and simxGetObjectOrientation and simxSetObjectOrientation.

I have taken a look at viewtopic.php?f=9&t=1811#p7133 and applied what is proposed, however on some occasions the components of the e-pucks do not retain their original properties.

These are some captures of the behavior:

Image
Image
Image
Image

Is there any way to restore the components to their original state?

Kind regards.

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

Re: Restore components to their original state

Post by coppelia » 15 Nov 2017, 09:07

Hello,

for every e-puck, you will have to do something like:

Code: Select all

-- init phase:
local initConf=simGetConfigurationTree(modelBase)

-- reset:
-- sim.setThreadAutomaticSwitch(false) -- in case your script is threaded
local objects=simGetObjectsInTree(modelBase,sim_handle_all,0)
for i=1,#objects,1 do
   simResetDynamicObject(objects[i])
end
simSetConfigurationTree(initConf)
-- sim.setThreadAutomaticSwitch(true) -- in case your script is threaded
since you are doing things from a remote API client, something like following would be more appropriate:

Code: Select all

-- init phase:
local initConf=simGetConfigurationTree(modelBase)

-- reset:
function setConfig(inInts,inFloats,inStrings,inBuffer)
    local desiredPosition={inFloats[1],inFloats[2],inFloats[3]}
    local desiredOrientation={inFloats[4],inFloats[5],inFloats[6]}
    -- sim.setThreadAutomaticSwitch(false) -- in case your script is threaded
    local objects=simGetObjectsInTree(modelBase,sim_handle_all,0)
    for i=1,#objects,1 do
       simResetDynamicObject(objects[i])
    end
    simSetConfigurationTree(initConf)
    simSetObjectPosition(modelBase,-1,desiredPosition)
    simSetObjectPosition(modelBase,-1,desiredOrientation)
    -- sim.setThreadAutomaticSwitch(true) -- in case your script is threaded
end
and you will have to call the above function with simxCallScriptFunction.

Cheers

vh6033813
Posts: 5
Joined: 07 Oct 2017, 01:16

Re: Restore components to their original state

Post by vh6033813 » 17 Nov 2017, 21:08

Thank you very much. It works perfectly.

On the other hand, is there any way to prevent the components of the robot from being damaged, for example when colliding with an object?

Kind regards.

Post Reply