初始化提交

This commit is contained in:
王立帮
2024-07-20 22:09:06 +08:00
commit c247dd07a6
6876 changed files with 2743096 additions and 0 deletions

View File

@@ -0,0 +1,21 @@
MIT License
Copyright (c) 2017 Denys Sene
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

View File

@@ -0,0 +1,65 @@
Simple Kalman Filter Library - [![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg?style=plastic)](https://raw.githubusercontent.com/denyssene/SimpleKalmanFilter/master/LICENSE) [![GitHub stars](https://img.shields.io/github/stars/denyssene/SimpleKalmanFilter.svg?style=plastic)](https://github.com/denyssene/SimpleKalmanFilter/stargazers) [![GitHub issues](https://img.shields.io/github/issues/denyssene/SimpleKalmanFilter.svg?style=plastic)](https://github.com/denyssene/SimpleKalmanFilter/issues)
========================================
![KalmanFilter](images/kalman_filter_example_1.png)
This is a basic kalman filter library for unidimensional models that you can use with a stream of single values like barometric sensors, temperature sensors or even gyroscope and accelerometers.
* Take a look at this [youtube video](https://www.youtube.com/watch?v=4Q5kJ96YYZ4) to see the Kalman Filter working on a stream of values!
*Special thanks to Professor Michel van Biezen and his amazing work in http://www.ilectureonline.com/*
Repository Contents
-------------------
* **/examples** - Example sketches for the library (.ino). Run these from the Arduino IDE.
* **/src** - Source files for the library (.cpp, .h).
* **keywords.txt** - Keywords from this library that will be highlighted in the Arduino IDE.
* **library.properties** - General library properties for the Arduino package manager.
Basic Usage
-------------------
* **e_mea: Measurement Uncertainty** - How much do we expect to our measurement vary
* **e_est: Estimation Uncertainty** - Can be initilized with the same value as e_mea since the kalman filter will adjust its value.
* **q: Process Variance** - usually a small number between 0.001 and 1 - how fast your measurement moves. Recommended 0.01. Should be tunned to your needs.
```c++
SimpleKalmanFilter kf = SimpleKalmanFilter(e_mea, e_est, q);
while (1) {
float x = analogRead(A0);
float estimated_x = kf.updateEstimate(x);
// ...
}
```
Example Briefs
--------------
* **BasicKalmanFilterExample** - A basic example reading a value from a potentiometer in A0 and SimpleKalmanFilter class to generate estimates.
* **AltitudeKalmanFilterExample** - Uses a BMP180 barometric sensor and the SimpleKalmanFilter class to estimate the correct altitude.
Additional Documentation
-------------------------
* **[Installing Additional Arduino Libraries](https://www.arduino.cc/en/Guide/Libraries)** - Basic information on how to install an Arduino library.
Version History
---------------
* [V 0.1.0](https://github.com/denyssene/SimpleKalmanFilter) -- Initial commit
License Information
-------------------
This is an _**open source**_ project!
Please review the LICENSE.md file for license information.
If you have any questions or concerns on licensing, please contact denys.sene@gmail.com.

View File

@@ -0,0 +1,72 @@
#include <SimpleKalmanFilter.h>
#include <SFE_BMP180.h>
/*
This sample code demonstrates how the SimpleKalmanFilter object can be used with a
pressure sensor to smooth a set of altitude measurements.
This example needs a BMP180 barometric sensor as a data source.
https://www.sparkfun.com/products/11824
SimpleKalmanFilter(e_mea, e_est, q);
e_mea: Measurement Uncertainty
e_est: Estimation Uncertainty
q: Process Noise
*/
SimpleKalmanFilter pressureKalmanFilter(1, 1, 0.01);
SFE_BMP180 pressure;
// Serial output refresh time
const long SERIAL_REFRESH_TIME = 100;
long refresh_time;
float baseline; // baseline pressure
double getPressure() {
char status;
double T,P;
status = pressure.startTemperature();
if (status != 0) {
delay(status);
status = pressure.getTemperature(T);
if (status != 0) {
status = pressure.startPressure(3);
if (status != 0) {
delay(status);
status = pressure.getPressure(P,T);
if (status != 0) {
return(P);
}
}
}
}
}
void setup() {
Serial.begin(115200);
// BMP180 Pressure sensor start
if (!pressure.begin()) {
Serial.println("BMP180 Pressure Sensor Error!");
while(1); // Pause forever.
}
baseline = getPressure();
}
void loop() {
float p = getPressure();
float altitude = pressure.altitude(p,baseline);
float estimated_altitude = pressureKalmanFilter.updateEstimate(altitude);
if (millis() > refresh_time) {
Serial.print(altitude,6);
Serial.print(",");
Serial.print(estimated_altitude,6);
Serial.println();
refresh_time=millis()+SERIAL_REFRESH_TIME;
}
}

View File

@@ -0,0 +1,49 @@
#include <SimpleKalmanFilter.h>
/*
This sample code demonstrates how to use the SimpleKalmanFilter object.
Use a potentiometer in Analog input A0 as a source for the reference real value.
Some random noise will be generated over this value and used as a measured value.
The estimated value obtained from SimpleKalmanFilter should match the real
reference value.
SimpleKalmanFilter(e_mea, e_est, q);
e_mea: Measurement Uncertainty
e_est: Estimation Uncertainty
q: Process Noise
*/
SimpleKalmanFilter simpleKalmanFilter(2, 2, 0.01);
// Serial output refresh time
const long SERIAL_REFRESH_TIME = 100;
long refresh_time;
void setup() {
Serial.begin(115200);
}
void loop() {
// read a reference value from A0 and map it from 0 to 100
float real_value = analogRead(A0)/1024.0 * 100.0;
// add a noise to the reference value and use as the measured value
float measured_value = real_value + random(-100,100)/100.0;
// calculate the estimated value with Kalman Filter
float estimated_value = simpleKalmanFilter.updateEstimate(measured_value);
// send to Serial output every 100ms
// use the Serial Ploter for a good visualization
if (millis() > refresh_time) {
Serial.print(real_value,4);
Serial.print(",");
Serial.print(measured_value,4);
Serial.print(",");
Serial.print(estimated_value,4);
Serial.println();
refresh_time = millis() + SERIAL_REFRESH_TIME;
}
}

View File

@@ -0,0 +1,26 @@
#############################################
# Syntax Coloring Map for SimpleKalmanFilter
#############################################
#######################################
# Datatypes (KEYWORD1)
#######################################
SimpleKalmanFilter KEYWORD1
#######################################
# Methods and Functions (KEYWORD2)
#######################################
updateEstimate KEYWORD2
setMeasurementError KEYWORD2
setEstimateError KEYWORD2
setProcessNoise KEYWORD2
getKalmanGain KEYWORD2
#######################################
# Constants (LITERAL1)
#######################################

View File

@@ -0,0 +1,18 @@
{
"name": "SimpleKalmanFilter",
"keywords": "kalman, filter, linear, quadratic, estimation, LQE",
"description": "A basic implementation of Kalman Filter for single variable models.",
"repository": {
"type": "git",
"url": "https://github.com/denyssene/SimpleKalmanFilter.git"
},
"version": "0.1.0",
"authors": {
"name": "Denys Sene",
"url": ""
},
"exclude": [
],
"frameworks": "arduino",
"platforms": "*"
}

View File

@@ -0,0 +1,9 @@
name=SimpleKalmanFilter
version=0.1
author=Denys Sene
maintainer=Denys Sene
sentence=A simple implementation of Kalman Filter.
paragraph=This is a basic kalman filter library for unidimensional models that you can use with a stream of single values like barometric sensors, temperature sensors or even gyroscope and accelerometers.
category=Data Processing
url=https://github.com/denyssene/SimpleKalmanFilter
architectures=*

View File

@@ -0,0 +1,49 @@
/*
* SimpleKalmanFilter - a Kalman Filter implementation for single variable models.
* Created by Denys Sene, January, 1, 2017.
* Released under MIT License - see LICENSE file for details.
*/
#include "Arduino.h"
#include "SimpleKalmanFilter.h"
#include <math.h>
SimpleKalmanFilter::SimpleKalmanFilter(float mea_e, float est_e, float q)
{
_err_measure=mea_e;
_err_estimate=est_e;
_q = q;
}
float SimpleKalmanFilter::updateEstimate(float mea)
{
_kalman_gain = _err_estimate/(_err_estimate + _err_measure);
_current_estimate = _last_estimate + _kalman_gain * (mea - _last_estimate);
_err_estimate = (1.0 - _kalman_gain)*_err_estimate + fabs(_last_estimate-_current_estimate)*_q;
_last_estimate=_current_estimate;
return _current_estimate;
}
void SimpleKalmanFilter::setMeasurementError(float mea_e)
{
_err_measure=mea_e;
}
void SimpleKalmanFilter::setEstimateError(float est_e)
{
_err_estimate=est_e;
}
void SimpleKalmanFilter::setProcessNoise(float q)
{
_q=q;
}
float SimpleKalmanFilter::getKalmanGain() {
return _kalman_gain;
}
float SimpleKalmanFilter::getEstimateError() {
return _err_estimate;
}

View File

@@ -0,0 +1,32 @@
/*
* SimpleKalmanFilter - a Kalman Filter implementation for single variable models.
* Created by Denys Sene, January, 1, 2017.
* Released under MIT License - see LICENSE file for details.
*/
#ifndef SimpleKalmanFilter_h
#define SimpleKalmanFilter_h
class SimpleKalmanFilter
{
public:
SimpleKalmanFilter(float mea_e, float est_e, float q);
float updateEstimate(float mea);
void setMeasurementError(float mea_e);
void setEstimateError(float est_e);
void setProcessNoise(float q);
float getKalmanGain();
float getEstimateError();
private:
float _err_measure;
float _err_estimate;
float _q;
float _current_estimate;
float _last_estimate;
float _kalman_gain;
};
#endif