Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mapping gui #49

Merged
merged 5 commits into from
Jun 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions gs/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions gs/shell.nix
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ let
];

packages = with pkgs; [
nodejs_20
pkg-config
dbus
openssl_3
Expand All @@ -23,6 +22,8 @@ let
webkitgtk
appimagekit
librsvg
rustc
cargo
cargo-tauri
];
in
Expand All @@ -34,4 +35,4 @@ pkgs.mkShell {
export LD_LIBRARY_PATH=${pkgs.lib.makeLibraryPath libraries}:$LD_LIBRARY_PATH
export XDG_DATA_DIRS=${pkgs.gsettings-desktop-schemas}/share/gsettings-schemas/${pkgs.gsettings-desktop-schemas.name}:${pkgs.gtk3}/share/gsettings-schemas/${pkgs.gtk3.name}:$XDG_DATA_DIRS
'';
}
}
6 changes: 5 additions & 1 deletion gs/src/lib/components/BottomBar.svelte
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<script lang="ts">
import { onMount } from 'svelte';
import {GrandDataDistributor} from "$lib";

let time = new Date().toLocaleTimeString([], { hour: '2-digit', minute: '2-digit', hour12: true });

Expand All @@ -12,14 +13,17 @@
clearInterval(interval);
};
});

const storeManager = GrandDataDistributor.getInstance().stores;
const fsmState = storeManager.getStore("FSMState");
</script>


<footer class="text-zinc-100 text-sm bg-primary-600 w-full flex flex-row flex-nowrap
justify-between px-4 gap-4 border-t border-black">
<p>Delft Hyperloop: Helios III</p>
<div class="flex gap-4">
<p>Current state: NOT SET</p>
<p>Current state: {$fsmState}</p>
<p class="">{time}</p>
</div>
</footer>
7 changes: 6 additions & 1 deletion gs/src/lib/components/FSM.svelte
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<script lang="ts">
import {onMount} from "svelte";
import {GrandDataDistributor} from "$lib";

export let size:'sm'|'lg' = 'sm'

Expand All @@ -19,6 +20,10 @@
let lane_switch_state:SVGGElement;
let all_states: SVGGElement[];


const storeManager = GrandDataDistributor.getInstance().stores;
const fsmState = storeManager.getStore("FSMState");

function turn_on(state:SVGGElement) {
if (state === emerg_brake_state) {
state.style.fill = '#D61111'
Expand All @@ -36,7 +41,7 @@

setInterval(() => {
turn_off_all(all_states);
turn_on(all_states[2 % all_states.length])
turn_on(all_states[$fsmState % all_states.length])
}, 100)
})

Expand Down
10 changes: 7 additions & 3 deletions gs/src/lib/components/Localiser.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
import {onMount} from "svelte";
import util from "$lib/util/util";
import {inputEmerg} from "$lib/stores/state";
import {GrandDataDistributor} from "$lib";

export let max:number = 16000;
export let max:number = 60000;
export let loc:number = 1000; /* should be < 16000 */
export let turning:boolean;

Expand Down Expand Up @@ -93,6 +94,9 @@
emergYPosition = progress_straight.getPointAtLength(emergPosition).y;
}
}

const storeManager = GrandDataDistributor.getInstance().stores;
const velocity = storeManager.getStore("Velocity");
</script>

<div class="w-full">
Expand Down Expand Up @@ -128,8 +132,8 @@
<path id="L6" d="M740.044 124V115.54H741.028V123.136H745.336V124H740.044ZM749.404 124.108C748.404 124.108 747.632 123.748 747.088 123.028C746.552 122.3 746.284 121.284 746.284 119.98C746.284 118.516 746.584 117.392 747.184 116.608C747.784 115.824 748.624 115.432 749.704 115.432C750.136 115.432 750.568 115.524 751 115.708C751.44 115.892 751.8 116.14 752.08 116.452L751.72 117.22C751.424 116.916 751.1 116.688 750.748 116.536C750.404 116.384 750.048 116.308 749.68 116.308C748.896 116.308 748.292 116.6 747.868 117.184C747.452 117.768 747.244 118.636 747.244 119.788V120.376C747.396 119.848 747.676 119.436 748.084 119.14C748.5 118.844 748.988 118.696 749.548 118.696C750.044 118.696 750.484 118.812 750.868 119.044C751.252 119.268 751.552 119.58 751.768 119.98C751.984 120.38 752.092 120.84 752.092 121.36C752.092 121.896 751.976 122.372 751.744 122.788C751.52 123.196 751.204 123.52 750.796 123.76C750.396 123.992 749.932 124.108 749.404 124.108ZM749.344 123.268C749.88 123.268 750.312 123.096 750.64 122.752C750.976 122.408 751.144 121.956 751.144 121.396C751.144 120.844 750.976 120.396 750.64 120.052C750.312 119.7 749.88 119.524 749.344 119.524C748.808 119.524 748.372 119.7 748.036 120.052C747.708 120.396 747.544 120.844 747.544 121.396C747.544 121.956 747.708 122.408 748.036 122.752C748.372 123.096 748.808 123.268 749.344 123.268Z" fill="#EFF0F0"/>
<path id="L5" d="M487.044 58V49.54H488.028V57.136H492.336V58H487.044ZM496.296 58.108C495.752 58.108 495.232 58.02 494.736 57.844C494.24 57.668 493.82 57.42 493.476 57.1L493.848 56.32C494.592 56.928 495.404 57.232 496.284 57.232C496.868 57.232 497.328 57.068 497.664 56.74C498 56.412 498.168 55.98 498.168 55.444C498.168 54.892 498.008 54.44 497.688 54.088C497.368 53.736 496.928 53.56 496.368 53.56C495.56 53.56 494.924 53.896 494.46 54.568H493.74V49.54H498.648V50.38H494.712V53.404C495.176 52.94 495.788 52.708 496.548 52.708C497.076 52.708 497.536 52.82 497.928 53.044C498.32 53.268 498.62 53.584 498.828 53.992C499.044 54.392 499.152 54.86 499.152 55.396C499.152 55.924 499.036 56.392 498.804 56.8C498.572 57.208 498.24 57.528 497.808 57.76C497.384 57.992 496.88 58.108 496.296 58.108Z" fill="#EFF0F0"/>
</g>
<text x="10" y="140" fill="#EFF0F0" font-size="12">Location: NOT SET</text>
<text x="100" y="140" fill="#EFF0F0" font-size="12">Speed: NOT SET</text>
<text x="10" y="140" fill="#EFF0F0" font-size="12">Location: {loc}</text>
<text x="100" y="140" fill="#EFF0F0" font-size="12">Speed: {$velocity}</text>
</g>
</svg>
</div>
Expand Down
7 changes: 4 additions & 3 deletions gs/src/lib/components/generic/Chart.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@
import {chartStore} from "$lib/stores/state";

