cancel
Showing results for 
Search instead for 
Did you mean: 

360 degree rotation on all axis, LIS3DSH

Ashish Pamula
Associate
Posted on June 21, 2018 at 00:36

Hi all, I'm working with the LIS3DSH accelerometer which is the accel2 click board on the raspberry pi. I was able to get the angles of x, y, and z-axis based on the binary reading and I was also able to determine the roll and pitch of the accelerometer based on the equation I found in the datasheet. The question I have is, how am I let it suppose to know that it has done a full 360-degree turn? As of now, it knows that when I turn the accelerometer tune 90 degrees, it shows me the angles of x and z plane with respect to the z-axis. As soon as the threshold gets more than 90 degrees, it resets to zero and does the math again. I am not able to implement it based on the figure I found in the datasheet which I have attached below, along with a snippet of my code which calculates the angles based on the readings outputted by the accelerometer. You can have a look at my whole '.c' code as well, which I have attached. How am I to do this?

0690X0000060BkZQAU.png0690X0000060BknQAE.png

#lis3dsh
1 ACCEPTED SOLUTION

Accepted Solutions
Rick Schue
Associate II
Posted on June 21, 2018 at 15:32

A single axis willl only give you information on which half of the 4-quadrant world you are in.  In your diagram,  a negative value of X will tell you if you are in one of the top 2 quadrants (quadrant 1 (0-90) or quadrant 2 (90-180)) or, if positive, one of the bottom two (quadrant 3 (180-270) and quadrant 4(270-360)).  To distinguish between the left and right halves of the world, you need another axis in quadrature (Y or Z depending on the orientation of the device).

Here's how I would approach the problem: 

Create a 2-bit (4-state) state machine that tracks the quadrants using two axis -  using the four combinations of positive and negative for each. Then compare the current readings with the previous and change from one state (quadrant) to the next based on the polarity changes - much the same way you would read a quadrature shaft encoder.  Be sure to handle transitions in both directions.

You could probably extend this to all three pairs or axes (X,Y), (X,Z), and (Y,Z) to separately track rotations in pitch, yaw, and roll.

View solution in original post

2 REPLIES 2
Rick Schue
Associate II
Posted on June 21, 2018 at 15:32

A single axis willl only give you information on which half of the 4-quadrant world you are in.  In your diagram,  a negative value of X will tell you if you are in one of the top 2 quadrants (quadrant 1 (0-90) or quadrant 2 (90-180)) or, if positive, one of the bottom two (quadrant 3 (180-270) and quadrant 4(270-360)).  To distinguish between the left and right halves of the world, you need another axis in quadrature (Y or Z depending on the orientation of the device).

Here's how I would approach the problem: 

Create a 2-bit (4-state) state machine that tracks the quadrants using two axis -  using the four combinations of positive and negative for each. Then compare the current readings with the previous and change from one state (quadrant) to the next based on the polarity changes - much the same way you would read a quadrature shaft encoder.  Be sure to handle transitions in both directions.

You could probably extend this to all three pairs or axes (X,Y), (X,Z), and (Y,Z) to separately track rotations in pitch, yaw, and roll.

Ashish Pamula
Associate
Posted on June 26, 2018 at 00:21

rick

‌, Thanks for the quick reply. Your explained approach was correct. I was able to get the correct values. Thanks again:)