Skip to content

Commit

Permalink
add blackbox unit, pid sum
Browse files Browse the repository at this point in the history
  • Loading branch information
bkleiner committed Aug 10, 2023
1 parent 9207e6b commit 3480225
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 3 deletions.
4 changes: 3 additions & 1 deletion src/components/TimeGraphComponent.vue
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { defineComponent } from "vue";
import {
blackboxFieldIDToString,
transformBlackbox,
unitBlackbox,
useBlackboxStore,
} from "@/stores/blackbox";
import CanvasComponent from "@/components/CanvasComponent.vue";
Expand Down Expand Up @@ -136,8 +137,9 @@ export default defineComponent({
return { field, str };
})
.map(({ field, str }) => {
const unit = unitBlackbox(field);
while (str.length < maxLen) str = " " + str;
return field.title + " " + str;
return field.title + " " + str + " " + unit;
});
},
},
Expand Down
38 changes: 36 additions & 2 deletions src/stores/blackbox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,19 @@ export function transformBlackbox(field: BlackboxFieldDef, val: number) {
}
}

export function unitBlackbox(field: BlackboxFieldDef) {
switch (field.unit) {
case BlackboxFieldUnit.RADIANS:
return "deg";

case BlackboxFieldUnit.US:
return "us";

default:
return "";
}
}

function processEntries(entries: any[], fields: BlackboxFieldDef[]) {
const rawEntries = entries.filter((entry: any[], index: number) => {
if (entry.length != fields.length) {
Expand Down Expand Up @@ -82,13 +95,13 @@ export const useBlackboxStore = defineStore("blackbox", {
const options = [[]] as any[];
const fields = Object.values(this.fields);

for (const field of fields) {
const generateOption = (field: BlackboxFieldDef) => {
if (!Array.isArray(field?.axis)) {
options[0].push({
...field,
id: { name: field.name } as BlackboxFieldID,
});
continue;
return;
}

const opt: any[] = [
Expand All @@ -109,7 +122,18 @@ export const useBlackboxStore = defineStore("blackbox", {
}),
];
options.push(opt);
};

for (const field of fields) {
generateOption(field);
}
generateOption({
name: "pid_sum",
scale: 3000,
title: "Pid Sum",
unit: BlackboxFieldUnit.NONE,
axis: ["Roll", "Pitch", "Yaw"],
});

return options;
},
Expand Down Expand Up @@ -168,6 +192,16 @@ export const useBlackboxStore = defineStore("blackbox", {
entries[blackboxFieldIDToString(id)] = Float32Array.from(values);
}
}
for (let axis = 0; axis < 3; axis++) {
entries[`pid_sum_${axis}`] = entries.time.map((_, index) => {
return (
entries[`pid_pterm_${axis}`][index] +
entries[`pid_iterm_${axis}`][index] +
entries[`pid_dterm_${axis}`][index]
);
});
}

this.entries = entries;

this.duration =
Expand Down

0 comments on commit 3480225

Please sign in to comment.