Hello,
I am using a Parallax accelerometer module and would like to keep the outputted values between 0 and 180 deg such that when rotated upside down it reads something like: ...177, 178, 179, 0, 1, 2, 3,... I was able to get this to work for the gyroscope module using the fmod(gyro,PI) function, but no such luck with the accelerometer.
Currently, the accelerometer is outputting ...177, 178, 179,-179,-178,-177...
Could someone kindly show me a routine to output the values I want?
Many thanks,
David
Comments
An accelerometer does not output values in degrees.
I'm curious, why do you call yourself "amalfiCoast" and "David" at the same time?
comparing your numbers you showed as example you could substract the number you got from 179 if negative.
but like @Heater. said, why you want to do that?
An accelerometer measures the change of movement, not some fixed position. holding it still at any degree should read zero.
Enjoy!
Mike
A determined coder can write COBOL programs in any language. -- Author unknown.
Press any key to continue, any other key to quit
The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", "SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in this post are to be interpreted as described in RFC 2119.
Think of how an aircraft's attitude and heading reference system display is always been 0 and 180 deg. When I fuse the accelAngle and gyroAngle together using a complementary filter I need both angles to be "on the same page" so to speak. When the sensors are inverted for example, gyroAngleMod goes like 178, 179, 0, 1, 2, etc. while the accelAngle does 178, 179, -179, -178, which is not what I want. I hope this helps explain what I mean.
Heater,
My name is David but I chose amalfiCoast as my profile name because it's one of the most beautiful places I have ever visited.
Thanks,
David
Life is unpredictable. Eat dessert first.
I'm still confused. Could you explain more what you mean by multiplying the accelerometer value by a factor that results in a value between -180 and +180?
Thank you.
David
Life is unpredictable. Eat dessert first.
atan2 is the standard function for converting cartesian to polar coords in 2 dimensions.
https://en.wikipedia.org/wiki/Spherical_coordinate_system
https://en.wikipedia.org/wiki/Vector_fields_in_cylindrical_and_spherical_coordinates
for a more in depth explanation.
Life is unpredictable. Eat dessert first.