|
Post by rayman on Aug 21, 2014 11:01:07 GMT -8
unfortunately, i don't understand the get_accel function in GD2.ccp on teensy3.1 the values of return = nonsense i get a 10-digit int can someone help me ...
|
|
|
Post by rayman on Aug 21, 2014 12:21:42 GMT -8
void GDClass::get_accel(int &x, int &y, int &z) { static int f[3];
for (byte i = 0; i < 3; i++) { int a = analogRead(A0 + i); // Serial.print(a, DEC); Serial.print(" "); int s = (-160 * (a - 376)) >> 6; f[i] = ((3 * f[i]) >> 2) + (s >> 2); Serial.print("i=> "); Serial.println(i); Serial.print(" a=> "); Serial.println(a, DEC); Serial.print(" s=> "); Serial.println(s, DEC); Serial.println("---"); } // Serial.println(); x = f[2]; y = f[1]; z = f[0]; }
the result is not -256 ... 256 i=> 0
a=> 525
s=> -373
---
i=> 1
a=> 520
s=> -360
---
i=> 2
a=> 617
s=> -603
---
|
|
|
Post by rayman on Aug 21, 2014 13:03:49 GMT -8
unfortunately, i don't understand the get_accel function in GD2.ccp on teensy3.1 the values of return = nonsense i get a 10-digit int can someone help me ... forget the stupid question broken GD.cmd_number(285, 30, 26, 3, ax); correct GD.cmd_number(285, 30, 26, OPT_SIGNED, ax);
|
|
|
Post by rayman on Aug 21, 2014 13:09:29 GMT -8
the result is not -256 ... 256 i=> 0
a=> 525
s=> -373
---
i=> 1
a=> 520
s=> -360
---
i=> 2
a=> 617
s=> -603
---
but the values are not yet correctly
|
|
bubu
Junior Member
Posts: 17
|
Post by bubu on Aug 21, 2014 22:23:08 GMT -8
My answer will not help you much, but I experience weird behaviour of that function as well with my arduino uno r3. Powering the device with USB cable gives other results than powering by battery and both do not match the values given in the book. You might try calibrating in your code, like measure the max and min values and calculate the level of turning yourself.
|
|