Orientation problem from inertial module LSM9DS1 Arduino - unity3d

I am working on a project where i have to determine position and rotation of an IoT object with accelerometer, gyroscope and magnetometer. The goal is to show this object in a Unity3D virtual world.
To do this, i have an Arduino Nano 33 BLE that include a LSM9DS1 as inertial module.
So, i started to determine the rotation of my object. This link was very usefull : http://gilles.thebault.free.fr/spip.php?article32
That's the line for get the Y axis :
angle=0.98*(angle+float(gy)0.01/131) + 0.02atan2((double)ax,(double)az)*180/PI;
With this one, i can get X, Y and Z angles. When i try one by one axis orientation, all axis rotation are fine. The problem is when i use 2 axis or more at same time. For example, i use only X and Y axis. When i turn only X axis of 90°, Y axis turn of 90° too. This video will explain more accurately than words : https://www.youtube.com/watch?v=IeuIuEcjUBc&feature=youtu.be
I searched lot of things to fix it but now, i have no more idea. Can anyone guide me?

Related

Is it possible to use OpenPose output of x and y coordinates to detect rotating movement?

I did some research on OpenPose and the output is x and y coordinates with confidence point. x and y coordinates are good for detecting up, down, left, and right movements. I was wondering is it possible to detect turning movements. Turning usually happens on the z axis. Is there a way to tell if body part has rotated 180 degrees with x and y coordinate.
I had few ideas like calculating the slope of the hand line. The slope tells us if the hand is tilted or not. If the slope is high or very low then the hand has rotated. Same concept for all other body parts. But I don't think that will work in all cases. Please check 2nd figure here https://cmu-perceptual-computing-lab.github.io/openpose/web/html/doc/md_doc_02_output.html to understand output of OpenPose.

Simulink 3D Animation using VRML

I've set up an animation of a tugboat [from VRML library] using the Virtual Reality Animation objects. but am having trouble with viewing the rotation of the boat.
To be more specific: I have a simulator going, where I calculate from rigid body dynamics the trajectory of it in time. This is, I have x, y, z, phi, theta, psi vs. time. I associate the translations and rotations to the node corresponding to the boat. When pressing play, I can see the translation and rotation which is not as expected.
Not sure what the problem could be. I tried to add one Transform in the .wrl for each of the rotational degrees of freedom, but I found it weird as when I give rotation in one direction I see the object rotating and translating other directions as well.
Any help is most welcome.

device motion in constrained environment

I am trying to solve a seemingly easy problem related to device motion but couldn't figure out how to solve it. I have a situation where iPhone will move in a circle in the x-y plane. I need to find the angle between the iPhone's x and y axes relative to the center of rotation. The iPhone may be in portrait mode or landscape mode or in any angle in between relative to the line connecting iphone to the center of rotation. See the attached picture that explains the scenario.
The yaw change for a given rotation is the same regardless of this angle, so that doesn't really help. I am hoping that there would be some relationship that I can calculate for every small rotation and then find the best fit for the entire motion - but can't figure out that yet.
I appreciate any help or pointers.
(I am writing in pseudo-code since I don't know the API you are using, sorry.)
Here is how to get the axis and angle of the rotation.
Get the rotation matrices R1 and R2 at the beginning and end of your rotation directly from the API (see CMAttitude and CMRotationMatrix). Then, determine the angle and axis of the rotation R that brings R1 to align with R2. You get R as follows:
R = R1 * transpose(R2)
The angle of rotation R is
angle = acos((trace(R)-1)/2)
and its axis is
axis = { R[3][2]-R[2][3], R[1][3]-R[3][1], R[2][1]-R[1][2] }
For further details, please check Rotation matrix to axis angle and also Axis-angle.
I am not sure how to get the angle you are interested in. Nevertheless, I hope that the above helps.
Please don't use roll, pitch and yaw anything other than display. And don't try to integrate them, nothing good will come out.
Anyways, behind the rotation matrices there is integration. In other words, somebody already did the integration for you.

Using the iPhone accelerometer in a car

I want to use the iPhones's accelerometer to detect motions while driving. I'm a bit confused what the accelerometer actually measures, especially when driving a curve.
As you can see in the picture, a car driving a curve causes two forces. One is the centripetal force and one is the velocity. Imagine the iPhone is placed on the dashboard with +y-axis is pointing to the front, +x-axis to the right and +z-axis to the top.
My Question is now what acceleration will be measured when the car drives this curve. Will it measure g-force on the -x-axis or will the g-force appear on the +y axis?
Thanks for helping!
UPDATE!
For thoses interested, as one of the answers suggested it measures both. The accelerometer is effected by centrifugal force and velocity resulting in an acceleration vector that is a combination of these two.
I think it will measure both. But don't forget that the sensor will measure gravity as well. So when your car is not moving, you will still get accelerometer readings. A nice talk on sensors in smartphones http://www.youtube.com/watch?v=C7JQ7Rpwn2k&feature=results_main&playnext=1&list=PL29AD66D8C4372129 (it's on android, but the same type of sensors are used in iphone).
Accelerometer measures acceleration of resultant force applied to it (velocity is not a force by the way). In this case force is F = g + w + c i.e. vector sum of gravity, centrifugal force (reaction to steering centripetal force, points from the center of the turn) and car acceleration force (a force changing absolute value of instantaneous velocity, points along the velocity vector). Providing Z axis of accelerometer always points along the gravity vector (which is rare case for actual car) values of g, w and c accelerations can be accessed in Z, X and Y coordinates respectively.
Unless you are in free fall the g-force (gravity) is always measured. If I understand your setup correctly, the g-force will appear on the z axis, the axis that is vertical in the Earth frame of reference. I cannot tell whether it will be +z or -z, it is partly convention so you will have to check it for yourself.
UPDATE: If the car is also going up/downhill then you have to take the rotation into account. In other words, there are two frames of reference: the iPhone's frame of reference and the Earth frame of reference. If you would like to deal with this situation, then please ask a new question.

How to use gyro z axis on the iPhone?

I'm using the gyro (does accelerometer and gyro the same on iPhone?) and the X axis and Y axis are working great.
The Z axis is called YAW, but I just can't understand it. It should change its value to 0 when iPhone on its sides and -1 to 1 when face up and down.
In reality , every move on the X/Y axis , change also the Z ...
The definition of Z is answer also on the definition of X axis anyway (same?) because Z is not discrete .
I just can't understand the Z axis thing and if there is another way of getting data of current position from iPhone except from this.
The iPhone has an accelerometer and a gyroscope. Here is a very good video explaining both:
http://www.gametrailers.com/user-movie/wiimotion-plus-explained/244882
I may be wrong, but I believe you are using the accelerometer not the gyro. There are going to be 2 values that are always going to be changing if you rotate the iPhone. Imagine or draw your iPhone vertically as a rectangle. Now draw a horizontal line and a vertical line across it. Those are your X and y axis. If you rotate your iPhone with the screen facing you 90 degrees (from portrait to landscape) you are going to see that your x and y values changed from 1 to 0 and from 0 to 1. The values change when the lines you drew before change from horizontal to vertical and from vertical to horizontal.
Imagine The iPhone facing you again. The z-axis is going to be a line going though the iPhone. So if you put your iPhone on a table you are going to see on the app that the x and y-axis are going to be the same (I believe 0) because both lines are flat, and the z-axis is going to be I believe 1 because the line going though the iPhone is vertical.
Here is an image showing the lines:
(source: garagegames.com)