Created
December 24, 2020 15:34
-
-
Save raysuhyunlee/fbcc9eb99e97175d0e8aa05f6dd28adf to your computer and use it in GitHub Desktop.
칼만필터 스터디
This file contains hidden or 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
| import random | |
| import time | |
| temp = 50 | |
| x = 30 | |
| pe = 2 | |
| re = 2 | |
| k = 0 | |
| def get_sensor(actual_temp): | |
| rand = random.random() | |
| if (rand < 0.5): | |
| sensor_temp = actual_temp | |
| elif (rand < 0.7): | |
| sensor_temp = actual_temp + 1 | |
| elif (rand < 0.9): | |
| sensor_temp = actual_temp - 1 | |
| elif (rand < 0.95): | |
| sensor_temp = actual_temp + 2 | |
| else: | |
| sensor_temp = actual_temp - 2 | |
| return sensor_temp | |
| while(True): | |
| sensor_temp = get_sensor(temp) | |
| k = pe / (pe + re) | |
| x = x + k * (sensor_temp - x) | |
| pe = (1 - k) * pe | |
| print ("센서값: {}, 추정값: {}".format(sensor_temp, x)) | |
| time.sleep(0.05) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment