-
Notifications
You must be signed in to change notification settings - Fork 28
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Arduino Nano 33 BLE with LSM9DS1 sensor -> problem with implementation Madgwick libary #14
Comments
… On Sun, Feb 16, 2020 at 2:41 PM mataldomen ***@***.***> wrote:
Hey Kris,
I am writing to You becouse I have big problem with my Arduino board and I
can't resolve this from week.
I want to implement Madgwick filter and quaternions into my Arduino Nano
33 BLE board. After that i receive a lot of really crazy numbers without
any sense.
I configured My board with ArduinoLSM9DS1 libary (
https://www.arduino.cc/en/Reference/ArduinoLSM9DS1) it's really simply
part of code in comparison into yours. For me is perfect beacouse I am
beginner.
In my first use of this board I used data from sensors and I calculated
Eulers angles to receive pitch,roll and yaw. I received preety good numbers.
Nextly I want to implement madgwick from here(
https://x-io.co.uk/open-source-imu-and-ahrs-algorithms/)
Maybe You know with Your experience why I still cant use Madgwick on my
board ? Maybe You done someting before on this board ?
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#14?email_source=notifications&email_token=ABTDLKT4IQWS4W7FJ7UK27TRDG6I7A5CNFSM4KWHMCK2YY3PNVWWK3TUL52HS4DFUVEXG43VMWVGG33NNVSW45C7NFSM4IN4HDRQ>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ABTDLKTHWB3ZTXW2VQFE5CDRDG6I7ANCNFSM4KWHMCKQ>
.
|
Hi Kris How did you go translating the example for the nano 33? Did you want to share some code maybe we can figure it out together? |
I did not translate the sketch for the Nano33, I have never used the Nano33.
Did you calibrate the sensors? How?
…On Sun, Feb 23, 2020 at 8:05 AM Michael Bell ***@***.***> wrote:
Hi Kris
How did you go translating the example for the nano 33?
I am also struggling a little getting accurate results with the new boards.
Did you want to share some code maybe we can figure it out together?
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#14?email_source=notifications&email_token=ABTDLKW35FR4GD7HRDGFZIDREKNCXA5CNFSM4KWHMCK2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEMV7SEA#issuecomment-590084368>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ABTDLKXTAG7R7VXTELLH4FLREKNCXANCNFSM4KWHMCKQ>
.
|
Ah sorry I meant @mataldomen :) I've managed to get some calibration data from motioncal but reapplying the offsets has been a little difficult. I was hoping to have some realtime calibration methods when the device starts up. I'll try your methods to see if I can implement it. |
You can try this version of the Madgwick lib for the nano 33 ble.
|
Hi @MichaelFBA Do You have any ideas how calibrate them properly ? |
This repo has examples of how to calibrate the sensor at runtime, we would need to modify it to conform with the Arduino imu API. I had a quick look at trying to migrate the code but haven't managed to finish it yet. There is a lot going on. |
As I was researching this topic, I discovered this message on the Arduino forum that could provide additional insights: https://forum.arduino.cc/index.php?topic=663160.msg4467543#msg4467543 Accoding to the illustration presented, magnetometer axis are flippped from the ones on accelerometerand gyroscopes. It also seems that rotation is left handed! |
Yes, this is all in the data sheet which everone who is using this sensor
should read completely, perhaps any times. The specific orientation of the
sensor axes has to be taken into account in the Madgwick or Mahony fusion
call.
…On Mon, Apr 20, 2020 at 2:57 AM César García ***@***.***> wrote:
As I was researching this topic, I discover this topic on the Arduino
forum that could provide additional insights:
https://forum.arduino.cc/index.php?topic=663160.msg4467543#msg4467543
Accoding to the illustriation presented, magnetometer axis are flippped
from the ones on accelerometerand gyroscopes. It also seems that rotation
is left handed!
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#14 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ABTDLKTQ5XVS6JQ2FAXZTFLRNQMA3ANCNFSM4KWHMCKQ>
.
|
Thanks @kriswiner for your response! |
Hello @MichaelFBA and @mataldomen , were either of you able to calibrate this sensor for the Arduino Nano 33 BLE? I have been stuck on this for a few days now. I tried changing the sensor axis and still cannot get it to work. |
Hello, I cant help You. If You have to set orientation based on quaternions maybe You should buy another sensor which calculating quaternions without madgwick library. On market is big choice but these sensors are more expensive than this in our Arduinos :D |
https://www.youtube.com/watch?v=T9jXoG0QYIA @mataldomen @MichaelFBA @Jeremiah1327 @elsatch I hope I'm not too late for you guys but I've recently have been working on the same problem and I've found some resources. As you can see from this video it's possible to calibrate the magnetometer without any libraries in a sort of brute force manner by taking a bunch of measurements in different places over a period of time, finding the median x y and z values and shifting them to 0 where 0 - median would be the offset that you could then add to every magnetometer reading and achieve calibration. I haven't looked just yet but I bet there are some 3D plotting libraries to help with this as well. It also seemed implied by the video that accelerometer values and gyroscope values were okay and didn't need to be calibrated, but I'm not sure if that is the case. I have noticed that the accelerometer and gyroscope read a little bit of noise when at rest and I think that disregarding values below some noise threshold might be enough. I've also looked into motion cal https://learn.adafruit.com/adafruit-sensorlab-magnetometer-calibration/magnetic-calibration-with-motioncal but I'm struggling to get the sketches to work on the Nano 33 BLE Sense, if some of you guys want to try them, let me know if you can get them to work. I've also experimented with using this algorithm: https://x-io.co.uk/open-source-imu-and-ahrs-algorithms/ in my receiver program to calculate a quaternion of rotation given the raw sensor data over bluetooth from my arduino, but the end result seems to be very inacurate and some of the axes seem to be wrong. I haven't calibrated yet so that might be part of my issue, also I have been randomly experimenting with the beta and sample period parameters since I'm not really sure what they're supposed to be, so that also might be a contributing factor lol but that's where I've gotten so far, let me know if anyone has more information, thanks! |
Basic accel/gyro, and mag calibration as well as quaternions are
implemented here
<https://github.com/kriswiner/LSM9DS1/blob/master/LSM9DS1_MS5611_BasicAHRS_t3.ino>.
Just need to make some small changes for your platforms. Not sure why this
is such a mystery....
…On Sun, May 31, 2020 at 9:26 PM Cole Lashley ***@***.***> wrote:
https://www.youtube.com/watch?v=T9jXoG0QYIA
@mataldomen <https://github.com/mataldomen> @MichaelFBA
<https://github.com/MichaelFBA> @Jeremiah1327
<https://github.com/Jeremiah1327> @elsatch <https://github.com/elsatch> I
hope I'm not too late for you guys but I've recently have been working on
the same problem and I've found some resources. As you can see from this
video it's possible to calibrate the magnetometer without any libraries in
a sort of brute force manner by taking a bunch of measurements in different
places over a period of time, finding the median x y and z values and
shifting them to 0 where median - 0 would be the offset that you could then
add to every magnetometer reading and achieve calibration. I haven't looked
just yet but I bet there are some 3D plotting libraries to help with this
as well. It also seemed implied by the video that accelerometer values and
gyroscope values were okay and didn't need to be calibrated, but I'm not
sure if that is the case. I have noticed that the accelerometer and
gyroscope read a little bit of noise when at rest and I think that
disregarding values below some noise threshold might be enough.
I've also looked into motion cal
https://learn.adafruit.com/adafruit-sensorlab-magnetometer-calibration/magnetic-calibration-with-motioncal
but I'm struggling to get the sketches to work on the Nano 33 BLE Sense, if
some of you guys want to try them, let me know if you can get them to work.
I've also experimented with using this algorithm:
https://x-io.co.uk/open-source-imu-and-ahrs-algorithms/ in my receiver
program to calculate a quaternion of rotation given the raw sensor data
over bluetooth from my arduino, but the end result seems to be very
inacurate and some of the axes seem to be wrong. I haven't calibrated yet
so that might be part of my issue, also I have been randomly experimenting
with the beta and sample period parameters since I'm not really sure what
they're supposed to be, so that also might be a contributing factor lol
but that's where I've gotten so far, let me know if anyone has more
information, thanks!
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#14 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ABTDLKS6DWBPAG3M7OG6NCDRUMUWHANCNFSM4KWHMCKQ>
.
|
Apologies, I’m a bit new to this. I saw that but I was a bit deterred because there was a lot of code that I didn’t understand. Is this a library that you can get from the arduino store or at least import into the arduino editor? And what would we need to change to make it compatible with the arduino nano 33 ble sense? |
Probably just need to change the Wire methods since i2c_t3.h is Teensy only.
But you can certainly copy the methods for accel/gyro calibration, mag
calibration, and quaternion determination. This sketch is not meant to be a
black box that you can plug into your Nano but rather an illustration of
methods that can be used.
…On Mon, Jun 1, 2020 at 8:17 AM Cole Lashley ***@***.***> wrote:
Apologies, I’m a bit new to this. I saw that but I was a bit deterred
because there was a lot of code that I didn’t understand. Is this a library
that you can get from the arduino store or at least import into the arduino
editor? And what would we need to change to make it compatible with the
arduino nano 33 ble sense?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#14 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ABTDLKQRAZ4DANGEFA6OH23RUPA7NANCNFSM4KWHMCKQ>
.
|
@MrStashley I spent many hours a day for over a week trying to get it to work. I watched a lot of YouTube videos about IMU calibration methods and tried to modify the numerous LSM9DS1 codes. I tried to modify @kriswiner 's code but still could not get it figured out. I bought the Arduino Nano BlE Sense for the purpose of having a built in IMU that would be easy to use. I decided to just try out different IMU/Microcontrollers with working libraries. I simply do not have the time and coding experience to do get it working with the BLE Sense and am not willing to sacrifice more time to get it to work, as I have deadlines for my project. If you end up figuring it out though, that would be awesome. |
@Jeremiah1327 ah okay. I'm still doing research and I haven't yet gotten around to trying to get @kriswiner 's code to work, but I have looked at and I see some stuff that seems promising, and getting another IMU is a last resort for me because I need the ble chip, but it might come to that for me as well. Which IMU did you end up buying that worked for you? |
@kriswiner do you know how I could implement the writeByte method in a way that would work on my nano 33 ble sense? |
This works on the ESP8252 and is pretty generic:
// I2C read/write functions
void writeByte(uint8_t address, uint8_t subAddress, uint8_t data)
{
Wire.beginTransmission(address); // Initialize the Tx buffer
Wire.write(subAddress); // Put slave register address in Tx buffer
Wire.write(data); // Put data in Tx buffer
Wire.endTransmission(); // Send the Tx buffer
}
uint8_t readByte(uint8_t address, uint8_t subAddress)
{
uint8_t data; // `data` will store the register data
Wire.beginTransmission(address); // Initialize the Tx buffer
Wire.write(subAddress); // Put slave register address in Tx buffer
Wire.endTransmission(false); // Send the Tx buffer, but send a restart to
keep connection alive
Wire.requestFrom(address, 1); // Read one byte from slave register address
data = Wire.read(); // Fill Rx buffer with result
return data; // Return data read from slave register
}
void readBytes(uint8_t address, uint8_t subAddress, uint8_t count, uint8_t
* dest)
{
Wire.beginTransmission(address); // Initialize the Tx buffer
Wire.write(subAddress); // Put slave register address in Tx buffer
Wire.endTransmission(false); // Send the Tx buffer, but send a restart to
keep connection alive
uint8_t i = 0;
Wire.requestFrom(address, count); // Read bytes from slave register address
while (Wire.available()) {
dest[i++] = Wire.read(); } // Put read results in the Rx buffer
}
- © 2020 GitHub, Inc.
- Terms <https://github.com/site/terms>
- Privacy <https://github.com/site/privacy>
- Security <https://github.com/security>
- Status <https://githubstatus.com/>
- Help <https://help.github.com>
<https://github.com>
…On Mon, Jun 1, 2020 at 6:43 PM Cole Lashley ***@***.***> wrote:
@kriswiner <https://github.com/kriswiner> do you know how I could
implement the writeByte method in a way that would work on my nano 33 ble
sense?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#14 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ABTDLKSSRY5WGPM3PIA4VY3RURKL7ANCNFSM4KWHMCKQ>
.
|
Ah okay. I thought Wire was a library that I might have to replace but my editor seems to think it's fine. The error I'm getting now is that I2C_NOSTOP was not declared in this scope and it seems that it wasn't declared in your code either. Is this a constant that I can define or something native to a certain kind of board? |
This is for i2c_t3.h only, replace with false as in the code snippets I
sent you.
…On Mon, Jun 1, 2020 at 7:06 PM Cole Lashley ***@***.***> wrote:
Ah okay. I thought Wire was a library that I might have to replace but my
editor seems to think it's fine. The error I'm getting now is that
I2C_NOSTOP was not declared in this scope and it seems that it wasn't
declared in your code either. Is this a constant that I can define or
something native to a certain kind of board?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#14 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ABTDLKVJX3SPE2IESI4EDF3RURNDVANCNFSM4KWHMCKQ>
.
|
ahh okay my bad I didn't notice. Thanks a ton :) |
So the writeByte method causes the Mbed OS to crash. It could be an issue with the actual registers used in the calls but the first writeByte call in accelgyrocal and in magcal crashes the OS. I'm sure this problem is way out of my expertise league, and it might just be a compatibility issue that's impossible to fix, but can you think of anything that might be related to the issue that I could look into? |
Run! Run away as fast as you can from MBED....
…On Mon, Jun 1, 2020 at 8:02 PM Cole Lashley ***@***.***> wrote:
So the writeByte method causes the Mbed OS to crash. It could be an issue
with the actual registers used in the calls but the first writeByte call in
accelgyrocal and in magcal crashes the OS. I'm sure this problem is way out
of my expertise league, and it might just be a compatibility issue that's
impossible to fix, but can you think of anything that might be related to
the issue that I could look into?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#14 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ABTDLKXSZ2D3VBEPXLSCMUDRURTV7ANCNFSM4KWHMCKQ>
.
|
Ah okay that's what I'm finding out lol. It sucks because the Nano 33 ble sense has everything I need for my project in terms of sensors and ble capability. Do you know of any other boards that have similar capabilities but don't have the annoying issue of being compatible with nothing? |
Is there not an Arduino core for the Nano33?
https://www.arduino.cc/en/Guide/NANO33BLESense
…On Mon, Jun 1, 2020 at 8:29 PM Cole Lashley ***@***.***> wrote:
Ah okay that's what I'm finding out lol. It sucks because the Nano 33 ble
sense has everything I need for my project in terms of sensors and ble
capability. Do you know of any other boards that have similar capabilities
but don't have the annoying issue of being compatible with nothing?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#14 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ABTDLKX2SBS6QFTLUPJ4HWLRURWYNANCNFSM4KWHMCKQ>
.
|
There is, it's just that none of the calibration libraries are compatible with the board so I haven't been able to calibrate the sensors and I can't get the AHRS algorithm to spit out numbers that makes even close to sense. I've heard that the sensors on the nano 33 ble sense have coordinate planes in wierd directions and that the accelerometer and gyroscope have left handed coordinate planes and I think that might be contributing to my error as well, but I'm not really sure how to fix it. |
The Madgwick fusion algorithm required the sensors data be fed in in NED
convention.
Besides, if using the Arduino IDE, you can just run my sketch (with slight
modification) and get all of this.
…On Mon, Jun 1, 2020 at 9:43 PM Cole Lashley ***@***.***> wrote:
There is, it's just that none of the calibration libraries are compatible
with the board so I haven't been able to calibrate the sensors and I can't
get the AHRS algorithm to spit out numbers that makes even close to sense.
I've heard that the sensors on the nano 33 ble sense have coordinate planes
in wierd directions and that the accelerometer and gyroscope have left
handed coordinate planes and I think that might be contributing to my error
as well, but I'm not really sure how to fix it.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#14 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ABTDLKWG744QS644CH2YNS3RUR7OXANCNFSM4KWHMCKQ>
.
|
ah okay thank you for that. I'll look into which axes I need to switch to get NED. well except that the writeByte function causes the Mbed OS to crash. Do you think that it's an issue with the location of the registers on my board or an issue with the Wire functions? |
The magic of Black-box Arduino sketch + Sensor breakout bought online ==
Accurate absolute orientation estimation rarely happens in my experience.
If this works for you using the BNO055, then great, end of discussion.
For most of us, sensor quality + adequate sensor calibration are the key
ingredients to accuracy.
There are much better sensors now than the LSM6DS1 (the BNO055 is not among
them).
But I suspect your problem with "didn't get it to work properly" is
inadequate calibration, which is something I can help with if you are
willing to step out of the "works like a charm right out of the box"
fantasy world.
…On Wed, Mar 17, 2021 at 2:51 AM StRob1980 ***@***.***> wrote:
I struggled with
https://github.com/kriswiner/LSM9DS1/blob/master/LSM9DS1_BasicAHRS_Nano33.ino
and still didn't get it to work properly. Drift in heading when turning the
board. If you turn the board on a flat surface back and fourth you will end
up in different heading and slowly compensating (minutes). If I remember
correctly the orientation is not correctly compensated to NED, I had to
change sign on some. (believe it is mentioned in my earlier comments).
After alot of effort I bought a BNO055 just to see what is achivable and I
can say that it works like a charm right out of the box. Even without
calibration if you are not interested in absolute heading, just relative.
No offence, we all appreciate all of your support, but I think it´s fair
to say that the sketch provided is not complete and working for the
Nano33BLE. At least as far as I could see.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#14 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ABTDLKXBHSOLELXBNBI3Q43TEB3SDANCNFSM4KWHMCKQ>
.
|
I got it to work! One of the main hang-ups was changing D1 & D2 (as others mentioned) to something like pinD1 & pinD2. The other half of my struggle was adjusting the code to feed into Unity and capture it on that side, which I finally got through. Next is dialing in sensitivity as well as orienting the w/x/y/z axis with that of the object. But that is NOTHING compared to the work you put into this library. I don't know how to thank you! And am learning so much in the process. @j-mcc1993 @kriswiner |
It might be inadequate calibration, sure. I followed the calibration routine in the code and also tried with increased number of samples. I did it on a wooden table far from any magnetic interference. I tried to get some other examples with hard and soft iron calibration to work with my Nano33BLE but with no luck unfortunately. @willyconcarne12 Did you get the heading/yaw responsive and somewhat accurate? |
@StRob1980 I appreciate your take as I appear to be in a similar boat. I am still wading through the right levers to pull and what each one does specifically as well as reading the the side notes with each section. For example, GyroMeasError (264, 265) comments seem completely relevant to optimizing performance vs. accuracy ("...not fast enough for a quadcopter or robot car!" [without adjustments]). Accuracy vs. response speed vs. sampling rates vs. bias, etc. levers to try to learn, pull and balance. Heck of a wrestling match going on over here! Thrilled I have the data now feeding and I'm moving the object, but the new brick wall has appeared in trying to get the model object oriented with the sensor and stable. No disconnects occurring so far which is great and when I lay it flat it will stabilize back to it's original position after a few seconds, but sense there's a lot more mountain to climb. |
@willyconcarne12 I hope we can follow your progress here. I wish you a happy climbing. :) |
Actually, the accel data look OK, so maybe a problem with the reporting of
your biases?
Mag calibration way off though. magnitude of mag vector should be ~450
mgauss. When comparing face up Mz or face down Mz should be equal and
opposite, etc.
…On Wed, Mar 31, 2021 at 3:16 PM willyconcarne12 ***@***.***> wrote:
Ok so still at it - making progress. It seems my calibration/bias is way
off on:
1. accelerometer, especially z-axis (bias 952)
2. magnetometer
[image: Calibration]
<https://user-images.githubusercontent.com/58528850/113218132-a181c580-9244-11eb-981c-47fc91e75376.PNG>
I have tried toggling just about everything... any thoughts?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#14 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ABTDLKSTNQYHSIU7CGCOJ33TGONK7ANCNFSM4KWHMCKQ>
.
|
Well that's good on accel! Hmmm... well here are the current initial params (I have been trying different things completely off the wall if you can't tell...)... // Using the LSM9DS1+MS5611 Teensy 3.1 Add-On shield, ADO is set to 1 #define SerialDebug true // set to true to get Serial output for debugging // Set initial input parameters enum Aodr { // set of allowable gyro sample rates enum Abw { // set of allowable accewl bandwidths enum Gscale { // set of allowable gyro full scale settings enum Godr { // set of allowable gyro sample rates enum Gbw { // set of allowable gyro data bandwidths enum Mscale { // set of allowable mag full scale settings enum Mmode { enum Modr { // set of allowable mag sample rates #define ADC_256 0x00 // define pressure and temperature conversion rates // Specify sensor full scale -- Also, does ADO have any effect on that? |
No. Take a look here
<https://github.com/kriswiner/MPU6050/wiki/Simple-and-Effective-Magnetometer-Calibration>
and try again on the mag calibration.
…On Wed, Mar 31, 2021 at 4:09 PM willyconcarne12 ***@***.***> wrote:
Well that's good on accel!
Hmmm... well here are the current initial params (I have been trying
different things completely off the wall if you can't tell...)...
// Using the LSM9DS1+MS5611 Teensy 3.1 Add-On shield, ADO is set to 1
// Seven-bit device address of accel/gyro is 110101 for ADO = 0 and 110101
for ADO = 1
#define ADO 1
#if ADO
#define LSM9DS1XG_ADDRESS 0x6B // Device address when ADO = 1
#define LSM9DS1M_ADDRESS 0x1E // Address of magnetometer
#define MS5611_ADDRESS 0x77 // Address of altimeter
#else
#define LSM9DS1XG_ADDRESS 0x6A // Device address when ADO = 0
#define LSM9DS1M_ADDRESS 0x1D // Address of magnetometer
#define MS5611_ADDRESS 0x77 // Address of altimeter
#endif
#define SerialDebug true // set to true to get Serial output for debugging
// Set initial input parameters
enum Ascale { // set of allowable accel full scale settings
AFS_2G,
AFS_4G,
AFS_8G,
AFS_16G
};
enum Aodr { // set of allowable gyro sample rates
AODR_PowerDown,
AODR_10Hz,
AODR_50Hz,
AODR_119Hz,
AODR_238Hz = 1,
AODR_476Hz,
AODR_952Hz
};
enum Abw { // set of allowable accewl bandwidths
ABW_408Hz = 1,
ABW_211Hz,
ABW_105Hz,
ABW_50Hz
};
enum Gscale { // set of allowable gyro full scale settings
GFS_245DPS,
GFS_500DPS = 1,
GFS_NoOp,
GFS_2000DPS
};
enum Godr { // set of allowable gyro sample rates
GODR_PowerDown,
GODR_14_9Hz,
GODR_59_5Hz,
GODR_119Hz,
GODR_238Hz = 1,
GODR_476Hz,
GODR_952Hz
};
enum Gbw { // set of allowable gyro data bandwidths
GBW_low, // 14 Hz at Godr = 238 Hz, 33 Hz at Godr = 952 Hz
GBW_med, // 29 Hz at Godr = 238 Hz, 40 Hz at Godr = 952 Hz
GBW_high = 1, // 63 Hz at Godr = 238 Hz, 58 Hz at Godr = 952 Hz
GBW_highest // 78 Hz at Godr = 238 Hz, 100 Hz at Godr = 952 Hz
};
enum Mscale { // set of allowable mag full scale settings
MFS_4G,
MFS_8G,
MFS_12G,
MFS_16G
};
enum Mmode {
MMode_LowPower,
MMode_MedPerformance,
MMode_HighPerformance = 1,
MMode_UltraHighPerformance
};
enum Modr { // set of allowable mag sample rates
MODR_0_625Hz,
MODR_1_25Hz,
MODR_2_5Hz,
MODR_5Hz,
MODR_10Hz,
MODR_20Hz,
MODR_80Hz = 1
};
#define ADC_256 0x00 // define pressure and temperature conversion rates
#define ADC_512 0x02
#define ADC_1024 0x04
#define ADC_2048 0x06
#define ADC_4096 0x08
#define ADC_D1 0x40
#define ADC_D2 0x50
// Specify sensor full scale
uint8_t OSR = ADC_4096; // set pressure amd temperature oversample rate
uint8_t Gscale = GFS_500DPS; // gyro full scale
uint8_t Godr = GODR_238Hz; // gyro data sample rate
uint8_t Gbw = GBW_high; // gyro data bandwidth
uint8_t Ascale = AFS_8G; // accel full scale
uint8_t Aodr = AODR_238Hz; // accel data sample rate
uint8_t Abw = ABW_408Hz; // accel data bandwidth
uint8_t Mscale = MFS_8G; // mag full scale
uint8_t Modr = MODR_80Hz; // mag data sample rate
uint8_t Mmode = MMode_HighPerformance; // magnetometer operation mode
float aRes, gRes, mRes; // scale resolutions per LSB for the sensors
--
Also, does ADO have any effect on that?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#14 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ABTDLKWOW4CT7OLWO73HVKLTGOTRLANCNFSM4KWHMCKQ>
.
|
Wow, way wrong.
Did you move the sensors in all three dimensions while gathering the mag
calibration data?
…On Wed, Mar 31, 2021 at 8:46 PM willyconcarne12 ***@***.***> wrote:
Thanks for sending this - I tried out adding the mag_max and mag_min from
the code included:
(int16_t mag_max[3] = {-32767, -32767, -32767}, mag_min[3] = {32767,
32767, 32767};)
*instead of*
(int16_t mag_max[3] = {0, 0, 0}, mag_min[3] = {0, 0, 0};)
Calibration Result:
[image: Calibration 2]
<https://user-images.githubusercontent.com/58528850/113240510-7746fc80-9272-11eb-9ce3-5df72f57ef8a.PNG>
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#14 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ABTDLKT6LNFAD7JJUS5EPVDTGPUBPANCNFSM4KWHMCKQ>
.
|
One thing that hasn't come up here... have you all been adjusting the magnetic declination parameter? That parameter depends on your location, and unless you happen to live in the SF Bay Area, the parameter that's in the code won't be accurate to your location. |
@kriswiner Doh! Yes I moved the sensor in a figure eight like it said (rotating it while also waving) while calibrating. Just tried it again with it sitting completely still the entire calibration and got these results. @j-mcc1993 great point - yes I had updated the location (using https://www.magnetic-declination.com/). I'm in Dallas so have +2.56 in there vs 13.3 for San Fran. I'm hoping that once calibration is fixed, that should be the fix for my unstable axis when rotating the sensor (ex. x-axis pointing left from sensor start position --> perform twist motion with the sensor and return to start position --> x-axis is now pointing up or some other direction). IMG_2490.mp4 |
Something is way wrong with the mag data. How are you applying the mag
calibrations?
…On Thu, Apr 1, 2021 at 7:45 AM willyconcarne12 ***@***.***> wrote:
@kriswiner <https://github.com/kriswiner> Doh! Yes I moved the sensor in
a figure eight like it said (rotating it while also waving) while
calibrating. Just tried it again with it sitting completely still the
entire calibration and got these results.
[image: Calibration 3]
<https://user-images.githubusercontent.com/58528850/113310964-675d0600-92ce-11eb-83c7-92752ddd1b6c.PNG>
@j-mcc1993 <https://github.com/j-mcc1993> great point - yes I had updated
the location (using https://www.magnetic-declination.com/). I'm in Dallas
so have +2.56 in there vs 13.3 for San Fran.
I'm hoping that once calibration is fixed, that should be the fix for my
unstable axis when rotating the sensor (ex. x-axis pointing left from
sensor start position --> perform twist motion with the sensor and return
to start position --> x-axis is now pointing up or some other direction).
https://user-images.githubusercontent.com/58528850/113311491-fb2ed200-92ce-11eb-804d-28863846c505.mp4
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#14 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ABTDLKWUKYOZWWDGAOH2Q6DTGSBKBANCNFSM4KWHMCKQ>
.
|
Hate to sound helpless but I'm not sure what to pull to answer your question (and thank you so much for helping/any guidance! really trying to learn). Should I send you my sketch? |
Yes, ***@***.***
…On Thu, Apr 1, 2021 at 10:23 AM willyconcarne12 ***@***.***> wrote:
Hate to sound helpless but I'm not sure what to pull to answer your
question (and thank you so much for helping/any guidance! really trying to
learn).
Should I send you my sketch?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#14 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ABTDLKQKTT2PUTPGXKL7EM3TGSTY5ANCNFSM4KWHMCKQ>
.
|
Awesome. Your email is redacted on here (@.***) but I just sent you a private message on hackaday.io (if you still have access to that) w/ a link to the sketch. |
// Calculate the magnetometer values in milliGauss
// Include factory calibration per data sheet and user environmental
corrections
mx = (float)magCount[0] * mRes;* // - magBias[0];* // get actual
magnetometer value, this depends on scale being set
my = (float)magCount[1] * mRes; *// - magBias[1];*
mz = (float)magCount[2] * mRes; *// - magBias[2];*
You are not applying the magBias values, why not? Uncomment and try again...
…On Thu, Apr 1, 2021 at 11:19 AM willyconcarne12 ***@***.***> wrote:
Awesome. Your email is redacted on here (*@*.***) but I just sent you a
private message on hackaday.io (if you still have access to that) w/ a
link to the sketch.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#14 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ABTDLKUOJA2RBQPWT6PAW53TGS2KLANCNFSM4KWHMCKQ>
.
|
Better, but there is still something wrong. When you weren;t using the
biases, you were showing very small mag values. Probably a scaling issue
somewhere...
Look up the local mag field expected (use USGS site) and compare to what
you are getting. Where I am I should see (X,Y, Z) 50, 200, and 400
milligauss, and when properly calibrated this is about what I see. Plus try
the face up/face down test. Are the Mz values equal and opposite? What is
the scale value of the mag vector, should be ~450 mG, etc. Lots of tests to
see if your mag values are reasonable.
…On Thu, Apr 1, 2021 at 11:39 AM willyconcarne12 ***@***.***> wrote:
[image: Calibration 4]
<https://user-images.githubusercontent.com/58528850/113339164-b2d3dc00-92ef-11eb-914c-a2d8f50e8b63.PNG>
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#14 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ABTDLKSUQUW2OFJ545XNBGDTGS4XZANCNFSM4KWHMCKQ>
.
|
OK, I just noticed that the mag biases are set to be written to the mag
bias registers, that's why it was commented out in the main loop. So I
would go back to commenting these out and then ask, why are the mag values
so low?
On Thu, Apr 1, 2021 at 11:50 AM Tlera Corporation ***@***.***>
wrote:
… Better, but there is still something wrong. When you weren;t using the
biases, you were showing very small mag values. Probably a scaling issue
somewhere...
Look up the local mag field expected (use USGS site) and compare to what
you are getting. Where I am I should see (X,Y, Z) 50, 200, and 400
milligauss, and when properly calibrated this is about what I see. Plus try
the face up/face down test. Are the Mz values equal and opposite? What is
the scale value of the mag vector, should be ~450 mG, etc. Lots of tests to
see if your mag values are reasonable.
On Thu, Apr 1, 2021 at 11:39 AM willyconcarne12 ***@***.***>
wrote:
> [image: Calibration 4]
> <https://user-images.githubusercontent.com/58528850/113339164-b2d3dc00-92ef-11eb-914c-a2d8f50e8b63.PNG>
>
> —
> You are receiving this because you were mentioned.
> Reply to this email directly, view it on GitHub
> <#14 (comment)>,
> or unsubscribe
> <https://github.com/notifications/unsubscribe-auth/ABTDLKSUQUW2OFJ545XNBGDTGS4XZANCNFSM4KWHMCKQ>
> .
>
|
I have been pouring through... I wonder if it has to do with the Device address and/or Mag address. I am only using an Arduino Nano 33 BLE (i.e. NOT +MS5611 Teensy 3.1 Add-On shield). However, when I set #define ADO 1 to #define ADO 0, I can't get any data to come across the monitor. // Using the LSM9DS1+MS5611 Teensy 3.1 Add-On shield, ADO is set to 1 |
Has nothing to do with device addresses.
It has to do with how the mag data is being converted from bytes to int16,
how it is being scaled to milligs and how the calibration is being applied.
What I don;t understand is the sketches in my github repo just work, so how
could you be having such trouble? Is it the Nano?
…On Thu, Apr 1, 2021 at 5:36 PM willyconcarne12 ***@***.***> wrote:
I have been pouring through... I wonder if it has to do with the Device
address and/or Mag address. I am only using an Arduino Nano 33 BLE (i.e.
NOT +MS5611 Teensy 3.1 Add-On shield). However, when I set #define ADO 1 to
#define ADO 0, I can't get any data to come across the monitor.
// Using the LSM9DS1+MS5611 Teensy 3.1 Add-On shield, ADO is set to 1
// Seven-bit device address of accel/gyro is 110101 for ADO = 0 and 110101
for ADO = 1
#define ADO 1
#if ADO
#define LSM9DS1XG_ADDRESS 0x6B // Device address when ADO = 1
#define LSM9DS1M_ADDRESS 0x1E // Address of magnetometer
#define MS5611_ADDRESS 0x77 // Address of altimeter
#else
#define LSM9DS1XG_ADDRESS 0x6A // Device address when ADO = 0
#define LSM9DS1M_ADDRESS 0x1D // Address of magnetometer
#define MS5611_ADDRESS 0x77 // Address of altimeter
#endif
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#14 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ABTDLKVCTZKM6EF5NYQNZ73TGUGSVANCNFSM4KWHMCKQ>
.
|
I apologize in advance if this is also not anywhere close to the solution, but trying to help. I do see a few differences looking at the sketch vs. the code snippet in the wiki you sent (https://github.com/kriswiner/MPU6050/wiki/Simple-and-Effective-Magnetometer-Calibration). Sketch includes a "uint8_t data[6]" vs. wiki snippet I also see a dest 1 AND dest 2 in mag_scale of the snippet but only dest 1 in the sketch (or at least in the same section; may be located elsewhere or not needed?). Sketch vs. snippet float avg_rad = mag_scale[0] + mag_scale[1] + mag_scale[2]; dest2[0] = avg_rad/((float)mag_scale[0]); |
That is an extra bit of calibration to equalize the response on the three
axes. Not the cause of your trouble.
What I don't understand is that even without mag calibration you should be
seeing reasonable values for the mag field. Your mag offset biases are
rather large and when you apply them you are getting somewhat odd mag field
values.
I would take a look at the mag output with no calibration, and then with
the calibration to see if the code is doing what you expect. Even just
siting still on a table and uncalibrated, you should get sensible mag data
that approximates what the USGS says is typical for your area.
…On Thu, Apr 1, 2021 at 7:29 PM willyconcarne12 ***@***.***> wrote:
I apologize in advance if this is also not anywhere close to the solution,
but trying to help. I do see a few differences looking at the sketch vs.
the code snippet in the wiki you sent (
https://github.com/kriswiner/MPU6050/wiki/Simple-and-Effective-Magnetometer-Calibration
).
*Sketch includes a "uint8_t data[6]"*
uint8_t data[6]; // data array to hold mag x, y, z, data
uint16_t ii = 0, sample_count = 0;
int32_t mag_bias[3] = {0, 0, 0};
int16_t mag_max[3] = {-32767, -32767, -32767}, mag_min[3] = {32767, 32767,
32767};
*vs. wiki snippet*
uint16_t ii = 0, sample_count = 0;
int32_t mag_bias[3] = {0, 0, 0}, mag_scale[3] = {0, 0, 0};
int16_t mag_max[3] = {-32767, -32767, -32767}, mag_min[3] = {32767, 32767,
32767}, mag_temp[3] = {0, 0, 0};
I also see a dest 1 AND dest 2 in mag_scale of the snippet but only dest 1
in the sketch (or at least in the same section; may be located elsewhere or
not needed?).
*Sketch*
void magcalLSM9DS1(float * dest1)
*vs. snippet*
void magcalMPU9250(float * dest1, *float * dest2*)
.
.
.
// Get soft iron correction estimate
mag_scale[0] = (mag_max[0] - mag_min[0])/2; // get average x axis max
chord length in counts
mag_scale[1] = (mag_max[1] - mag_min[1])/2; // get average y axis max
chord length in counts
mag_scale[2] = (mag_max[2] - mag_min[2])/2; // get average z axis max
chord length in counts
float avg_rad = mag_scale[0] + mag_scale[1] + mag_scale[2];
avg_rad /= 3.0;
dest2[0] = avg_rad/((float)mag_scale[0]);
dest2[1] = avg_rad/((float)mag_scale[1]);
dest2[2] = avg_rad/((float)mag_scale[2]);
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#14 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ABTDLKU3ORAUL7JGABONTKDTGUTZVANCNFSM4KWHMCKQ>
.
|
This might what these guys were wrestling with? https://forum.arduino.cc/index.php?topic=663160.msg4467543#msg4467543 |
No, this is not your problem yet.
Here are the steps to get accurate mag data for each axis:
1) read two register bytes
2) combine two register bytes into one int16_t signed integer
3) scale signed integer to get field value in Gauss or milliGauss
I suspect your code (or your Nano) is not doing one or more of these steps
correctly.
You can verify by checking the mag field you measure against what the USGS
says you should expect. Once you have done this, you can move on to proper
calibration.
…On Fri, Apr 2, 2021 at 11:41 AM willyconcarne12 ***@***.***> wrote:
This might what these guys were wrestling with?
https://forum.arduino.cc/index.php?topic=663160.msg4467543#msg4467543
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#14 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ABTDLKUEIEW6FR75IT36VUTTGYFWVANCNFSM4KWHMCKQ>
.
|
Thank you for that! Hate to ask another ignorant question, but is this the area of mag calibration adjustment once verifying? the 32768.0 denominator here void getMres() { and the correlating 32768 in the mag_max and mag_min scale here? uint8_t data[6]; // data array to hold mag x, y, z, data i.e. is 32768 "the number"? |
The sensor data is signed 16-bits, so max values will be +/- 2^15 = 32768.
Verify this for yourself.
…On Fri, Apr 2, 2021 at 12:01 PM willyconcarne12 ***@***.***> wrote:
Thank you for that! Hate to ask another ignorant question, but is this the
area of mag calibration adjustment once verifying?
*the 32768.0 denominator here*
void getMres() {
switch (Mscale)
{
// Possible magnetometer scales (and their register bit settings) are:
// 4 Gauss (00), 8 Gauss (01), 12 Gauss (10) and 16 Gauss (11)
case MFS_4G:
mRes = 4.0 / 32768.0;
break;
case MFS_8G:
mRes = 8.0 / 32768.0;
break;
case MFS_12G:
mRes = 12.0 / 32768.0;
break;
case MFS_16G:
mRes = 16.0 / 32768.0;
break;
and the correlating 32768 in the mag_max and mag_min scale here?
uint8_t data[6]; // data array to hold mag x, y, z, data
uint16_t ii = 0, sample_count = 0;
int32_t mag_bias[3] = {0, 0, 0};
int16_t mag_max[3] = {-32768, -32768, -32768}, mag_min[3] = {32768, 32768,
32768};
i.e. is 32768 "the number"?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#14 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ABTDLKQEEXAY7HW2XPWZ6YTTGYIBHANCNFSM4KWHMCKQ>
.
|
Found at this link kriswiner/LSM9DS1#14 (comment)
Hey Kris,
I am writing to You becouse I have big problem with my Arduino board and I can't resolve this from week.
I want to implement Madgwick filter and quaternions into my Arduino Nano 33 BLE board. After that i receive a lot of really crazy numbers without any sense.
I configured My board with ArduinoLSM9DS1 libary (https://www.arduino.cc/en/Reference/ArduinoLSM9DS1) it's really simply part of code in comparison into yours. For me is perfect beacouse I am beginner.
In my first use of this board I used data from sensors and I calculated Eulers angles to receive pitch,roll and yaw. I received preety good numbers.
Nextly I want to implement madgwick from here(https://x-io.co.uk/open-source-imu-and-ahrs-algorithms/)
Maybe You know with Your experience why I still cant use Madgwick on my board ? Maybe You done someting before on this board ?
The text was updated successfully, but these errors were encountered: