Denmark
Offline
Full Member
Karma: 7
Posts: 246
|
 |
« Reply #90 on: July 30, 2011, 05:07:41 am » |
Try changing the calibration page to this: //This is pretty simple. It takes 100 readings and calculate the average.
//gyros long resultGyroX;//x-axis long resultGyroY;//y-axis long resultGyroZ;//z-axis
//accelerometers long resultAccX;//x-axis long resultAccY;//y-axis long resultAccZ;//z-axis
//gyros int calibrateGyroX() { for(int i=0;i<100;i++) { resultGyroX += analogRead(gX); delay(1); } resultGyroX = resultGyroX/100; return resultGyroX; }
int calibrateGyroY() { for(int i=0;i<100;i++) { resultGyroY += analogRead(gY); delay(1); } resultGyroY = resultGyroY/100; return resultGyroY; }
int calibrateGyroZ() { for(int i=0;i<100;i++) { resultGyroZ += analogRead(gZ); delay(1); } resultGyroZ = resultGyroZ/100; return resultGyroZ; }
//accelerometers int calibrateAccX() { for(int i=0;i<100;i++) { resultAccX += analogRead(aX); delay(1); } resultAccX = resultAccX/100; return resultAccX; } int calibrateAccY() { for(int i=0;i<100;i++) { resultAccY += analogRead(aY); delay(1); } resultAccY = resultAccY/100; return resultAccY; }
int calibrateAccZ() { for(int i=0;i<100;i++) { resultAccZ += analogRead(aZ); delay(1); } resultAccZ = resultAccZ/100; return resultAccZ; }
And double check your connections: Acc_Gyro Arduino 3.3V <—> 3.3V GND <—> GND Gx4 X <—> AN0 Gx4 Y <—> AN1 Gx4 Z <—> AN2 Acc X <—> AN3 Acc Y <—> AN4 Acc Z <—> AN5 Also connect 3.3V to the AREF pin on the Arduino for more accuracy.
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 7
|
 |
« Reply #91 on: July 30, 2011, 05:14:18 am » |
Changing the Calibration as you detailed is looking much more promising!
The data is starting to look reasonable, and it's not going away and never coming back anymore.
That's serious progress! Thanks!
Please check:
accXval = (accXadc-accZeroX)/102,3; accYval = (accYadc-accZeroY)/102,3; accZval = (accZadc-accZeroZ)/102,3;
I suspect you may have a problem there. For me, 102,3 is not the same as 102.3... We can check this by just writing a sketch that multiplies two decimal numbers together, once with a decimal point and once with a comma. The results are not the same for me. Are they for you?
|
|
|
|
|
Logged
|
|
|
|
|
Denmark
Offline
Full Member
Karma: 7
Posts: 246
|
 |
« Reply #92 on: July 30, 2011, 05:25:50 am » |
Glad I could help. I see your point. I am not home right now, but I will check it tonight 
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 7
|
 |
« Reply #93 on: July 30, 2011, 05:49:04 am » |
Once again, thanks! That change to Calibration did the trick. After changing 102,3 to 102.3, I'm getting results from just compAngle plenty repeatable enough for my use. (Part of a nearspace-craft sensor array) All we're really doing is syncing the rotation and vibration readouts to the video cameras from the balloon and rocket. The ground control UI is taking data down from the craft over a radio telemetry link. Now I just need to integrate it.  compAngleX, compAngleY, AccX,Y,Z values are all I need. Thanks!
|
|
|
|
|
Logged
|
|
|
|
|
Denmark
Offline
Full Member
Karma: 7
Posts: 246
|
 |
« Reply #94 on: July 31, 2011, 08:48:36 am » |
I have updated the code, so it is now ver3. Please try it out, and say if it works  The accelerometer can not measure the rotation (yaw), look at some of the previous post for help. The accelerometer can only measure pitch and roll:  You need a magnetometer to measure yaw. Here is a link for one at Sparkfun: http://www.sparkfun.com/products/9371. Why do you want to use the complimentary filter? The kalman, is more precise  Anyway the project sound really cool, please post a video when your are done 
|
|
|
|
|
Logged
|
|
|
|
|
Rio de Janeiro
Offline
Newbie
Karma: 0
Posts: 34
|
 |
« Reply #95 on: August 09, 2011, 02:32:58 am » |
Lauszus, I made use of your already functional Kalman Filter algorithm in my project: A self stabilizing platform. You code worked great and you saved me a lot of time  Thank you Here are the results: I also posted the project in the Exhibition forum, in this post.
|
|
|
|
|
Logged
|
|
|
|
|
Denmark
Offline
Full Member
Karma: 7
Posts: 246
|
 |
