Hi there, drvnm
A couple things , Not sure what configuration you are using and pretty sure/certain the demo’s are not tuned or calibrated in anyway and the data NOT filtered, so things to try, Check out the data sheet on the IMU make sure , I would first roll back the BSP to and earlier one and see if it has any effect then I would try the higher level examples , Also note the calibration data for each sensor is stored in the config registers , You also maybe could apply that data to your output
Without knowing more about your setup, It’s looks normal with a little error
I don’t see the IMU configuration in the code above?
Checkout some of other demo’s , ie. FreeFall , etc.
I had this problem a couple weeks ago. In section 4.1 of the LSM6DS3 datasheet there is a type column which gives you scaling constants depending on which mode you use. So if you want the correct acceleration you would read the raw acceleration and multiply by 0.061 assuming it’s in the ±2 mode (can be changed which register writes as well, check datasheet). Similarly, if you wanted to read the gyro, you would divide the raw value by 17.50
it seems to be already multiplying the ``typ``` constant. In your own code, do you multiply with the raw values of the gyro or with the readFloatGyro? as in the code you sent above, you dont multiply with the raw values.
Here is what i want to do again: I simply want to increment a counter everytime it rotates 180 degrees (3 counters for 3 directions)
Registers 5 and 6 control the angular rate sensor, so for example if you wanted 1000 dps you would write out the following
This means that you write to register 0x11 the hex data 0x8. The 0x11 comes from the datasheet screencap below and is right beside the title in the bold parenthesis (ignore the ‘h’). The 0x tells the compiler to read it as hex. That 0x8 might look a little confusing at first so we can break it down.
Since we want to change FS_G1 (position 5) and FS_G0 (position 6) we would write out the following data 00001000, the first four zeros are the default value, the next values denote the 1000 dps, the next is default value, and the final must be 0 (table 49). I then take 00001000 and put it in a binary to hex converter, which becomes 8 and then is written to the register.
Additionally, you can check below before you write to the register to see the default is 250 dps.
I mistakenly put readFloatGyro (oopsies!), but yes you’ll read the raw value and then divide it by the coefficient. I think the readFloatGyro attempts to check the register, to clean up the data, but it dividing the raw val does the job as well.
For your use case, reading when it rotates 180 degrees would mean you need create a new variable to sum up each new measurement. Gyros read in deg/s but you need deg.
A final consideration is using something like a complimentary filter to reduce gyro drift (since it’ll mess up your readings). ‘Phil’s Lab’ on youtube has a great video about complementary filters.
Ok that’s good to hear.
You’ll need to read the data sheet and perhaps print out the GYRO config registers in your code and review the settings. After edit the settings to be pertinent to your application needs, BTW the Demo’s are just that , they don’t do anything super fancy Just shows the chip is working and that your code is NOT garbage. The rest is up to
I’m using the floats, here,
// Calculate gyro motion magnitude based on gyroscope data (you can adjust the threshold as needed)
float gyroMotionMagnitude = sqrt(gyroX * gyroX + gyroY * gyroY + gyroZ * gyroZ);
For my application, This line of code calculates the magnitude (or length) of a three-dimensional vector using the formula for Euclidean distance. The vector components are gyroX, gyroY, and gyroZ.
Here’s a breakdown of the line:
gyroX, gyroY, and gyroZ are variables representing the components of a three-dimensional vector, likely obtained from a gyroscope sensor or a similar source.
gyroX * gyroX + gyroY * gyroY + gyroZ * gyroZ calculates the sum of the squares of each vector component.
sqrt(...) calculates the square root of the sum of squares, resulting in the magnitude of the three-dimensional vector.
So, gyroMotionMagnitude will contain the length of the vector represented by the gyroX, gyroY, and gyroZ components.
This is often used in applications where the overall motion or acceleration of a device in three-dimensional space needs to be measured or analyzed.
What you need to do is not that difficult,
what code do you have so far ? Post it up we can suggest edits.
You can change these with register writes if you want
I think these might also be 17.50 instead of 16.50
Yeah the drift is pretty bad! But there are some ways to get around it. There are some filters that can be used that use sensor fusion (combination of data from multiple sensors) to lessen the error. The video below talks about a complimentary filter which combines data from the accel and data from the gyro to help negate the drift. There are some filters that are talked about in later videos, but the complementary one is a great place to start!
I haven’t implemented it into my work application yet, so I can’t provide much insight.
Additionally, you could add a ‘calibration’ section where you let the board run for maybe ~10 seconds or so to collect data and then average them together. You could then subtract your average from the measured values. Its a pretty rough approach, but it might be able to work depending on the length of time you want to measure data.