Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
imu_cleaner/src/imu_cleaning.py
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
executable file
22 lines (19 sloc)
628 Bytes
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
#!/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() |