This repository has been archived by the owner on Apr 20, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ce83680
commit f67f2bf
Showing
8 changed files
with
226 additions
and
114 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
// Copyright (c) FIRST and other WPILib contributors. | ||
// Open Source Software; you can modify and/or share it under the terms of | ||
// the WPILib BSD license file in the root directory of this project. | ||
|
||
package frc.robot.util; | ||
|
||
public record TimeData(double time, double data) {} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// Copyright (c) FIRST and other WPILib contributors. | ||
// Open Source Software; you can modify and/or share it under the terms of | ||
// the WPILib BSD license file in the root directory of this project. | ||
|
||
package frc.robot.util; | ||
|
||
import java.util.ArrayList; | ||
|
||
public class TimedDataBuffer { | ||
ArrayList<TimeData> dataSet = new ArrayList<TimeData>(); | ||
private int size = 0; | ||
|
||
public TimedDataBuffer(int size) { | ||
this.size = size; | ||
} | ||
|
||
public void addData(double time, double data) { | ||
if (dataSet.size() > size) { | ||
dataSet.remove(0); | ||
} | ||
dataSet.add(new TimeData(time, data)); | ||
} | ||
|
||
public double lookupData(double time) { | ||
if (time <= dataSet.get(0).time()) { | ||
return dataSet.get(0).data(); | ||
} | ||
if (time >= dataSet.get(dataSet.size() - 1).time()) { | ||
return dataSet.get(dataSet.size() - 1).data(); | ||
} | ||
|
||
for (int i = 0; i < dataSet.size() - 1; i++) { | ||
double x1 = dataSet.get(i).time(); | ||
double x2 = dataSet.get(i + 1).time(); | ||
double y1 = dataSet.get(i).data(); | ||
double y2 = dataSet.get(i + 1).data(); | ||
|
||
if (time >= x1 && time <= x1) { | ||
double slope = (y2 - y1) / (x2 - x1); | ||
return (slope * time) + (y1 - (slope * x1)); | ||
} | ||
} | ||
return dataSet.get(dataSet.size() - 1).data(); | ||
} | ||
} |
This file contains 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
Oops, something went wrong.