How to correctly set the initial angular velocity of an object

Typically: "How do I... ", "How can I... " questions
Post Reply
robertcc
Posts: 3
Joined: 06 Jun 2018, 15:53

How to correctly set the initial angular velocity of an object

Post by robertcc » 10 Jun 2018, 01:47

Hello,
In my project, I need to set exactly the initial linear/angular velocity of a body. Since the controller can be seen as acting in open-loop, I have to be sure about the current state.

In initialization I've written these lines:

Code: Select all

	simSetObjectFloatParameter(quadcopterH, sim_shapefloatparam_init_velocity_a, state.rate_a);
	simSetObjectFloatParameter(quadcopterH, sim_shapefloatparam_init_velocity_b, state.rate_b);
	simSetObjectFloatParameter(quadcopterH, sim_shapefloatparam_init_velocity_g, state.rate_g);
The linear velocity works as expected, but the angular does not. To check this initialization, when running, I also compute the angular velocity as you suggested in a previous post:

Code: Select all

-- in frame t:
local m1=simGetObjectMatrix(objHandle,-1)
-- in frame t+dt:
local m2=simGetObjectMatrix(objHandle,-1)
local rotationAxis,rotationAngle=simGetRotationAxis(m1,m2)
rotationVelocity=rotationAngle/dt
However the two values are not consistent. So I need to understand the V-REP conventions about angular velocity:
  • What is the physical meaning of these three parameters? Are they the, approximated, time derivative of the Euler angles? If that is the case, I would compute them inverting the following relation:
    https://imgur.com/a/wc3fYMT
  • In this post viewtopic.php?t=6780#p26986 you explained that simGetVelocity is (abg/dt) computed on the "difference" of consecutive rotation matrices. But in my tests it seems to return the same value as rotationAxis*rotationVelocity, that is just an angular velocity.
Thanks!

Running on V-REP 3.4.0

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

Re: How to correctly set the initial angular velocity of an object

Post by coppelia » 12 Jun 2018, 10:24

Hello,

you have several ways to get a shape's velocity (linear or angular). First, it is important to understand that you can:
  • compute the velocity from the object's successive positions
  • get the velocity from the physics engine (since the physics engine is taking care of non-static shapes)
Above two ways may not give you the exact same results.
Additionally, the angular velocity can be expressed in different ways (e.g. via Euler angles derivative (relative to previous orientation), or rotation speed about an axis, which is the way to go).

In your case simply use sim.getVelocity to read the linear and angular velocity from the physics engine. Then use those values to set the initial velocity of a non static shape.

Beware that depending on the physics engine, small initial velocities could be ignored and/or damped.

Cheers

robertcc
Posts: 3
Joined: 06 Jun 2018, 15:53

Re: How to correctly set the initial angular velocity of an object

Post by robertcc » 12 Jun 2018, 16:52

Thanks for you reply.

Yes, I can compute the relevant measures myself to get the current state, but the problem is just with setting the initial velocity.

l also know how to express the angular velocity in these conventions: abg Euler rates, rotation axis in body frame, rotation axis in global frame. Which of these should i choose if I want to set these parameters?

Code: Select all

sim_shapefloatparam_init_velocity_a
sim_shapefloatparam_init_velocity_b
sim_shapefloatparam_init_velocity_g
In which convention are they?

(anyway, I need to set the initial state because the body should start in a configuration that is consistent with a vector field: a linear/angular velocity is given, for each pose)

Thanks

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

Re: How to correctly set the initial angular velocity of an object

Post by coppelia » 13 Jun 2018, 13:38

sorry for any misunderstanding. The misunderstanding also comes from bad naming for the initial angular velocity components, which should rather be sim.shapefloatparam_init_ang_velocity_x, sim.shapefloatparam_init_ang_velocity_y, sim.shapefloatparam_init_ang_velocity_z.

Basically you would use the vector given by the axis of rotation (where the vector is scaled with the angular velocity).

Following shows how to make a static object rotate around such a vector:

Code: Select all

function sysCall_init()
    objectHandle=sim.getObjectAssociatedWithScript(sim.handle_self)
    -- e.g.:
    avx=0.01
    avy=0.02
    avz=0.03
end

function sysCall_actuation()
    local rotVect={avx,avy,avz}
    local rotVel=math.sqrt(rotVect[1]*rotVect[1]+rotVect[2]*rotVect[2]+rotVect[3]*rotVect[3])
    sim.setObjectMatrix(objectHandle,-1,sim.rotateAroundAxis(sim.getObjectMatrix(objectHandle,-1),rotVect,sim.getObjectPosition(objectHandle,-1),rotVel))
end
Cheers

robertcc
Posts: 3
Joined: 06 Jun 2018, 15:53

Re: How to correctly set the initial angular velocity of an object

Post by robertcc » 14 Jun 2018, 00:09

Perfect!
Now the measured axial rotation is the same as was set at initialization.

Thank you

Post Reply