Tuesday, 8 February 2011

Developer Journal 54

12:54 PM
I've just gotten back from see my partner off at the airport. I was going a bit nutty last night till about 2:00 AM trying to work out how to detect when a robot has fallen over. I still haven't worked out how to do it yet. The numbers regarding robot orientation I expect to see keep changing. Grr. Bullet Physics, don't fail me now!

I'm sleepy and my back is sore :). I'd love to get something into the upcoming AGI 2011 conference and the due date for a paper is fast approaching, 15/2/11.Determined not to nap :). Really don't feel like working out today.

I tried converting a Bullet quaternion to an Ogre quaternion to an Ogre matrix to Ogre Radians. I then incremented yaw, pitch, or roll, and converted back to an Ogre matrix, then an Ogre quaternion, and then a Bullet quaternion. It works great when I change pitch and roll but I can only change yaw between -90 and 90 degrees.

I saw a post on the Bullet Physics forums, btMatrix3x3 getEuler returning nan, that suggested parts of Bullet were unpredictable.

I switched back to Bullet transform to Bullet matrix, and then to yaw, pitch, and roll. I incremented yaw but my robot rolled.

Testing yaw.
Changing yaw changed roll instead.
Started at 0, went up to 3.14, then -3.14 and then went up to 0.
Interesting that it did not go above 3.14.
Did do a full rotation

Took an hour long nap. Could not keep eyes open.

Testing pitch.
Changing pitch changed yaw instead and turn robot left.
Started at 0 and went to pi /2 and could not go any higher.
Did not do a full rotation.

Testing roll.
Changing roll changed pitched.
Robot rotated backwards.
Did full rotations.

Switching from btMatrix3x3::setEulerYPR() to btMatrix3x3::setZYX().
I changed Z and Y but my robot just did a kind of shivering movement.

Going back to btMatrix3x3::setEulerYPR().
Instead of increment the real yaw, I created a separate variable, incremented that and my robot did a full rotation.

Yaw went from 0 up to pi/2, then down to 0, then below 0 to -pi/2 back to 0.
Drew it out on paper and boy, is it confusing.

Yaw goes from up from -pi/2 to pi/2 and then down from pi/2 to -pi/2.
So those are they key points.

5:37 PM

Oh. My. G. Eureka! Instead of get Euler angles, incrementing them and then putting them back, I can create a matrix with a rotation increment and then apply that! I so need to develop my maths!

Version 1 - only rotates between -90 and +90 degrees

// get yaw, pitch, roll
float yaw = 0.0f;
float pitch = 0.0f;
float roll = 0.0f;
transform.getBasis().getEulerYPR( yaw, pitch, roll );
pitch += 0.0873f; // about 5 degrees
transform.getBasis().setEulerYPR( yaw, pitch, roll );

Version 2 - goes in the right direction for a while and then sometimes goes in the wrong direction

// get yaw, pitch, roll
float yaw = 0.0f;
float pitch = 0.0f;
float roll = 0.0f;
transform.getBasis().getEulerYPR( yaw, pitch, roll );
// fix the increment value
const float halfPi = 3.1416f / 2.0f;
static float increment = -0.01f;
pitch += increment;
if( increment > 0.0f )
    if( pitch > halfPi )
        increment *= -1.0f;
if( increment < 0.0f )
    if( pitch < -halfPi )
        increment *= -1.0f;

transform.getBasis().setEulerYPR( yaw, pitch, roll );

Version 3

btMatrix3x3 matrix3x3;
const float yaw = 0.0873f; // about 5 degrees
matrix3x3.setEulerYPR( 0.0f, yaw, 0.0f );
transform.getBasis() *= matrix3x3;

I am on my way to writing the code that detects when robots have fallen over and helps them get back up again. This is temporary code until I can give the robots the ability to right themselves

1 1 1 1


No comments:

Post a Comment