mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-11-01 05:51:36 +08:00
Auto Formatting with clang-format-6.0 (#727)
* Add clang-format * Auto-format AlphaFilter and RingBuffer * Update to tab=8spaces * Allow for 120 width
This commit is contained in:
+8
-16
@@ -38,34 +38,26 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
template<typename T>
|
||||
class AlphaFilter final
|
||||
{
|
||||
template <typename T>
|
||||
class AlphaFilter final {
|
||||
public:
|
||||
AlphaFilter() = default;
|
||||
~AlphaFilter() = default;
|
||||
|
||||
void reset(const T &val) { _x = val; }
|
||||
|
||||
void update(const T &input, float tau, float dt)
|
||||
{
|
||||
const float alpha = dt / tau;
|
||||
void update(const T &input, float tau, float dt) {
|
||||
const float alpha = dt / tau;
|
||||
update(input, alpha);
|
||||
}
|
||||
|
||||
void update(const T &input, float alpha)
|
||||
{
|
||||
_x = (1.f - alpha) * _x + alpha * input;
|
||||
}
|
||||
void update(const T &input, float alpha) { _x = (1.f - alpha) * _x + alpha * input; }
|
||||
|
||||
// Typical 0.9/0.1 lowpass filter
|
||||
void update(const T &input)
|
||||
{
|
||||
update(input, 0.1f);
|
||||
}
|
||||
void update(const T &input) { update(input, 0.1f); }
|
||||
|
||||
const T& getState() const { return _x; }
|
||||
const T &getState() const { return _x; }
|
||||
|
||||
private:
|
||||
T _x{}; ///< current state of the filter
|
||||
T _x{}; ///< current state of the filter
|
||||
};
|
||||
|
||||
+13
-17
@@ -42,11 +42,9 @@
|
||||
#include <cstring>
|
||||
|
||||
template <typename data_type>
|
||||
class RingBuffer
|
||||
{
|
||||
class RingBuffer {
|
||||
public:
|
||||
RingBuffer()
|
||||
{
|
||||
RingBuffer() {
|
||||
if (allocate(1)) {
|
||||
// initialize with one empty sample
|
||||
data_type d = {};
|
||||
@@ -61,8 +59,7 @@ public:
|
||||
RingBuffer(RingBuffer &&) = delete;
|
||||
RingBuffer &operator=(RingBuffer &&) = delete;
|
||||
|
||||
bool allocate(uint8_t size)
|
||||
{
|
||||
bool allocate(uint8_t size) {
|
||||
if (_buffer != nullptr) {
|
||||
delete[] _buffer;
|
||||
}
|
||||
@@ -78,7 +75,8 @@ public:
|
||||
_head = 0;
|
||||
_tail = 0;
|
||||
|
||||
// set the time elements to zero so that bad data is not retrieved from the buffers
|
||||
// set the time elements to zero so that bad data is not
|
||||
// retrieved from the buffers
|
||||
for (uint8_t index = 0; index < _size; index++) {
|
||||
_buffer[index] = {};
|
||||
}
|
||||
@@ -88,14 +86,12 @@ public:
|
||||
return true;
|
||||
}
|
||||
|
||||
void unallocate()
|
||||
{
|
||||
void unallocate() {
|
||||
delete[] _buffer;
|
||||
_buffer = nullptr;
|
||||
}
|
||||
|
||||
void push(const data_type &sample)
|
||||
{
|
||||
void push(const data_type &sample) {
|
||||
uint8_t head_new = _head;
|
||||
|
||||
if (!_first_write) {
|
||||
@@ -123,19 +119,18 @@ public:
|
||||
|
||||
uint8_t get_oldest_index() const { return _tail; }
|
||||
|
||||
bool pop_first_older_than(const uint64_t ×tamp, data_type *sample)
|
||||
{
|
||||
bool pop_first_older_than(const uint64_t ×tamp, data_type *sample) {
|
||||
// start looking from newest observation data
|
||||
for (uint8_t i = 0; i < _size; i++) {
|
||||
int index = (_head - i);
|
||||
index = index < 0 ? _size + index : index;
|
||||
|
||||
if (timestamp >= _buffer[index].time_us && timestamp - _buffer[index].time_us < (uint64_t)1e5) {
|
||||
|
||||
*sample = _buffer[index];
|
||||
|
||||
// Now we can set the tail to the item which comes after the one we removed
|
||||
// since we don't want to have any older data in the buffer
|
||||
// Now we can set the tail to the item which
|
||||
// comes after the one we removed since we don't
|
||||
// want to have any older data in the buffer
|
||||
if (index == _head) {
|
||||
_tail = _head;
|
||||
_first_write = true;
|
||||
@@ -150,7 +145,8 @@ public:
|
||||
}
|
||||
|
||||
if (index == _tail) {
|
||||
// we have reached the tail and haven't got a match
|
||||
// we have reached the tail and haven't got a
|
||||
// match
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user