Calculate azimuth and elevation angles

If I have two frames: /parent and /child. I can use tf:lookuptransform to find the transformation between two frames. Now, I want to find the azimuth and elevation angles in spherical coordinate between two frames. Do ROS have any available function to do something like that?

Thanks

edit retag close merge delete

How would you define the azimuth and elevation angles "between two frames"? They give you 2DOF and a generic 3D transformation would need 6DOF...

( 2016-03-21 19:55:52 -0500 )edit

Sort by » oldest newest most voted

No, to my knowledge ROS doesn't make those methods available.

You need to better define what between two frames means, though. Assuming you can treat Frame1 as the origin (that is, position (x,y,z)=(0,0,0) and orientation (x,y,z,w)=(0,0,0,1)), calculating the azimuth/elevation to another frame can be accomplished using only Frame2's relative-to-Frame1 (x2,y2,z2) location:

magnitude = sqrt((x2*x2) + (y2*y2) + (z2*z2));
azimuth   = atan2(y2, x2);
elevation = asin(z2 / magnitude);


Note that angles should be normalized to -M_PI <= val < M_PI.

If you're going to be working with spherical coordinates, two sites I've found invaluable are Aviation Formulary and Calculate distance, bearing and more between Latitude/Longitude points.

more

Hi There,

You are trying to convert a quaternion representation used internally by ROS into Euler angle representation. I'm assuming you don't care about the translation element or the roll element of the transformation. Azimuth and Elevation are often used to describe the 'direction' to something, this can also be achieved with a TF albeit with a fair amount of redundancy.

The tricky thing about Euler angles is that they can be applied in different orders to get different results. For example rotating 10 degrees around X then Y then Z results in a different effect than 10 degrees about Y then X then Z.

You'll need to work out which order of rotations will give you the Azimuth and Elevation you require.

The KDL Library can convert quaternions into various different Euler angle representations. If you don't want to get stuck in and work it out from scratch.

more