Novice: Data to use for EKF with sensor #27
Replies: 1 comment 1 reply
-
Hi Rhys, I'm glad the package is useful for your projects. First, just to be clear, if you give the sensor data at the construction of the EKF object, it will try to estimate all orientations automatically and store it in the attribute If you want to avoid this, then build the object without giving any sensor data: ekf = EKF() In this case the object is created, but no estimations are done yet, and the attribute Regarding the All implementations of the EKF require an initial state, in this case an initial orientation represented as a quaternion, so that the following estimations can be built on top of it:
You can do this by setting this initial orientation at the construction of the object: ekf = EKF(q0=[1.0, 0.0, 0.0, 0.0]) In this example I set it to the identity quaternion ([1, 0, 0, 0]), but you can set it to any unit quaternion (a quaternion with norm equal to 1) representing the initial orientation. A second detail to point out is that some sensors (especially low cost not used in aeronautics) tend to use a different reference frame called ENU (East-North-Up). It might be that yours could be using it too. You can also set this different frame at the construction of the object: ekf = EKF(q0=[1.0, 0.0, 0.0, 0.0], frame='ENU') Otherwise, it will be set to the default 'NED' (North-East-Down) used often in aeronautics. For the case of the An alternative to that problem would be using the function q = ahrs.common.orientation.acc2q(acc_data)
ekf = EKF(q0=q) Also, don't forget to set the sampling frequency. The default value is equal to 100 Hz, but if you are giving sensor signals at a different rate, you must set it in the constructor. For example, for 200 Hz: ekf = EKF(frequency=200.0) In summary, for your real-time application, a convenient solution could be: ekf = EKF()
acc_data = imu.read_accelerometer_gyro_data()[:3]
q = ahrs.common.orientation.acc2q(acc_data)
print(q) # Print Initial Orientation
while True:
imu_data = imu.read_accelerometer_gyro_data()
acc_data = imu_data[:3]
gyr_data = imu_data[3:]
q = ekf.update(q, gyr_data, acc_data)
print(q) # Print newest Orientation Notice the index If you want to use the magnetometer samples, then I would suggest to substitute the ekf = EKF()
acc_data = imu.read_accelerometer_gyro_data()[:3]
mag_data = imu.read_magnetometer_data()
q = ahrs.common.orientation.ecompass(acc_data, mag_data, frame='ENU', representation='quaternion')
print(q) # Print Initial Orientation
while True:
imu_data = imu.read_accelerometer_gyro_data()
acc_data = imu_data[:3]
gyr_data = imu_data[3:]
mag_data = imu.read_magnetometer_data()
q = ekf.update(q, gyr_data, acc_data, mag_data)
print(q) # Print newest Orientation Give it a try and let me know if it works. |
Beta Was this translation helpful? Give feedback.
-
Hello,
I'd like to start by saying this repo is incredible, there are so many types and styles of orientation estimation, it must've been a massive project to undertake. Amazing.
I am going to use it to build a robot car as a personal learning project and an attempt to push my skills up a level.
So the question;
I am trying to use your EKF module to get some orientation information, I am using the sensor ICM20948 which has an accelerometer, gyro and magnetometer.
To start the script, imports and sensor initialise;
The information I get from the ICM20948 is 9 individual float type variables, in my code it looks like;
which I then convert into numpy arrays for the module;
then I create the ekf object
and after this I have the mainloop, the Q part confuses me because it seem like there should already be the quaternion information before it makes the estimation.
Basically I'm trying to integrate the ICM20948 with your EKF filter module, I am quite novice and in-experienced, so please forgive any very obvious mistakes.
Also on a completely separate topic, when I try to import the
Tilt
package it doesnt seem to be able to find it. whereas theEKF
package imports just fine.Python3.7.3
thanks,
Rhys.
Beta Was this translation helpful? Give feedback.
All reactions