Skip to content

Commit

Permalink
Adapt regression to signals
Browse files Browse the repository at this point in the history
  • Loading branch information
rbrott committed Mar 7, 2023
1 parent 332704b commit db869f3
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 16 deletions.
18 changes: 13 additions & 5 deletions TeamCode/src/main/assets/tuning/dead-wheel-angular-ramp.html
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ <h1>RR Dead Wheel Angular Ramp Regression</h1>
<script>
function loadRegression(data) {
const [_, angVels] = data.angVels.reduce((acc, vsArg) => {
const vs = fixAngVels(vsArg.slice(0, -1)).map(v => Math.abs(v));
const vs = fixAngVels(vsArg.values.slice(0, -1)).map(v => Math.abs(v));
const maxV = vs.reduce((acc, v) => Math.max(acc, v), 0);
const [accMaxV, _] = acc;
if (maxV >= accMaxV) {
Expand All @@ -93,23 +93,31 @@ <h1>RR Dead Wheel Angular Ramp Regression</h1>
const div = document.createElement('div');
newLinearRegressionChart(div,
angVels.slice(1, -1),
fixVels(data.encTimes.slice(0, -1), data.parEncPositions[i].slice(0, -1), vs.slice(0, -1)),
fixVels(
vs.times.slice(0, -1),
data.parEncPositions[i].values.slice(0, -1),
vs.values.slice(0, -1)
),
{title: `Parallel Wheel ${i} Regression`, slope: 'y-position', noIntercept: true});
deadWheelCharts.appendChild(div);
});
data.perpEncVels.forEach((vs, i) => {
const div = document.createElement('div');
newLinearRegressionChart(div,
angVels.slice(1, -1),
fixVels(data.encTimes.slice(0, -1), data.perpEncPositions[i].slice(0, -1), vs.slice(0, -1)),
fixVels(
vs.times.slice(0, -1),
data.perpEncPositions[i].values.slice(0, -1),
vs.values.slice(0, -1)
),
{title: `Perpendicular Wheel ${i} Regression`, slope: 'x-position', noIntercept: true});
deadWheelCharts.appendChild(div);
});

const setParams = (() => {
const allPowers = [...data.leftPowers, ...data.rightPowers];
const appliedVoltages = data.voltages.slice(0, -1).map((v, i) =>
allPowers.reduce((acc, ps) => Math.max(acc, ps[i]), 0) * v);
const appliedVoltages = data.voltages.values.slice(0, -1).map((v, i) =>
allPowers.reduce((acc, ps) => Math.max(acc, ps.values[i]), 0) * v);

const setTrackWidthData = newLinearRegressionChart(
document.getElementById('trackWidthChart'),
Expand Down
14 changes: 7 additions & 7 deletions TeamCode/src/main/assets/tuning/drive-encoder-angular-ramp.html
Original file line number Diff line number Diff line change
Expand Up @@ -62,31 +62,31 @@ <h1>RR Drive Encoder Angular Ramp Regression</h1>
<script>
function loadRegression(data) {
const leftEncVels = data.leftEncVels.map((vs, i) =>
fixVels(data.encTimes.slice(0, -1), data.leftEncPositions[i].slice(0, -1), vs.slice(0, -1)));
fixVels(vs.times.slice(0, -1), data.leftEncPositions[i].values.slice(0, -1), vs.values.slice(0, -1)));
const rightEncVels = data.rightEncVels.map((vs, i) =>
fixVels(data.encTimes.slice(0, -1), data.rightEncPositions[i].slice(0, -1), vs.slice(0, -1)));
fixVels(vs.times.slice(0, -1), data.rightEncPositions[i].values.slice(0, -1), vs.values.slice(0, -1)));

newLinearRegressionChart(
document.getElementById('rampChart'),
[
...leftEncVels.flatMap(vs => vs.slice(0, -1).map(v => -v)),
...rightEncVels.flatMap(vs => vs.slice(0, -1)),
...leftEncVels.flatMap(vs => vs.values.slice(0, -1).map(v => -v)),
...rightEncVels.flatMap(vs => vs.values.slice(0, -1)),
],
[
...data.leftPowers.flatMap(ps => {
const psNew = ps.slice(0, -1).map((p, i) => -p * data.voltages[i]);
const psNew = ps.values.slice(0, -1).map((p, i) => -p * data.voltages.values[i]);
return psNew.slice(1, -1);
}),
...data.rightPowers.flatMap(ps => {
const psNew = ps.slice(0, -1).map((p, i) => p * data.voltages[i]);
const psNew = ps.values.slice(0, -1).map((p, i) => p * data.voltages.values[i]);
return psNew.slice(1, -1);
}),
],
{title: 'Ramp Regression', slope: 'kV', intercept: 'kS'}
);

const p = data.angVels.reduce((acc, vsArg) => {
const vs = fixAngVels(vsArg).map(v => Math.abs(v));
const vs = fixAngVels(vsArg.values).map(v => Math.abs(v));
const maxV = vs.reduce((acc, v) => Math.max(acc, v), 0);
const [accMaxV, _] = acc;
if (maxV >= accMaxV) {
Expand Down
8 changes: 4 additions & 4 deletions TeamCode/src/main/assets/tuning/forward-ramp.html
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,10 @@ <h1>RR Forward Ramp Regression</h1>
<script>
function loadRegression(data) {
const forwardEncVels = data.forwardEncVels.flatMap((vs, i) =>
fixVels(data.encTimes.slice(0, -1), data.forwardEncPositions[i].slice(0, -1), vs.slice(0, -1)));
const appliedVoltages = data.forwardEncVels.flatMap(vs => {
const voltages = data.voltages.slice(0, -1).map((v, i) =>
data.powers.reduce((acc, ps) => Math.max(acc, ps[i]), 0) * v);
fixVels(vs.times.slice(0, -1), data.forwardEncPositions[i].values.slice(0, -1), vs.values.slice(0, -1)));
const appliedVoltages = data.forwardEncVels.flatMap(() => {
const voltages = data.voltages.values.slice(0, -1).map((v, i) =>
data.powers.reduce((acc, ps) => Math.max(acc, ps.values[i]), 0) * v);

return voltages.slice(1, voltages.length - 1);
});
Expand Down

0 comments on commit db869f3

Please sign in to comment.