export let title: string;
export let refreshRate: number = 100;
export let refreshRate: number = 1000;
export let span: number = 5*60*1000;

export let background: string = "bg-surface-800";
export let height: number = 200;
export let chart: PlotBuffer = $chartStore.get(title) || new PlotBuffer(1000, [0, 100], false);
export let chart: PlotBuffer = $chartStore.get(title) || new PlotBuffer(refreshRate, span, [0, 100], false);

let width: number;
let resize = (width:number) => {
Expand All @@ -20,7 +21,7 @@
let plotContainer: HTMLDivElement;

onMount(async () => {
chart.draw(plotContainer, refreshRate);
chart.draw(plotContainer);
resize(width)
})

Expand Down
6 changes: 1 addition & 5 deletions gs/src/lib/panels/LogsPanel.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
let filters: Record<string, boolean> = { 'STATUS': true, 'WARNING': true, 'INFO': true, 'ERROR': true }; // filter variable

$: filteredLogs = logs.filter(log => filters[log.log_type]);
``

function toggleFilter(type: string) {
filters[type] = !filters[type];
}
Expand All @@ -37,22 +37,18 @@

onMount(async () => {
unlistens[0] = await listen('status_channel', (event) => {
console.log(event)
//@ts-ignore
logs = [...logs, {message: event.payload, status: 'STATUS', timestamp: Date.now().valueOf()}];
});
unlistens[1] = await listen(EventChannels.INFO, (event) => {
console.log(event)
//@ts-ignore
logs = [...logs, {message: event.payload, log_type: 'INFO', timestamp: Date.now().valueOf()}];
});
unlistens[2] = await listen(EventChannels.WARNING, (event) => {
console.log(event)
//@ts-ignore
logs = [...logs, {message: event.payload, log_type: 'WARNING', timestamp: Date.now().valueOf()}];
});
unlistens[3] = await listen(EventChannels.ERROR, (event) => {
console.log(event)
//@ts-ignore
logs = [...logs, {message: event.payload, log_type: 'ERROR', timestamp: Date.now().valueOf()}];
});
Expand Down
24 changes: 18 additions & 6 deletions gs/src/lib/panels/VitalsPanel.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,27 @@
const lvBattery = storeManager.getStore("BatteryBalanceLow");
const hvBattery = storeManager.getStore("BatteryBalanceHigh");

const speed = storeManager.getStore("Velocity");
const position = storeManager.getStore("Localisation");

const propTemp = storeManager.getStore("PropulsionTemperature");
const leviTemp = storeManager.getStore("LevitationTemperature");
const brakeTemp = storeManager.getStore("BrakeTemperature");

let tableArr: any[][];
let tableArr2: any[][];


$: tableArr = [
["Upper drawer VB", 0],
["Bottom drawer VB", 0],
["outside of VB", 0],
["Upper drawer VB", $propTemp],
["Bottom drawer VB", $leviTemp],
["Outside of VB", $brakeTemp],
["HEMS", 0],
["Motor core", 0],
["EMS", 0],
["Motor Front", 0],
["Motor Back", 0],
]

$: tableArr2 = [
["Current State", 0],
["Bottom drawer VB", 0],
Expand Down Expand Up @@ -89,8 +101,8 @@
<Tile bgToken={700} containerClass="col-span-2">
<div class="flex flex-wrap justify-between">
<div class="flex gap-4">
<p>Velocity: <span class="font-mono font-medium">{0}</span></p>
<p>Position: <span class="font-mono font-medium">{0}</span></p>
<p>Velocity: <span class="font-mono font-medium">{$speed}</span></p>
<p>Position: <span class="font-mono font-medium">{$position}</span></p>
</div>
<div class="flex gap-4">
<div class="flex gap-2">
Expand Down
26 changes: 20 additions & 6 deletions gs/src/lib/panels/tabs/BatteriesTab.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,23 @@
const max8Vol = storeManager.getStore("Module8MaxVoltage");
const min8Vol = storeManager.getStore("Module8MinVoltage");

const avgLvTemp = storeManager.getStore("BatteryMinTemperatureLow");
const minLvTemp = storeManager.getStore("BatteryMinTemperatureLow");
const maxLvTemp = storeManager.getStore("BatteryMaxTemperatureLow");
const avgLvVol = storeManager.getStore("BatteryMinVoltageLow");
const minLvVol = storeManager.getStore("BatteryMinVoltageLow");
const maxLvVol = storeManager.getStore("BatteryMaxVoltageLow");

const lvCurrent = storeManager.getStore("BatteryCurrentLow");
const hvCurrent = storeManager.getStore("BatteryCurrentHigh");

const imdV = storeManager.getStore("IMDVoltageDetails");
const imdI = storeManager.getStore("IMDIsolationDetails")

let titles = ["Battery", "Avg cell V", "Max cell V", "Min cell V"
, "Avg cell °C", "Max cell °C", "Min cell °C"];
$: tableArr = [
["LV", "12.5V", "13.5V", "10.5V", "30°C", "50°C", "20°C"],
["LV", $avgLvVol, $maxLvVol, $minLvVol, $avgLvTemp, $maxLvTemp, $minLvTemp],
["HV mod 1", $avg1Vol, $max1Vol, $min1Vol, $avg1Temp, $max1Temp, $min1Temp],
["HV mod 2", $avg2Vol, $max2Vol, $min2Vol, $avg2Temp, $max2Temp, $min2Temp],
["HV mod 3", $avg3Vol, $max3Vol, $min3Vol, $avg3Temp, $max3Temp, $min3Temp],
Expand Down Expand Up @@ -113,18 +125,20 @@
</Tile>
<Tile insideClass="flex h-full items-center">
<div class="flex flex-col ml-4">
<p>LV Current: NOT SET</p>
<p>HV Current: NOT SET</p>
<p>LV Current: {$lvCurrent}</p>
<p>HV Current: {$hvCurrent}</p>
<p>IMD Isolat: {$imdI}</p>
<p>IMD Voltag: {$imdV}</p>
</div>
</Tile>
<Tile containerClass="col-span-4" heading="Battery stats">
<Table background="bg-surface-900" {tableArr} {titles} />
</Tile>
<Tile containerClass="col-span-2" heading="LV Current">
<Chart title="LVI" background="bg-surface-900" />
<Chart title="LV Current" background="bg-surface-900" />
</Tile>
<Tile containerClass="col-span-2" heading="HV Current">
<Chart title="LVI" background="bg-surface-900" />
<Chart title="HV Current" background="bg-surface-900" />
</Tile>
</TileGrid>
</div>
</div>
9 changes: 6 additions & 3 deletions gs/src/lib/panels/tabs/LocationTab.svelte
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<script lang="ts">
import {Table, Localiser, TileGrid, Tile, Chart, inputTurn} from "$lib";
import {Table, Localiser, TileGrid, Tile, Chart, inputTurn, GrandDataDistributor} from "$lib";
import {RunMode} from "$lib/types";

let tableArr2:any[][];
Expand All @@ -14,16 +14,19 @@
["table entry", 0],
["here", 0]
]

const storeManager = GrandDataDistributor.getInstance().stores;
const location = storeManager.getStore("Localisation");
</script>

<div class="p-4">
<h2 class="text-xl font-semibold mb-4">Location & IMU</h2>
<TileGrid columns="1fr 1fr" rows="">
<Tile containerClass="col-span-2">
<Localiser loc={0} max={50} turning={$inputTurn !== RunMode.ShortRun}/>
<Localiser loc={$location} max={50} turning={$inputTurn !== RunMode.ShortRun}/>
</Tile>
<Tile>
<Chart title="Speed" background="bg-surface-900" />
<Chart title="Velocity" background="bg-surface-900" />
</Tile>
<Tile>
<Chart title="Acceleration" background="bg-surface-900" />
Expand Down
2 changes: 1 addition & 1 deletion gs/src/lib/util/GrandDataDistributor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ class StoreManager {
* @param processFunction - the function to process the data
*/
public registerStore<T>(name: NamedDatatype, initial: T, processFunction?: dataConvFun<T>) {
if (this.stores.has(name)) throw new Error(`Store with name ${name} already exists`);
// if (this.stores.has(name)) throw new Error(`Store with name ${name} already exists`);
this.stores.set(name, new Store(initial, processFunction));
}

Expand Down
Loading
Loading