## V-REP and fluids

Typically: "How do I... ", "How can I... " questions
amattag
Posts: 16
Joined: 05 Mar 2013, 13:06
Contact:

### V-REP and fluids

Dear all,

I relly like this video:

http://youtu.be/KggpZe2mgrw

Can you explain how do you simulate fluids in order to simulate water?

Kind regards,

Antonio Matta.

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

### Re: V-REP and fluids

Hello Antonio,

In V-REP, fluids are not directly simulated. But you can prepare the simulation so that a robot/object behaves in a similar way as in a fluid.

In the case of the ACMR5 simulation, it is done in following way:
• Each body element has a specific mass, i.e. m. Each body element will check (from within a child script) its Z-position, then calculate a compensating force: if the element is completely above Z=0, then there is no additional force. When the element is completely below Z=0, then the additional force is m*gravity==m*9.81. When the element is partially in the water, a partial force is added. You can add a force to a non-static shape with the simAddForceAndTorque API function. The force needs to be added at each simulation pass.
• Each body element calculates its velocity with simGetVelocity. If below Z=0 (or to a certain degree when only partially in the water), then a compensation force (or a kind of damping) radial to the body element is calculated, that is opposite to the element radial movement. The compensation force is inversely proportional to the velocity. To do this, the velocity is first calculated in the element's frame, and only the radial component is kept. The force is added in the absolute reference frame.
Below the code that is in charge to keep one element floating, and that adds radial damping:

Code: Select all

p=simGetObjectPosition(bodyS,-1)
cm=(0.05-p[3])/0.05
if (cm>1.05) then cm=1.05 end
if (cm<0) then cm=0 end
linV,angV=simGetVelocity(body)
m=simGetObjectMatrix(bodyS,-1)
m[4]=0
m[8]=0
m[12]=0
mi=simGetInvertedMatrix(m)
linV=simMultiplyVector(mi,linV)
linV[1]=0
linV=simMultiplyVector(m,linV)
f={linV[1]*mass*str*cm,linV[2]*mass*str*cm,linV[3]*mass*str*cm}
Make sure you inspect the child scripts attached to each body element (e.g. ACMR_bodyRespondable#0)

Cheers

srcg
Posts: 2
Joined: 07 Nov 2014, 03:37

### Re: V-REP and fluids

Hello!

I cannot figure out what the value str is supposed to represent.

Will be very thankful if someone can help me!

Best Regards,

SG

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

### Re: V-REP and fluids

Hello,

as far as I can tell, the str variable represents a drag coefficient. It will generate a force that is inversely proportional to the element velocity vector (if str is negative). The velocity vector is radially projected onto the element (in order to have only a radial drag, i.e. there is no drag in the direction of forward movement of the snake)

Cheers

srcg
Posts: 2
Joined: 07 Nov 2014, 03:37

### Re: V-REP and fluids

Thank you so much!
=)

zhenli
Posts: 5
Joined: 13 Dec 2014, 14:16

### Re: V-REP and fluids

Dear coppelia.
Thanks for the explanation on ACM-R5.
linV,angV=simGetVelocity(body)
linV is the velocity of the object coordinates or the world coordinates?
why we need following function to get the velocity of the object in the world coordinates?
Can you give more detail help on the following functions:
mi=simGetInvertedMatrix(m)
linV=simMultiplyVector(mi,linV)
linV[1]=0
linV=simMultiplyVector(m,linV)

is it means V=m-1*V*m?
what is the math function for it, or what is the phyical function ?
Since I want to use similar way to calculate the adhere force when we control the rotation of the robot in the water.
Thanks for any feedback.
Best regards.
Zhenli

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

### Re: V-REP and fluids

Hello Zhenli,

the velocity retrieved with simGetVelocity is expressed relative to the absolute reference frame. But in our case, we need to velocity to compute the drag of the object. And we only want drag radially to the robot segment, not in the direction of movement.

So we first transform the velocity so that we have it relative to the segment's reference frame. Then we set the velocity component that goes in the direction of movement to zero. Finally, we transform the velocity into world reference frame again.

Cheers

zhenli
Posts: 5
Joined: 13 Dec 2014, 14:16

### Re: V-REP and fluids

Dear coppelia.
But I still do not understand it well.
I can understant that
-------------------------------------
linV,angV=simGetVelocity(body)
m=simGetObjectMatrix(bodyS,-1)
------------------------------------
they can get the velocity and transmatrix.
-------------------------------
m[4]=0
m[8]=0
m[12]=0
-------------------------------
and set the translation component from one coordinates to another as zero.
---------------------

mi=simGetInvertedMatrix(m)
linV=simMultiplyVector(mi,linV)
--------------------
get the vecolicty in sub-coordinates without translation component

but I do not understand why we need set

-----
linV[1]=0

????
--------
Does linV[1] is related to translation component???

then we can get the velocity only related with rotation?
linV=simMultiplyVector(m,linV)
Best regards.
Zhenli

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

### Re: V-REP and fluids

We set the X-component of the drag to zero, because we do not want drag in the forward direction. You can try to comment out that line, and you will see that the snake will not be able to properly move in water.

Of course, in reality, there is also drag along the forward direction of the snake, but it is like with a train: basically, only the first wagon will have a drag force in the forward direction, all other wagons are in the wind-shadow of the first wagon (in the forward direction).

Cheers

eason

### Re: V-REP and fluids

Dear copplia,
Firstly, thanks for your previous reply ,now I know a lot about ACM-R5 motion underwater according to your notes. mainly principle on ACM-r5 under the water, but in terms of ACM-R5 in the V-rep, i don't understand a variable cm=(0.05-p[3])/0.05.Can you explain 0.05 this value? why is 0.05? I don't understand why use this value. I would greatly appreciate it if you could give me some details about cm.
code :

Code: Select all

p=simGetObjectPosition(bodyS,-1)
cm=(0.05-p[3])/0.05
if (cm>1.05) then cm=1.1 end
if (cm<0) then cm=0 end