Hi folks,

I just figured out that angular velocity fetched via remote API (simxGetObjectFloatParameter with parameter number 14) always returns positive values no matter which direction the object is rotating.

How do I convert this absolute value to a value that takes direction of rotation into account?

Thanks

## remote api get angular velocity - negative values?

### Re: remote api get angular velocity - negative values?

Hello,

if you take 2 different configurations in space, then you can always transform the first configuration into the second one with a single rotation about a given axis. Because of that, the rotation angle (or in your case the rotation velocity) will always be positive (i.e. a negative velocity doesn't make sense in that case).

You can also retrieve a

Cheers

if you take 2 different configurations in space, then you can always transform the first configuration into the second one with a single rotation about a given axis. Because of that, the rotation angle (or in your case the rotation velocity) will always be positive (i.e. a negative velocity doesn't make sense in that case).

You can also retrieve a

*more complicated*(or*less intuitive/elegant*) 3-valued rotation angle/velocity by looking at the Euler angles (i.e. the Euler angles that transform a 3x3 matrix into another 3x3 matrix). In that case the 3 returned angles (or angular velocities) will be signed. If this is what you wish to do, you can use a child script attached to your object with following content:Code: Select all

```
if (simGetScriptExecutionCount()==0) then
h=simGetObjectAssociatedWithScript(sim_handle_self)
c=simAuxiliaryConsoleOpen('Euler angles/velocities',100,4,{100,100},{800,600})
else
currentTime=simGetSimulationTime()
currentMatrix=simGetObjectMatrix(h,-1)
oldMatrixInverted=simGetInvertedMatrix(oldMatrix)
transformation=simMultiplyMatrices(oldMatrixInverted,currentMatrix)
eulerAngles=simGetEulerAnglesFromMatrix(transformation)
dt=currentTime-oldTime
simAuxiliaryConsolePrint(c,eulerAngles[1]/dt..', '..eulerAngles[2]/dt..', '..eulerAngles[3]/dt..'\n')
end
oldTime=simGetSimulationTime()
oldMatrix=simGetObjectMatrix(h,-1)
```

### Re: remote api get angular velocity - negative values?

I see, thanks. I'm trying to use the value returned by simxGetObjectFloatParameter to simulate an odometry for ROS. I must admit I'm not really sure if ROS needs a direction dependently signed value for its tf and navigation stacks. All I know is that a gyroscope/IMU like the Phidget Spatial 3/3/3 provides a signed angular velocity. Hence my assumption is that ROS also needs a properly signed value for its odometry.

Please correct me if I'm wrong.

Please correct me if I'm wrong.

### Re: remote api get angular velocity - negative values?

The angular velocity returned via simxGetObjectFloatParameter(objectHandle,14) is not bound to a rotation in the plane, and can describe a general rotation in space. The same with the method based on Euler angles.

Depending on how you have defined the reference frame of an object, you can read its planar rotation angle by looking at

Depending on how you have defined the reference frame of an object, you can read its planar rotation angle by looking at

*eulerAngles[3]*(index 3 in Lua corresponds to the 3rd value).This is the only rotation that is with most wheeled robots and in that case its configuration is defined by 3 signed values:- position x
- position y
- rotation gamma

### Re: remote api get angular velocity - negative values?

Okay, I see. It could be the velocity of any rotation around any given axis.

I can read the planar rotation angle, that's right. So, I understand I'll have to differentiate it to get the angular velocity around the vertical axis of the robot (that is subtract the last from the current angle and devide it by the time delta in seconds). That way I get a signed angular velocity around the vertical axis.

I just thought there was an easier way using only the remote API without having to manually calculate it.

Well, thanks again!

I can read the planar rotation angle, that's right. So, I understand I'll have to differentiate it to get the angular velocity around the vertical axis of the robot (that is subtract the last from the current angle and devide it by the time delta in seconds). That way I get a signed angular velocity around the vertical axis.

I just thought there was an easier way using only the remote API without having to manually calculate it.

Well, thanks again!

### Re: remote api get angular velocity - negative values?

Just use a code similar to this one, attached to your object:

and on your remote API client side, retrieve that data with the simxGetFloatSignal command.

If you simply retrieve the Euler angles from a given configuration and compare it with its previous configuration, then your Euler angles might

Cheers

Code: Select all

```
if (simGetScriptExecutionCount()==0) then
h=simGetObjectAssociatedWithScript(sim_handle_self)
c=simAuxiliaryConsoleOpen('Euler angles/velocities',100,4,{100,100},{800,600})
else
currentTime=simGetSimulationTime()
currentMatrix=simGetObjectMatrix(h,-1)
oldMatrixInverted=simGetInvertedMatrix(oldMatrix)
transformation=simMultiplyMatrices(oldMatrixInverted,currentMatrix)
eulerAngles=simGetEulerAnglesFromMatrix(transformation)
dt=currentTime-oldTime
simSetFloatSignal("rotVel",eulerAngles[3]/dt)
end
oldTime=simGetSimulationTime()
oldMatrix=simGetObjectMatrix(h,-1)
```

If you simply retrieve the Euler angles from a given configuration and compare it with its previous configuration, then your Euler angles might

*jump*, which will result in wrong readings. That's why you should use the code here above.Cheers