Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Added gravity calculation functionality.
- Average of first 50 records seen is used to calculate gravity.
- Loading branch information
Showing
3 changed files
with
26 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#!/usr/bin/env python | ||
import rospy | ||
from geometry_msgs.msg import Quaternion, Vector3 | ||
from sensor_msgs.msg import Imu | ||
|
||
import math | ||
|
||
def main(): | ||
# Collect first 50 entries and average them. | ||
rospy.init_node("imu_cleaner") | ||
totals =[0,0,0] | ||
for i in range(50): | ||
cval = rospy.client.wait_for_message('imu',Imu) | ||
totals[0]+=cval.linear_acceleration.x | ||
totals[1]+=cval.linear_acceleration.y | ||
totals[2]+=cval.linear_acceleration.z | ||
averages = map(lambda x: x/50,totals) | ||
print(averages) | ||
print("Magnitude is:", math.sqrt(math.pow(averages[0],2)+math.pow(averages[1],2)+math.pow(averages[2],2))) | ||
|
||
if __name__=='__main__': | ||
main() |