Skip to content

Commit

Permalink
add throttle settings
Browse files Browse the repository at this point in the history
  • Loading branch information
bkleiner committed Jul 23, 2022
1 parent 3cb25da commit dbff3e5
Show file tree
Hide file tree
Showing 3 changed files with 146 additions and 0 deletions.
137 changes: 137 additions & 0 deletions src/panel/ThrottleSettings.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
<template>
<div class="card">
<header class="card-header">
<p class="card-header-title">Throttle Settings</p>
</header>

<div class="card-content">
<div class="content">
<div class="columns column-narrow field-is-5">
<div class="column is-6">
<div class="field is-horizontal mt-6">
<div class="field-label">
<label class="label" for="throttle_mid">
Throttle Mid
<tooltip entry="rate.throttle_mid" />
</label>
</div>
<div class="field-body">
<div class="field">
<div class="control is-expanded">
<input
class="input"
step="0.01"
id="throttle_mid"
type="number"
min="0"
max="1"
v-model.number="profile.rate.throttle_mid"
/>
</div>
</div>
</div>
</div>

<div class="field is-horizontal">
<div class="field-label">
<label class="label" for="throttle_expo">
Throttle Expo
<tooltip entry="rate.throttle_expo" />
</label>
</div>
<div class="field-body">
<div class="field">
<div class="control is-expanded">
<input
class="input"
step="0.01"
id="throttle_expo"
type="number"
min="0"
max="1"
v-model.number="profile.rate.throttle_expo"
/>
</div>
</div>
</div>
</div>
</div>
<div class="column is-6">
<LineChart
:title="'Throttle'"
:labels="plot.labels"
:axis="plot.axis"
></LineChart>
</div>
</div>
</div>
</div>
</div>
</template>

<script lang="ts">
import { useProfileStore } from "@/store/profile";
import { defineComponent } from "vue";
import LineChart from "@/components/LineChart.vue";
export default defineComponent({
name: "ThrottleSettings",
components: {
LineChart,
},
setup() {
return {
profile: useProfileStore(),
};
},
data() {
return {
plot: {
labels: ["Throttle"],
axis: [
{
label: "Throttle",
data: [] as any[],
},
],
},
};
},
watch: {
"profile.rate.throttle_expo"() {
this.update();
},
"profile.rate.throttle_mid"() {
this.update();
},
},
methods: {
constrainf(val, lower, upper) {
if (val > upper) return upper;
if (val < lower) return lower;
return val;
},
calcThrottle(throttle: number): number {
const n = throttle * 2.0 - 1.0;
const expo = this.profile.rate.throttle_expo;
const mid = this.profile.rate.throttle_mid;
return this.constrainf((n * n * n * expo + n * (1.0 - expo) + 1.0) * mid, 0.0, 1.0);
},
update() {
const axis = [] as any[];
for (let i = 0; i <= 100; i++) {
const input = i / 100.0;
axis.push({
x: i,
y: this.calcThrottle(input) * 100,
});
}
this.plot.axis[0].data = axis;
},
},
created() {
this.update();
},
});
</script>
2 changes: 2 additions & 0 deletions src/store/profile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ export const useProfileStore = defineStore("profile", {
level_max_angle: 0,
sticks_deadband: 0,
rates: [] as any[],
throttle_expo: 0,
throttle_mid: 0,
},
voltage: {},
receiver: {
Expand Down
7 changes: 7 additions & 0 deletions src/views/Rates.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
<StickRatesLegacy v-if="default_profile.has_legacy_stickrates"></StickRatesLegacy>
<StickRates v-else></StickRates>
</div>
<div v-if="profile.profileVersionGt('0.2.0')" class="column is-12">
<ThrottleSettings></ThrottleSettings>
</div>
<div class="column is-12">
<PIDRates></PIDRates>
</div>
Expand All @@ -19,7 +22,9 @@ import StickRates from "@/panel/StickRates.vue";
import StickRatesLegacy from "@/panel/StickRatesLegacy.vue";
import PIDRates from "@/panel/PIDRates.vue";
import FilterSettings from "@/panel/FilterSettings.vue";
import ThrottleSettings from "@/panel/ThrottleSettings.vue";
import { useDefaultProfileStore } from "@/store/default_profile";
import { useProfileStore } from "@/store/profile";
export default defineComponent({
name: "Rate",
Expand All @@ -28,9 +33,11 @@ export default defineComponent({
PIDRates,
FilterSettings,
StickRatesLegacy,
ThrottleSettings,
},
setup() {
return {
profile: useProfileStore(),
default_profile: useDefaultProfileStore(),
};
},
Expand Down

0 comments on commit dbff3e5

Please sign in to comment.