Measure angle for swing motion - rotation

I have a pendulum and an IMU sensor that is capable to give me Euler angles and Quaternions. I want to attach the sensor on pendulum and measure θ angle around x axis from the starting position (see the following image). The problem is that the pendulum rotates itself (around z axis) and this is a problem according to Euler singularities (gimbal lock). So when the pendulum is at 180 degrees and rotates around z-axis i get wrong θ angle.
How can i solve this issue and get the correct θ angle?
example of pendulum and sensor
Edit:
Lets say that we attach the sensor on pendulum such as x-axis is parallel to ceiling and z-axis parallel to pendulum's thread.
Cordinate system of the sensor

Related

Rotating an IMU around X axis, but all 3 angles changes

I am having trouble with Euler angles of an IMU. I have an IMU that gives quaternion and Euler angles. Such questions like bias and so on will be done by the manufacturer and it like a black box for me. I have to trust on it.
My question is as follows: If I rotate IMU around his X-axis, so just the X angle should change its value (for example Roll angle) and it doesn't matter how I oriented the IMU in the space before. But if I rotate it around X Axes I get changes also on other 2 angles. It is like the rotation is not in IMU own coordinate system.

Calculating the opposite side of two triangles on the x and y axis with a correction for yaw

For a project I want to do a very simple Pythagoras calculation in C++. An object is equiped with an IMU sensor that gives either a Quaternion rotation or Euler angles. What I want to know is the opposite sides of the triangle underneath the object.:
I want to know these sides of the triangle for both the X and Y axis (black arrows):
This is pretty much very simple, except for the fact that the object can rotate. When the object is rotated I still want to use the X and Y axis in world space (black arrows), but when yawing the Euler angles of the IMU provide me with pitch and roll, which are in local space (red arrows):
In what way can I still get the world space angles (black arrows) while yawing, to be able to calculate my simple Pythagoras calculation? If I can't get them, is there a way to calculate the opposite sides I want using Quaternions?
We can do the calculation by taking into account the Euler angles in the following order -
Pitch
First of all, as you change the roll of the sensor, the sensor "ray" sweeps out a plane inclined to the horizon at angle pitch. We need to first calculate the closest distance between (i) the line of intersection between the plane and the ground, and (ii) the point directly below the sensor on the ground. This is given by d = h * tan(pitch).
Roll
Next we need to do another trigonometric step. As before the roll sweeps through the plane. The offset distance along the axis perpendicular to the line joining (i) and (ii) is given by f = h / cos(pitch) * tan(roll). This gives the intersection point on the ground to be (d, f)
Yaw
Previously, we considered a frame in which the yaw was zero. We now need to rotate this intersection point around the Z-axis by yaw. Thus the final intersection point is given by (x, y) = (d * cos(yaw) - f * sin(yaw), d * sin(yaw) + f * cos(yaw)). You can calculate the "space angle" you want by taking atan2(y, x).

Calculating the rotation vector of a sphere

I'm trying to calculate the axis of rotation of a ball which is moving and spinning at the same time, i.e. I want the vector along the axis that the ball is spinning on.
For every frame I know the x, y and z locations of 3 specific points on the surface of the sphere. I assume that by looking at how these 3 points have moved in successive frames, you can calculate the axis of rotation of the ball, however I have very little experience with this kind of maths, any help would be appreciated!
You could use the fact that the direction a position vector moves in will always be perpendicular to the axis of rotation. Therefore, if you have two position vectors v1 and v2 at successive times (for the same point), use
This gives you an equation with three unknowns (the components of w, the rotation axis). If you then plug in all three points you have knowledge of you should be able to solve these simultaneous equations and work out w.

Understanding quaternions and axis angle representations

I have a sensor that gives me a quaternion. I convert the quaternion to an axis-angle representation using http://www.euclideanspace.com/maths/geometry/rotations/conversions/quaternionToAngle/. When I hold the sensor on a flat surface and rotate the sensor pressed against the flat surface, I would have expected the axis to be the same and the angle to vary from 0-360 degrees - but this does not happen (the axis varies significantly). Any ideas why? Maybe I don't understand the axis-angle representation?

How to find average velocity and acceleration of Bezier Spline ?

In my application, I have few screen coordinates through which I draw a Bezier Spline and I need to find the average Velocity and acceleration through that spline.
How should I go about it ?
I will find it in terms of pixel/sec and pixels/square-sec.
and then convert it to m/sec and m/sec sq once the User provides pixel-meter mapping.
But How will I get the velocity or accn as I cant just take start point and end point, It has to be thru that curve.
Ughh, leave the pixel/sex and the pixels/square-sec approach aside for now.
I'm assuming from your question that you have an x-y plot with some sort of Bezier spline, some sort of curve which represents way over time. The x axis usually represents time, while the y axis represents way (length) s.
Velocity is the derivation of length over time, and acceleration the derivation of that. A derivation is simply the ratio of dy/dx in a (preferably) close pair of points.
So, what you need for a start is to interpolate and gather as many points from that Bezier spline. Leaving that up to you. From there,
dy = y(i+1) - yi
dx = x(i+1) - xi
velocity = dy/dx
So a graph of velocity over time would be that plotted on a time basis. Same goes for accelleration, just repeat the process.
You need to differentiate the curve once with respect to the temporal dimension in your plot (here I am assuming the x-axis/horizontal axis represents time; the y-axis/vertical axis represents distance travelled) to gain the local velocity component. Differentiate twice with respect to the same temporal dimension to get the acceleration at a given point. This is basically working out the gradient at each point along the curve for velocity, and the gradient of velocity to get the rate of change of velocity, namely acceleration.
To do this you use numerical integration to get the new quantities (velocity and acceleration) at each discreet point (or coordinate) on your spline based upon the data surrounding that point/coordinate location.

Resources