I am quite new to arduino programming and I really need your help.
I am using a Genuino 101 and Max Msp.
I managed to receive the gyroscope data into max msp, I get angles and all works good.
I used a code found on the forum... the MUvisualiser...
My problem is that after a wile I get drift. I guess it's normal but..
I would like, through max, to re-trig the gyroscope calibration process without having to reset the arduino.
I implemented in the code few lines that will re-trig the calibration process once it receives the number 1 from the serial port.
It actually works, but just for one second, then it goes back to the previous values.
Reading the forum it looks like I have to clear the buffer, but I have no idea how to do that.
I downloaded the MPU6050 and the i2cdev libraries but I didn't get how to use it.
I'll post the code I am using..please help me and sorry for my bad knowledge.
S_v_L:
Why don't you combine the values from the accelerometer and the gyroscope to correct the drifting from the gyro?
In the common case where the board is level with gravity, the accelerometer can only be used to correct for X and Y axis gyroscope drift. Libraries like MadgwickAHRS do this for you. But Z axis gyroscope drift generally can't be corrected by an accelerometer. You generally need a magnetometer for that, and indeed many motion sensors (but not the one in Curie) have magnetometers for exactly this reason.
I've recently been working on improvements to MadgwickAHRS. Here's the latest example for use with Arduino101.
Unfortunately, CurieIMU does not yet provide functions for reading each unique sample, so this contains some ugly timing code to pace itself to the gyroscope rate. I hope to greatly improve this as CurieIMU develops....
Perhaps you could use the "data ready" interrupt from the imu and a suitable output data rate? If I understand what you are trying to do with the "ugly timing"?
I had a slightly different implementation of the imu visualizer working, but on the old api and just the main number crunching part of the madgwick copied into the sketch rather than the madgwick filter library.
I was using raw quaternions and creating a "teapot packet" to suit one of the original arduino IMU visualizer processing sketches.
I agree with your comments 100%. The following is a little off topic but I am providing it for information.
Unfortunately Intel decided to create a wrapper to the BMI160 library which allows you much more flexibility. I got around it by accessing the BMI160 library directly using the following construct CurieIMU.BMI160Class::Whatever-function-you-want from the BMI160 Lib. Its a pain but it works.
There are also a couple of other things that I recommended to be changed in the MadgwickAHRS which I don't think you identified yet; (1) expose the quaternions so a user can access them for whatever they want, (2) allow the user to change the filter factor (betadef) and (3) use the correct sampling frequency for the filter since currently its fixed at 512Hz. I have a couple of pull requests out to do this. Included is a YPR processing sketch. I also included the Mahony filter as well. Couldn't resist. You may recognize it from Fabio's FreeIMU library.
By the way I included it in my updated version of his library (FreeIMU-updates) on GitHub and it works quite well - works even better with a magnetometer when the I2C bus is working.
Respectfully
Mike
(aka mjs513 on GitHub, CyberMerln on YouTube)
To go along with DavidOR's comments you might also be able to use the BMI160's FIFO to sync gyro and accel readings. There also a sketch out there that uses a runonce function as a scheduler.
Sorry guys I am at a very basic level.
What I would like to do is to re-start the calibration process through code while I am using the arduino.
Being in a different position than the start position, I want to tell the arduino to consider the new position as start point. In this way I can receive from the arduino the start values through the serial port, as if it was just reset.
I would like to implement a toggle or button in max msp that will tell the arduino to consider its current position as the start position. I think the name for all this is calibration.
Is it possible to do that ?
reset the unit takes time and it's not always easy to get access to the reset button.
Thanks
/Users/Roberto/Documents/Arduino/libraries/MadgwickAHRS-master/examples/Visualize101/Visualize101.ino:1:22: fatal error: CurieIMU.h: No such file or directory #include <CurieIMU.h>
^
compilation terminated.
exit status 1
Error compiling.
Just a shot here but did you update to the new Arduino101 core (1.0.5). In 1.0.5 they changed the name of the library to CurieIMU from CurieImu. I just tried compiling it on a windows 10 machine and IDE 1.6.7 and it worked fine.
I just tried your sketch and the YPR values are out of sync. By this I mean, it appear Yaw reads 180 when it should be reading 180, pitch is reversed, ie., + should be nose up but I am seeing - or nose down, roll is probably reversed as well.
From what I understand and other runs with CurieIMU x points to BLE symbol, z is up and y points to the left as you hold the usb connector towards you.
Not sure if axes where redefined somewhere else or not.
Looking the CurieIMU.cpp file it looks like it enables the offsets automatically once you issue these commands.
That's calibration. If you want to do a reset of the IMU you can just try and issue the CurieIMU.begin() command again and that should reset it. There is also a register command you can use #define BMI160_CMD_SOFT_RESET 0xB6 but you would need to read the spec and issue the from your sketch by writing to that register.
Not sure why you getting the fatal error: avr/io.h: No such file or directory if you have the Arduino101 board selected.
What exactly are you trying to do Reset the board or the IMU. What is your project trying to accomplish?
The code for the inialization(CurieIMU.begin and the Gyro/Acc cal) only will reset or recalibrate the IMU. In the later case the Madgwick algorithm will always converge to the current orientation. By the way if you do a recalibrate when the board is not level you will induce errors in the calculation.
Even if you reset the board the IMU readings will go the present orientation of the board.
What I am trying to do is to control daw panning through arduino.
I am using Max Msp to build a plugin.
I have to say my arduino does not drift drastically. It just drifts a bit in time due to quick movements or shakes.
I have implemented calibration through code within Max msp but it is just a simple calculation, It is not a real board calibration.
I don't want to reset the board with the reset button.
I would like to trigger the calibration process again, trough code, while the board is working.
I want to tell the board: consider "this" as your new start position.
After calibration I would aspect the board to send, through the serial port, the 0 degree angle for jaw roll and pitch for the new position where it is as soon as I trig the new calibration process.
I need to calibrate the board because if I just calibrate the readings from the serial port in Max, the board will still think to be in another position than the one it actually is, this resulting in strange behaviours if big drifts are in place.
It would be easy to just reset the board in the new position but I don't want to do that, at least not through the reset button.
Hi Roblars, here is my interpretation of what I think you want :
After some movement, errors gradually accumulate until the position your output describes does not match the actual physical location at all.
You want to "re-synchronize" the interpreted location and the actual location - either at specific intervals or specific known physical locations.
I'm no expert on the IMU stuff but here's my 2cents:
If the board regularly returns to a given "park" location then you can re-sync your position calculations - using a switch or certain period of inactivity to signal the "park" position.
If the board does not regularly return to the same position, but makes regular pauses during its motion, then a magnetometer will probably help. Haven't used one, most look a little slow so I don't know if they are helpful during constant movement.
In either case I understand it as "resetting the calculated position" rather than resetting or recalibrating the IMU itself.
I guess there are other different tactics you can use depending on the application.
A couple of points on IMU and the various filters - you will always have some drifting in yaw, a magnetometer will reduce that drift significantly as Paul said in an earlier post. Pitch and Roll tend to be very stable.
Now to your issue, so from what I think you said is that after you perform a move and then stop movement you want to reset yaw, pitch and roll in the current position is essentially zero before your next move and keep repeating this cycle. If that is the case you are really just looking at deltas in yaw, pitch and roll between the old and new position. Then you can just keep track of how much you moved during the current movement.
If this is the case you don't need to try and reset the IMU or board. Like I said before this won't really accomplish what you want.
As DavidOR stated there are couple of other things you can do to reduce yaw drifting.