# I need to code a gymbal – or, a gyroscope

I’ve been asked if I could devise a program that basically simulates a gymbal – a gyroscope. The gyroscope would be spinning in a set of three concentric rings, each one attached to the next-inner one by two points on one axis (X,Y,Z).

The idea is that this could be in a mobile device, where the accelerometer would detect how the user moved the phone or tablet, and it would move the gyro accordingly.

Well, I want to start small: just using Blender to model the thing using OpenGL graphics, and leaving “mobile device” for some other day. I think that Blender should allow me to “rough it out” fairly quickly.

I’d like pointers to Python code samples and etc. which would point me in the right direction, especially with regard to the mathematics. (I am a very experienced programmer, well-versed in Python.)

I’m visualizing that movement of the device as reported by the accelerometer would correspond to “global” movement – movement of the box, so to speak, in which the gyro sits – and that this would be translated to movements in the local coordinate space of each ring, each one of which is constrained to only-rotate and only in one of its axes. I surmise that the proper math to do this will be quaternions.

Fortunately, my description of the thing as a “gimbal” is nothing more nor less than:

a mechanism, typically consisting of rings pivoted at right angles, for keeping an instrument such as a compass or chronometer horizontal in a moving vessel or aircraft. :yes:

Undoubtedly the actual mathematics would be quaternions. Specifically to avoid (uhh …) “gimbal lock.”

But my immediate concern is how to properly express the “cascade” of constraints and motion vectors. For example, if the gyroscope is contained within a box that is turned over in some absolute direction or another, that force would of course be conveyed to all of the nested rings in turn. But each of them would by definition be constrained to respond to that force only by rotation, and only in the one (local coordinates …) axis around which they are permitted to rotate. And it seems to me that this is a problem that must be caculated “from the outside in … one, two, three.”

That’s the math that’s puzzling me right now.

But, I basically have already anticipated that, in a gimbal of (x,y,z) rings, given an absolute movement a, each of the three influences can be described as nested functions: x(a), y(x(a)), z(y(x(a))). … I think … and with some suitable transformation from global to local coordinates . . . :spin:

it is a complicated system
and the order in which you do the rotation is very important

so not so easy to implement
but if you do show us how to !
would be interesting to have a working model

Quaternion works fine if you don’t go over 360 degrees

happy cl