Jump to content
  • Advertisement
Sign in to follow this  
RobMaddison

Simple rotation question (hopefully)

This topic is 2127 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

The fact that your app already "shows" your vectors  means that you have a position that you're drawing them at.

 

But anyway, what you are talking about are two different things:

On the one hand you're talking about Earth and North, which to me sounds more like a spherical/geographical coordinate system, A.K.A.: latitude, longitude, altitude coordinates.

On the other hand, you're talking about a carthesian coordinate system A.K.A.: X, Y, Z coordinates.

 

Now pitch, roll and yaw also have different meanings in each type of coordinate system:

In the spherical/geographical coordinate system, the pitch, roll and yaw are always relative to a position that is represented as latitude, longitude and altitude.

In the carthesian coordinate system, the pitch, roll and yaw are always relative to a position that is specified as X, Y, Z.

 

This is why LorenzoGatti proposed that you use a plane tangential to a sphere as a reference point plane - he thinks that the roll and pitch values that you already have are relative to spherical coordinates, not carthesian ones (and so do I), but only you can clear this up.

Edited by tonemgub

Share this post


Link to post
Share on other sites
Advertisement
Guys I got this working last night (well when the sensor is 'up' at least).

So the accelerometer gives me a vector in line with gravity. When I move the sensor around in roll/pitch fashion, the vector still points down but the sensor reports the vector relative to its orientation. So if I hold the sensor flat, we get 0,1,0. If I pitch it on the sensor's own local x axis (its local axes are physically marked on the sensor) 45 degrees to the right, the accelerometer reports something like 0.707, 0.707, 0.

It's worth noting that all vectors from the sensor (apart from the gyro) have been normalised so they all have an origin at 0,0,0. That's for my purposes, all they are really are direction vectors.

This gives me a coordinate system local to the sensor and so I can use that vector to create a pitch and roll matrix. If I apply that matrix to a box on the screen, rightly enough it pitches and rolls perfectly with the sensor (I've filtered it with the gyro values to get it smooth and steady but that's a different subject).

Whilst it pitches and rolls, if I move the physical sensor around on the yaw axis (or compass axis ill call it), the box on the screen still pitches and rolls as if the physical yaw is still. That's part one out of the way - I've got x and z (pitch and roll) directly correlated to the sensor's x and z (the sensor uses z up but I've converted it y).

So Earth's magnetic field vector is static, it always points to north (assuming you're in the northern hemisphere) and has an inclination (where I am this is roughly 60 degrees). Effectively, this is identical to having a gravity vector only thankfully, it's slightly off axis (off the sensor's gravity axis that is) so it also includes x and z when it is 'vertical' - by that I mean when the sensor is dead flat on the xz plane, if I spin it, the sensor's magnetic vector spins around vertical. Imagine looking down on top of the capital letter V where one of it's spines(?) is vertical and in line with the gravity vector. Rotate it around that spine and the tip of other spine will make a circle around it, that's the x and z value of the magnetic field as reported by the sensor.

Anyway, this V shape stays intact (if you discount accelerometer 'wobble') throughout any orientation of the sensor which means if I put the sensor in any position and compute the rotation needed to get the gravity vector back to 0,1,0 - I can apply that same rotation to the magnetic vector (the one that the sensor is currently reporting) which will give me where the magnetic vector would be if the sensor was flat. Then it's a simple case of taking x and z which gives tilt-compensated yaw.

I know this is probably better achieved in some other mathematical shortcut way but I implemented it last night and it works beautifully. I can now orient my sensor in any way ( northern hemisphere only at the moment as my pitch and roll only cater for 90 degree rotations - ill fix this later) and my box on the screen follows it perfectly.

I tend to visualise things in a practical and physical way rather than mathematically so apologies if I've misled anyone with my terminology.

Thanks again for all your help

Edit: having re-read tonemgub's recent post, I just wanted to clarify that I don't really consider 'Earth' in this computation with regard to longitude or latitude, only its downward gravity vector and magnetic vector relative to gravity.

I have no need for where north is specifically, I only need it as a reference point to compute the yaw axis of my model to coincide with the yaw axis of the sensor. To put it another way, if the gyros didn't drift over time, I could use those and they have no idea where north is, or indeed where any direction is

Share this post


Link to post
Share on other sites


I know this is probably better achieved in some other mathematical shortcut way

Nope. This is the simplest way to find the yaw given pitch and roll relative to the surface of the Earth, and a vector that points to North. Just keep in mid that this won't work when your magnetometer's vector points directly down or directly up (i.e., if you take the magnetometer to the North or South poles :) ), because in this case, the V's spines will be merged into a single spine, and when rotated around the gravity axis, it will define only a point instead of a circle. :)

 

Glad I could help.

Share this post


Link to post
Share on other sites

Just keep in mid that this won't work when your magnetometer's vector points directly down or directly up (i.e., if you take the magnetometer to the North or South poles :) ), because in this case, the V's spines will be merged into a single spine, and when rotated around the gravity axis, it will define only a point instead of a circle. :) Glad I could help.


Ah yes, thanks. I've compensated for this when the sensor gets close to this region by combining it with the roll and pitch. Luckily, at that point I have the missing link already by using the roll and pitch combined with the fact that we effectively implicitly know the yaw at the point we don't know it - if that makes sense...!?

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!