Skip to content

Commit

Permalink
修改命名,README
Browse files Browse the repository at this point in the history
  • Loading branch information
berberman committed Aug 31, 2018
1 parent 31f4904 commit d0a6e7f
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 16 deletions.
43 changes: 42 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# 滤波器

[![Download](https://api.bintray.com/packages/mechdancer/maven/filters/images/download.svg) ](https://bintray.com/mechdancer/maven/filters/_latestVersion)
[![Build Status](https://www.travis-ci.org/MechDancer/filters.svg?branch=master)](https://www.travis-ci.org/MechDancer/filters)

## 概述
Expand Down Expand Up @@ -37,5 +38,45 @@
* 卡尔曼滤波器



## 开始使用

* Gradle
* Maven
* Bintray

您需要将其添加至 [仓库和依赖](https://docs.gradle.org/current/userguide/declaring_dependencies.html) 中。

### Gradle

```groovy
repositories {
jcenter()
}
dependencies {
compile 'org.mechdancer:filters:0.1.0'
}
```

### Maven

```xml
<repositories>
<repository>
<id>jcenter</id>
<name>JCenter</name>
<url>https://jcenter.bintray.com/</url>
</repository>
</repositories>

<dependency>
<groupId>org.mechdancer</groupId>
<artifactId>filters</artifactId>
<version>0.1.0</version>
<type>pom</type>
</dependency>
```

### Bintray

您总可以从 bintray 直接下载 jar:[![Download](https://api.bintray.com/packages/mechdancer/maven/filters/images/download.svg) ](https://bintray.com/mechdancer/maven/filters/_latestVersion)

Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package org.mechdancer.filters.signalAndSystem

class LowpassFilter(private val _forgetRate: Double) : IMemorableOnlineSystem {
class LowpassFilter(private val forgetRate: Double) : IMemorableOnlineSystem {
var memory = .0
private set

override fun invoke(data: Double): Double {
memory = memory * (1 - _forgetRate) + data * _forgetRate
memory = memory * (1 - forgetRate) + data * forgetRate
return memory
}

Expand Down
25 changes: 12 additions & 13 deletions src/main/kotlin/org/mechdancer/filters/signalAndSystem/PID.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,25 @@ package org.mechdancer.filters.signalAndSystem

import java.lang.Math.abs

class PID(private val _k: Double,
private val _ki: Double,
private val _kd: Double,
private val _integrateIArea: Double,
private val _deadArea: Double)
class PID(private val k: Double,
private val ki: Double,
private val kd: Double,
private val integrateIArea: Double,
private val deadArea: Double)
: IMemorableOnlineSystem {

/** 运行参数 */
private var sum = 0.0
private var last = 0.0

@Suppress("PARAMETER_NAME_CHANGED_ON_OVERRIDE")
override fun invoke(error: Double): Double {
val value = abs(error)
sum = if (value > _integrateIArea) .0 else sum + error
if (value < _deadArea) sum *= .75
override fun invoke(data: Double): Double {
val value = abs(data)
sum = if (value > integrateIArea) .0 else sum + data
if (value < deadArea) sum *= .75
//计算
val result = error + _kd * (error - last) + _ki * sum
last = error
return _k * result
val result = data + kd * (data - last) + ki * sum
last = data
return k * result
}

/** 重置运行间参数 */
Expand Down

0 comments on commit d0a6e7f

Please sign in to comment.