-
-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathPlayground.java
156 lines (130 loc) · 6.59 KB
/
Playground.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
/* Copyright (c) 2022 StuyPulse Robotics. All rights reserved. */
/* This work is licensed under the terms of the MIT license */
/* found in the root directory of this project. */
package com.stuypulse.stuylib.util.plot;
import com.stuypulse.stuylib.math.Vector2D;
import com.stuypulse.stuylib.math.Regression.LinearRegression;
import com.stuypulse.stuylib.math.interpolation.*;
import com.stuypulse.stuylib.streams.*;
import com.stuypulse.stuylib.streams.angles.AFuser;
import com.stuypulse.stuylib.streams.angles.AStream;
import com.stuypulse.stuylib.streams.angles.filters.AHighPassFilter;
import com.stuypulse.stuylib.streams.angles.filters.ALowPassFilter;
import com.stuypulse.stuylib.streams.angles.filters.AMotionProfile;
import com.stuypulse.stuylib.streams.angles.filters.ARateLimit;
import com.stuypulse.stuylib.streams.booleans.*;
import com.stuypulse.stuylib.streams.booleans.filters.*;
import com.stuypulse.stuylib.streams.filters.*;
import com.stuypulse.stuylib.streams.vectors.*;
import com.stuypulse.stuylib.streams.vectors.filters.*;
import com.stuypulse.stuylib.util.plot.FuncSeries.Domain;
import com.stuypulse.stuylib.util.plot.Series.Config;
import com.stuypulse.stuylib.util.plot.TimeSeries.TimeSpan;
public class Playground {
public interface Constants {
int CAPACITY = 10;
String TITLE = "StuyLib Plotting Library";
String X_AXIS = "x-axis";
String Y_AXIS = "y-axis";
int WIDTH = 800;
int HEIGHT = 600;
double MIN_X = 0.0;
double MAX_X = 10.0;
double MIN_Y = 0.0;
double MAX_Y = 10.0;
Settings SETTINGS =
new Settings()
.setSize(WIDTH, HEIGHT)
.setAxes(TITLE, X_AXIS, Y_AXIS)
.setXRange(MIN_X, MAX_X)
.setYRange(MIN_Y, MAX_Y);
public static Series make(String id, IFilter function) {
return new FuncSeries(new Config(id, CAPACITY), new Domain(MIN_X, MAX_X), function);
}
public static Series make(String id, IStream series) {
return new TimeSeries(new Config(id, CAPACITY), new TimeSpan(MIN_X, MAX_X), series);
}
public static Series make(String id, VStream series) {
return new XYSeries(new Config(id, CAPACITY), series);
}
public static Series make(String id, AStream series, double magnitude) {
return new AngleSeries(new Config(id, CAPACITY), series, magnitude);
}
public static Series make(String id, BStream series) {
return make(id, IStream.create(series));
}
}
public static void main(String[] args) throws InterruptedException {
Plot plot = new Plot(Constants.SETTINGS);
VStream m = VStream.create(() -> plot.getMouse().sub(new Vector2D(0.5, 0.5)).mul(2));
AStream angle_mouse = AStream.create(() -> m.get().getAngle());
AStream jerk_angle = angle_mouse.filtered(new AMotionProfile(-1, 4));
AStream rate_angle = angle_mouse.filtered(new ARateLimit(1));
AStream lpf_angle = angle_mouse.filtered(new ALowPassFilter(0.5));
AStream hpf_angle = angle_mouse.filtered(new AHighPassFilter(0.5));
AStream delay_angle =
angle_mouse
.filtered(new ALowPassFilter(0.25))
.add(
AStream.create(
IStream.create(() -> Math.random() - 0.5)
.filtered(new LowPassFilter(1))));
AStream afuser_angle = new AFuser(1, delay_angle, angle_mouse);
VStream mouse = VStream.create(() -> angle_mouse.get().getVector().mul(1.0));
VStream jerk = VStream.create(() -> jerk_angle.get().getVector().mul(0.95));
VStream rate = VStream.create(() -> rate_angle.get().getVector().mul(0.9));
VStream lpf = VStream.create(() -> lpf_angle.get().getVector().mul(0.85));
VStream hpf = VStream.create(() -> hpf_angle.get().getVector().mul(0.8));
VStream delay = VStream.create(() -> delay_angle.get().getVector().mul(1.1));
VStream afuser = VStream.create(() -> afuser_angle.get().getVector().mul(1.05));
Vector2D[] refPoints = {new Vector2D(1,2), new Vector2D(2,5), new Vector2D(6, 10)};
LinearRegression LinearRegression = new LinearRegression(refPoints);
plot.addSeries(new FuncSeries(
new Config("linear regression", 1000),
new Domain(0, 10),
x -> LinearRegression.predictedValue(x)
));
// plot.addSeries(Constants.make("Angle", mouse))
// .addSeries(Constants.make("Jerk", jerk))
// .addSeries(Constants.make("Rate", rate))
// .addSeries(Constants.make("LPF", lpf))
// .addSeries(Constants.make("HPF", hpf))
// .addSeries(Constants.make("afuser", afuser))
// .addSeries(Constants.make("delayed", delay))
// .addSeries(Constants.make("mouse", m));
//
// .addSeries(Constants.make("y=x", x -> x))
// .addSeries(
// Constants.make(
// "interp",
// new LinearInterpolator(
// new Vector2D(0.0, 0.43),
// new Vector2D(0.2, 0.56),
// new Vector2D(0.4, 0.72),
// new Vector2D(0.6, 0.81),
// new Vector2D(0.8, 0.02),
// new Vector2D(1.0, 0.11))))
// .addSeries(Constants.make("mouse y", IStream.create(plot::getMouseY)))
// .addSeries(
// Constants.make(
// "lpf",
// IStream.create(plot::getMouseY).filtered(new LowPassFilter(0.2))))
// .addSeries(
// Constants.make("mouse bool", BStream.create(() -> plot.getMouseY() > 0.5)))
// .addSeries(
// Constants.make(
// "debounced",
// BStream.create(() -> plot.getMouseY() > 0.5)
// .filtered(new BDebounce.Both(1.0))))
// .addSeries(Constants.make("mouse position", VStream.create(plot::getMouse)))
// .addSeries(
// Constants.make(
// "jerk limit",
// VStream.create(plot::getMouse)
// .filtered(new VJerkLimit(10.0, 5.0))));
while (plot.isRunning()) {
plot.update();
Thread.sleep(10);
}
}
}