I have a problem using the adafruit LSM6DSOX module. I'm trying to set the gyro x value to a variable but it doesn't seem to be working. Could somebody please help me?
`#include <Adafruit_LSM6DSOX.h>
Please give useful details about the actual problem, like the full text of error messages. Posting hints are given in the "How to get the best out of this forum" post.
It is a good idea to start with one of the working Adafruit examples provided in the library for that IMU, and make sure you understand it, before writing your own code.
The error is the following: error: cannot convert 'sensors_event_t' to 'float' in assignment
gyro_previous = gyro;
I would like some help to figure out which type of variable can be assigned to a sensors_event_t variable.
Use something like this instead. gyro_previous = gyro.gyro.x
However, this expression angle = (gyro_previous+gyro.gyro.x)*(millis()-time_previous)/2 + angle_previous;
does not appear to take into account the rate gyro contribution and scale factor properly, and will likely produce nonsensical angles.
Thank you !
I have one last question: how do I find out the structure type?
Could you link some code on how to create a similar struct and assign the gyro value?
Then it would be a good idea to carefully read through the tutorial I linked in post #9, and if that doesn't make the concept clear, perhaps some other tutorials.
is at least the average of the old reading and the new reading.
You may want to use a general version of that known as a leaky integrator, a kind of low pass filter with an adjustable factor for taking contributions to the new reading as some, not necessarily half, the new reading, and some, also not half the old reading, viz;
"A little of the new angle, and most of the previous angle"
Just use two constants that add up to 1.0. (0.1 and 0.9 in the example). The bigger the portion of the new angle you use, the faster the value will converge. You can try different values; the serial monitor plotting function can be useful.
The gyro outputs a rotation rate in degrees per second (after properly scaling the raw data), and to integrate that to measure an angle in 1 dimension only, one can do something like this in pseudocode.