localOrientation on rotary inverted pendulum I am setting up a rotary inverted pendulum in bge. If you look at the picture below, the body rotates around the z-axis and the pole is linked to the base with a hinge. I am having trouble getting the angle of the pole as it falls down. Using pole.localOrientation.to_euler() I get a vector of angles x, y, and z. I thought the angle I was looking for would always be on the y-axis, but it seems to alternatively switch between x and y, and I cannot figure out why. Below is an excerpt of the output of pole.localOrientation.to_euler() where it switches between x and y. (I thought maybe it could be when z goes negative or positive but I have found occurrences where it is not the case)
I think this is the result of the conversion to Euler coordinates. 

Your values are too close to the pole of the "coordinate sphere". Little precision errors have large influence on the calculation of the rotation between angles around X and Y. It behaves like a compass near one of the magnetic poles. The direction can't be determined exactly due to the near pole.

You might need a different way to determine the axis around Z. I'm not that familiar with Euler. I suggest to use a different order.