Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Kalman.h> // Include Kalman Filter Library
- Kalman kalmanX; // Create Kalman filter for X-axis
- Kalman kalmanY; // Create Kalman filter for Y-axis
- float angleX, angleY; // Filtered angle output
- void setup() {
- Serial.begin(115200);
- kalmanX.setAngle(0); // Initialize the filter angle
- kalmanY.setAngle(0);
- }
- void loop() {
- float accelX, accelY, gyroX, gyroY; // Simulated sensor readings
- // Replace these with actual sensor readings
- accelX = getAccelX();
- accelY = getAccelY();
- gyroX = getGyroX();
- gyroY = getGyroY();
- // Apply Kalman filter
- angleX = kalmanX.getAngle(accelX, gyroX, 0.01);
- angleY = kalmanY.getAngle(accelY, gyroY, 0.01);
- Serial.print("Angle X: "); Serial.print(angleX); Serial.print("\t");
- Serial.print("Angle Y: "); Serial.println(angleY);
- delay(10);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement