Hello,
I have a dummy, and I want to find its angular velocity with respect to an arbitrary reference frame. I know how to get the derivatives of Euler angles of an object in Coppeliasim, but I do not need that here. I want angular velocity, like the values an IMU sensor returns. ( Note that derivatives of Euler angles are different from the angular velocity values which IMU sensor returns)
Thanks for your help in advance.
Best
getting IMU angular velocity
Re: getting IMU angular velocity
Hello,
did you have a look at sim.getObjectVelocity? Use it like:
Cheers
did you have a look at sim.getObjectVelocity? Use it like:
Code: Select all
local linearVelocity, angularVelocity=sim.getObjectVelocity(objectHandle | sim.handleflag_axis)
Re: getting IMU angular velocity
Thanks for your reply. I used the function you mentioned. Here is my script:
But the values of angularVelocity_axis and angularVelocity I got from the above script do not have a difference, and I think they both calculate Euler angle derivatives (since sim.getObjectVelocity(dummy) calculates Euler angle derivatives and its return value is the same as the angularVelocity_axis)
I also tried to calculate the angular velocity vector of my dummy object in a local reference frame using derivatives of Euler angles myself by the following formula. Still, that does not give me the correct angular velocity either. Also, my calculated values for angular velocity using derivatives of Euler angles have a considerable difference from the angularVelocity_axis value I got from the above script. Here is the code I used to transfer Euler angle derivatives into angular velocity:
In the above script I get the Euler angles from the scene by using this code:
Also, I used the following code for obtaining the Euler dot vector of the dummy with respect to the ref frame, which is an arbitrary frame:
I get confused now. How should I get the angular velocity correctly?
Code: Select all
function sysCall_init()
dummy = sim.getObject("/dummy_path")
function sysCall_sensing()
linearVelocity, angularVelocity_axis=sim.getObjectVelocity(dummy | sim.handleflag_axis)
linearVelocity, angularVelocity=sim.getObjectVelocity(dummy)
print(angularVelocity_axis)
print(angularVelocity)
I also tried to calculate the angular velocity vector of my dummy object in a local reference frame using derivatives of Euler angles myself by the following formula. Still, that does not give me the correct angular velocity either. Also, my calculated values for angular velocity using derivatives of Euler angles have a considerable difference from the angularVelocity_axis value I got from the above script. Here is the code I used to transfer Euler angle derivatives into angular velocity:
Code: Select all
# This is a python script, I process the returned data from the scene here!
# The data I have used here are Euler angles and their derivatives!
def findOmega(self):
map = np.array([[0, -np.sin(self.euler[0]), np.cos(self.euler[1])*np.cos(self.euler[0])],
[0, np.cos(self.euler[0]), np.cos(self.euler[1])*np.sin(self.euler[0])],
[1, 0, -np.sin(self.euler[1])]])
self.omega_mp = map @ self.euler_dot
Code: Select all
-- Find Euler Angles with respect to ref frame!!
orient = sim.getObjectOrientation(dummy, ref)
alpha = orient[1]
beta = orient[2]
gamma = orient[3]
yaw_z, pitch_y, roll_x = sim.alphaBetaGammaToYawPitchRoll(alpha, beta, gamma)
euler = {yaw_z, pitch_y, roll_x}
Code: Select all
-- Finding derivatives of Euler angles in ZYX convention!
function sysCall_init()
-- in frame t:
t1 = sim.getSimulationTime()
m1=sim.getObjectMatrix(dummy,-1)
function sysCall_sensing()
-- in frame t+dt:
t2 = sim.getSimulationTime()
dt = t2 - t1
t1 = t2
sim.invertMatrix(m1)
m2=sim.getObjectMatrix(dummy,-1)
m=sim.multiplyMatrices(m1,m2) -- now m is the transf. matrix of obj at t, expressed relative to the transf. matrix of obj at t+dt
euler=sim.getEulerAnglesFromMatrix(m)
euler_dot={euler[1]/dt,euler[2]/dt,euler[3]/dt}
m1 = m2
Re: getting IMU angular velocity
I just realized that you didn't reply to your other post regarding this exact same topic. Not sure why you opened another topic.
But my reply is still the same: if you need to use a rotational velocity based on Euler angles, do it like you described in your other post. But Euler angles for rotations is very rarely a good idea, and you should rather use the instantaneous rotation axis and an angle. If sim.handleflag_axis is specified, the return is not the derivative of Euler angles, but the inst. rotation axis, and the rotation velocity around that axis is given by the length of that axis.
Cheers
But my reply is still the same: if you need to use a rotational velocity based on Euler angles, do it like you described in your other post. But Euler angles for rotations is very rarely a good idea, and you should rather use the instantaneous rotation axis and an angle. If sim.handleflag_axis is specified, the return is not the derivative of Euler angles, but the inst. rotation axis, and the rotation velocity around that axis is given by the length of that axis.
Cheers
Re: getting IMU angular velocity
Thanks for your reply again. I opened a new topic because the topic you mentioned was about finding derivatives of Euler angles, where here I am asking about finding angular velocity that IMU returns. I thought it would be better to discuss this issue in a new topic. I understand your point that by adding the sim.handleflag_axis to the sim.getObjectVelocity function, I will get the angular velocity of my object, but this returned angular velocity is in the absolute reference frame (which I think is the frame of the object and not the global reference frame right?). I want this angular velocity in a reference frame that I defined in my scene. Can I simply multiply the Rotation matrix between the reference frame of the object and my desired reference frame by the returned value of sim.getObjectVelocity to get the angular velocity in my desired reference coordinate?
Re: getting IMU angular velocity
you can transform the rotation vector into any frame you want. e.g.:
Cheers
Code: Select all
local _,absAngularVelVector=sim.getObjectVelocity(objectHandle | sim.handleflag_axis)
local frame=sim.getObjectMatrix(sim.getObject('/myDummy'),-1)
sim.invertMatrix(frame)
frame[4]=0 frame[8]=0 frame[12]=0 -- remove the translational component
local relAngularVelVector=sim.multiplyVector(frame,absAngularVelVector)