Advertisement
lukifrancuz

Projekt Arduino

Jan 3rd, 2022
202
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <SimpleKalmanFilter.h>
  2.  
  3. double e_mea = 10;
  4. double e_est = 10;
  5. double q = 0.01;
  6.  
  7. SimpleKalmanFilter skf = SimpleKalmanFilter(e_mea, e_est, q);
  8.  
  9. double ultraSonicDistance(int trigPin, int echoPin) {
  10.   digitalWrite(trigPin, LOW);
  11.   delayMicroseconds(2);
  12.   digitalWrite(trigPin, HIGH);
  13.   delayMicroseconds(10);
  14.   digitalWrite(trigPin, LOW);
  15.   long microseconds = pulseIn(echoPin, HIGH);
  16.   return (double)(microseconds/58);
  17. }
  18.  
  19. void setup() {
  20.   pinMode(12, OUTPUT);
  21.   pinMode(13, INPUT);
  22. }
  23.  
  24. void loop() {
  25.   double distance = ultraSonicDistance(12, 13);
  26.   double distanceSKF = skf.updateEstimate(distance);
  27.  
  28.   Serial.print(distance);
  29.   Serial.print(" ");
  30.   Serial.print(distanceSKF);
  31.   Serial.println(" ");
  32.  
  33.   delay(100);
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement