Move circular buffer class from wpilib to wpiutil (#1840)

This commit is contained in:
Tyler Veness
2019-08-24 21:35:19 -07:00
committed by Peter Johnson
parent 4cd8a56672
commit e3d86fee46
9 changed files with 26 additions and 28 deletions

View File

@@ -12,8 +12,7 @@
#include <units/units.h>
#include <wpi/ArrayRef.h>
#include "frc/circular_buffer.h"
#include <wpi/circular_buffer.h>
namespace frc {
@@ -142,8 +141,8 @@ class LinearFilter {
double Calculate(double input);
private:
circular_buffer<double> m_inputs{0};
circular_buffer<double> m_outputs{0};
wpi::circular_buffer<double> m_inputs{0};
wpi::circular_buffer<double> m_outputs{0};
std::vector<double> m_inputGains;
std::vector<double> m_outputGains;
};

View File

@@ -12,9 +12,9 @@
#include <vector>
#include <wpi/ArrayRef.h>
#include <wpi/circular_buffer.h>
#include <wpi/deprecated.h>
#include "frc/circular_buffer.h"
#include "frc/filters/Filter.h"
namespace frc {
@@ -215,8 +215,8 @@ class LinearDigitalFilter : public Filter {
double PIDGet() override;
private:
circular_buffer<double> m_inputs;
circular_buffer<double> m_outputs;
wpi::circular_buffer<double> m_inputs;
wpi::circular_buffer<double> m_outputs;
std::vector<double> m_inputGains;
std::vector<double> m_outputGains;
};

View File

@@ -11,6 +11,7 @@ import java.util.Arrays;
import edu.wpi.first.hal.FRCNetComm.tResourceType;
import edu.wpi.first.hal.HAL;
import edu.wpi.first.wpiutil.CircularBuffer;
/**
* This class implements a linear, digital filter. All types of FIR and IIR filters are supported.

View File

@@ -11,8 +11,8 @@ import java.util.Arrays;
import edu.wpi.first.hal.FRCNetComm.tResourceType;
import edu.wpi.first.hal.HAL;
import edu.wpi.first.wpilibj.CircularBuffer;
import edu.wpi.first.wpilibj.PIDSource;
import edu.wpi.first.wpiutil.CircularBuffer;
/**
* This class implements a linear, digital filter. All types of FIR and IIR filters are supported.

View File

@@ -1,11 +1,11 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) 2015-2018 FIRST. All Rights Reserved. */
/* Copyright (c) 2015-2019 FIRST. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
/*----------------------------------------------------------------------------*/
package edu.wpi.first.wpilibj;
package edu.wpi.first.wpiutil;
/**
* This is a simple circular buffer so we don't need to "bucket brigade" copy old values.

View File

@@ -1,5 +1,5 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) 2015-2018 FIRST. All Rights Reserved. */
/* Copyright (c) 2015-2019 FIRST. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
@@ -10,7 +10,7 @@
#include <cstddef>
#include <vector>
namespace frc {
namespace wpi {
/**
* This is a simple circular buffer so we don't need to "bucket brigade" copy
@@ -57,6 +57,6 @@ class circular_buffer {
size_t ModuloDec(size_t index);
};
} // namespace frc
} // namespace wpi
#include "frc/circular_buffer.inc"
#include "wpi/circular_buffer.inc"

View File

@@ -1,5 +1,5 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) 2015-2018 FIRST. All Rights Reserved. */
/* Copyright (c) 2015-2019 FIRST. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
@@ -9,7 +9,7 @@
#include <algorithm>
namespace frc {
namespace wpi {
template <class T>
circular_buffer<T>::circular_buffer(size_t size) : m_data(size, 0) {}
@@ -236,4 +236,4 @@ size_t circular_buffer<T>::ModuloDec(size_t index) {
}
}
} // namespace frc
} // namespace wpi

View File

@@ -1,11 +1,11 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) 2015-2018 FIRST. All Rights Reserved. */
/* Copyright (c) 2015-2019 FIRST. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
/*----------------------------------------------------------------------------*/
package edu.wpi.first.wpilibj;
package edu.wpi.first.wpiutil;
import org.junit.jupiter.api.Test;

View File

@@ -1,18 +1,16 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) 2015-2018 FIRST. All Rights Reserved. */
/* Copyright (c) 2015-2019 FIRST. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
/*----------------------------------------------------------------------------*/
#include "frc/circular_buffer.h" // NOLINT(build/include_order)
#include "wpi/circular_buffer.h" // NOLINT(build/include_order)
#include <array>
#include "gtest/gtest.h"
using namespace frc;
static const std::array<double, 10> values = {
{751.848, 766.366, 342.657, 234.252, 716.126, 132.344, 445.697, 22.727,
421.125, 799.913}};
@@ -24,7 +22,7 @@ static const std::array<double, 8> pushBackOut = {
{342.657, 234.252, 716.126, 132.344, 445.697, 22.727, 421.125, 799.913}};
TEST(CircularBufferTest, PushFrontTest) {
circular_buffer<double> queue(8);
wpi::circular_buffer<double> queue(8);
for (auto& value : values) {
queue.push_front(value);
@@ -36,7 +34,7 @@ TEST(CircularBufferTest, PushFrontTest) {
}
TEST(CircularBufferTest, PushBackTest) {
circular_buffer<double> queue(8);
wpi::circular_buffer<double> queue(8);
for (auto& value : values) {
queue.push_back(value);
@@ -48,7 +46,7 @@ TEST(CircularBufferTest, PushBackTest) {
}
TEST(CircularBufferTest, PushPopTest) {
circular_buffer<double> queue(3);
wpi::circular_buffer<double> queue(3);
// Insert three elements into the buffer
queue.push_back(1.0);
@@ -91,7 +89,7 @@ TEST(CircularBufferTest, PushPopTest) {
}
TEST(CircularBufferTest, ResetTest) {
circular_buffer<double> queue(5);
wpi::circular_buffer<double> queue(5);
for (size_t i = 1; i < 6; i++) {
queue.push_back(i);
@@ -105,7 +103,7 @@ TEST(CircularBufferTest, ResetTest) {
}
TEST(CircularBufferTest, ResizeTest) {
circular_buffer<double> queue(5);
wpi::circular_buffer<double> queue(5);
/* Buffer contains {1, 2, 3, _, _}
* ^ front