« Reply #96 on: August 09, 2011, 03:14:25 am » |
#Rivello Awesome job, glad I could help  - Lauszus
|
|
|
|
|
Logged
|
|
|
|
|
Zaragoza
Offline
Newbie
Karma: 0
Posts: 7
|
 |
« Reply #97 on: August 10, 2011, 08:55:01 am » |
Hi!! I was hoping you could help me as I'm getting nuts with this IMU  I've tested the IMU just as in your post, same pin connections and the original code (version 2 & 3) but I'm getting some weird data. Or at least that's what it looks to me! The xAngle and yAngle printed at the end of the processing function doesn't go further than 40 degrees. I've tested it by rotating over one of the axes until I reach 90º. I've checked the voltage output directly from the accelerometers to see if something is wrong but the readings I believe make sense. At calibration voltage for accelerometer is around 1.57v. At 90º it is around 1.9v. If I have understood correctly sensitivity is 330mV/g, so just rotating it by 90º should vary +- 0.33v; exactly as I can read. The gyros look "good". Obviously it is hard for me to make a precise reading of it, but when stable it shows around 1.22v which vary while being rotated. If done quite fast I can see values under 1v and around 2v. I would really appreciate any help as I'm really lost on why I can only measure angles up to 40º. I've seen other replies commenting the same but no root cause. I'm quite sure I'm doing something wrong but I can't trace it  Thanks for the help! Guillermo
|
|
|
|
|
Logged
|
|
|
|
|
Denmark
Offline
Full Member
Karma: 7
Posts: 246
|
 |
« Reply #98 on: August 10, 2011, 09:00:42 am » |
#Elwylly Have you remembered to connect 3.3V to the VREF pin? 
|
|
|
|
|
Logged
|
|
|
|
|
Zaragoza
Offline
Newbie
Karma: 0
Posts: 7
|
 |
« Reply #99 on: August 10, 2011, 09:28:59 am » |
Hi Lauszus, Yes, I've connected AREF to 3.3v. Also the rest of the pins are connected as you described to make sure I was not messing up with the values  I'm wondering whether the gyros are working correctly. I think the acc is working as expected due to the voltage readings, but I'm trying to figure out the self-test option the gyros have. To be honest, that's the only explanation I seem to find.  Cheers,
|
|
|
|
|
Logged
|
|
|
|
|
Denmark
Offline
Full Member
Karma: 7
Posts: 246
|
 |
« Reply #100 on: August 10, 2011, 09:34:32 am » |
#Elwylly Are you sure that you have connected the it to the right way: Gx4 X <—> AN0 Gx4 Y <—> AN1 Gx4 Z <—> AN2 Acc X <—> AN3 Acc Y <—> AN4 Acc Z <—> AN5 ?  It is pretty hard for me, to help when I do not know more  It should not be necessary to use the self-test. - Lauszus
|
|
|
|
|
Logged
|
|
|
|
|
Zaragoza
Offline
Newbie
Karma: 0
Posts: 7
|
 |
« Reply #101 on: August 10, 2011, 12:13:48 pm » |
Yep. Everything connected as you mentioned. I've checked hundreds of times as it is a stupid mistake that I would love to avoid  I've been checking just the accelerometer value, accYangle, and it is not even close to be correct. It is showing a value of 30º when rotated 90º. At 90º, considering that Gx4 sensitivity is 0.33v/g, the voltage reading is 1.9v (1.57v when flat). That seems to be correct as if I have understood correctly accelerometer in that position should be reflecting gravitational force only for that axis. I think the problem may be there. I'll try to see what's going on when calculating the accelerometer values as they seem to be the source of error. Maybe as somebody mention is a environment config problem that is messing with calculations. Cheers,
|
|
|
|
|
Logged
|
|
|
|
|
Zaragoza
Offline
Newbie
Karma: 0
Posts: 7
|
 |
« Reply #102 on: August 10, 2011, 12:58:08 pm » |
Hi Lauszus,
I think I found what's disturbing my readings. The problem seems to be the Z axis. I've got the IMU with the ICs facing down, and I think the problem is there. I need to calculate correctly the Z axis...
Cheers,
|
|
|
|
|
Logged
|
|
|
|
|
Denmark
Offline
Full Member
Karma: 7
Posts: 246
|
 |
« Reply #103 on: August 10, 2011, 03:12:41 pm » |
Okay, it is simple then. In line 97, is says: accZval++;//1g in horizontal position That should just be changed to: accZval--;//-1g when facing down
|
|
|
|
|
Logged
|
|
|
|
|
Zaragoza
Offline
Newbie
Karma: 0
Posts: 7
|
 |
« Reply #104 on: August 11, 2011, 01:34:31 pm » |
I had to adjust the 360 degrees part as well but finally it is working as expected  Thanks for your post Lauszus, it was really helpful.
|
|
|
|
|
Logged
|
|
|
|
|
|