## Move sibling independent from parent

Typically: "How do I... ", "How can I... " questions
Aklinger
Posts: 18
Joined: 24 Jan 2014, 15:10

### Move sibling independent from parent

Hi all,
is there a possibility to move a sibling independent from its parent? I have a proximity scanner and want to update its position only after a full scan was made (I rotate the proximity sensor to get multiple measurments). The scanner should be inside the robot hierachy.

Sincerely,
Aklinger

coppelia
Posts: 7689
Joined: 14 Dec 2012, 00:25

### Re: Move sibling independent from parent

Hello Aklinger,

If I understood correctly: you have a robot, and a sensor (static object) attached to it (in its hierarchy). If you move the robot, you wish to keep the sensor in place, until a given condition is met. Is that correct?

If you look at the main script, you will notice that each simulation pass is divided into an actuation part, and a sensing part. If you did things correctly, movement will occure in the actuation part (your robot will move or be moved in that part), and your sensors will do their sensing in the sensing part (i.e. the child script attached to your sensor should be flagged as Execute in the sensing phase (check the script dialog)).

So what you could do is: each time your sensor child script is called, set the desired absolute position/orientation of your sensor (i.e. set the same absolute position/orientation as in previous pass). Then do the sensing. If on the other hand, you which the sensor to simply follow the robot's movement, then set its initial local position/orientation. Maybe something like this (in a non-threaded child script):

Code: Select all

if (simGetScriptExecutionCount()==0) then
-- initialization phase (called just once):
sensorHandle=simGetObjectHandle('mySensor')
initialLocalMatrix=simGetObjectMatrix(sensorHandle,sim_handle_parent)
previousAbsoluteMatrix=simGetObjectMatrix(sensorHandle,-1)
end

-- Following is called at each simulation pass:
if keepSamePoseAsInPreviousSimulationPass then
simSetObjectMatrix(sensorHandle,-1,previousAbsoluteMatrix)
else
simSetObjectMatrix(sensorHandle,sim_handle_parent,initialLocalMatrix)
end
previousAbsoluteMatrix=simGetObjectMatrix(sensorHandle,-1)

-- Do your sensing here
Just make sure your sensor script is executing in the sensing phase. Best would be to also set its execution order to First, so that it will be the first to execute in the sensing phase.

Cheers

Aklinger
Posts: 18
Joined: 24 Jan 2014, 15:10

### Re: Move sibling independent from parent

Unfortunately the child script is threaded. My idea was a reference object which is moving with the robot and every time (before I start a new scan) I take its position and set the joint of the sensor to it. So there is no magical button to press so that a sibling (in my case this joint) ignores the transform of the parent?

Thank you!
Aklinger

coppelia
Posts: 7689
Joined: 14 Dec 2012, 00:25

### Re: Move sibling independent from parent

you could still use the same approach, by having an intermediate object (between the robot and the sensor) that has the above mentioned non-threaded child script attached. In that case however, make sure your threaded child script (of your sensor) executes in the sensing phase. For that, use following command in the beginning of the threaded child script: simSetThreadResumeLocation(4,0)

Yet another possibility, maybe the simplest in your case:

You could simply detach the sensor from the robot at simulation start (it will automatically be re-attached at simulation end) with simSetObjectParent(sensorHandle,-1,true). And each time your threaded child script is about to start a new scan, update the sensor's position/orientation according to the robot's position/orientation.

Cheers

Aklinger
Posts: 18
Joined: 24 Jan 2014, 15:10

### Re: Move sibling independent from parent

Thank you! The simplest way is always the good one.

Sincerely
Aklinger