Changed name of Config dashboard to Tuning. Added ActionEnum component.

This commit is contained in:
PAJohnson
2020-09-28 05:06:12 -04:00
parent fa48d7050f
commit fd7d1dfa74
13 changed files with 337 additions and 112 deletions
+2
View File
@@ -4,6 +4,7 @@ import os
from flask import make_response, request, jsonify, session
from flask_socketio import SocketIO, send, emit
from flask_cors import CORS
from engineio.payload import Payload
import json
import time
import argparse
@@ -20,6 +21,7 @@ app.config.update(
SESSION_COOKIE_SAMESITE='None'
)
CORS(app, support_credentials=True)
Payload.max_decode_packets = 100
socketio = SocketIO(app, cors_allowed_origins="*", async_mode = "threading")
def get_all_odrives():
+1 -1
View File
@@ -35,7 +35,7 @@
<button
v-if="
dash.name !== 'Start' &&
dash.name !== 'Config' &&
dash.name !== 'Tuning' &&
dash.name !== 'Wizard'
"
class="close-button"
@@ -1,5 +1,5 @@
{
"name": "Config",
"name": "Tuning",
"component": "Dashboard",
"id": "deadb33f",
"controls": [
@@ -11,18 +11,6 @@
"controlType": "CtrlNumeric",
"path": "odrives.odrive0.axis0.controller.config.vel_limit"
},
{
"controlType": "CtrlNumeric",
"path": "odrives.odrive0.config.brake_resistance"
},
{
"controlType": "CtrlNumeric",
"path": "odrives.odrive0.axis0.motor.config.pole_pairs"
},
{
"controlType": "CtrlNumeric",
"path": "odrives.odrive0.axis0.encoder.config.cpr"
},
{
"controlType": "CtrlSlider",
"path": "odrives.odrive0.axis0.controller.config.pos_gain"
@@ -36,8 +24,58 @@
"path": "odrives.odrive0.axis0.controller.config.vel_integrator_gain"
},
{
"controlType": "CtrlFunction",
"path": "odrives.odrive0.axis0.clear_errors"
"controlType": "CtrlEnum",
"path": "odrives.odrive0.axis0.requested_state",
"options": [
{
"text": "Undefined",
"value": 0
},
{
"text": "Idle",
"value": 1
},
{
"text": "Starup Sequence",
"value": 2
},
{
"text": "Full Calibration Sequence",
"value": 3
},
{
"text": "Motor Calibration",
"value": 4
},
{
"text": "Sensorless Control",
"value": 5
},
{
"text": "Encoder Index Search",
"value": 6
},
{
"text": "Encoder Offset Calibration",
"value": 7
},
{
"text": "Closed Loop Control",
"value": 8
},
{
"text": "Lockin Spin",
"value": 9
},
{
"text": "Encoder Direction Find",
"value": 10
},
{
"text": "Homing",
"value": 11
}
]
},
{
"controlType": "CtrlFunction",
@@ -46,22 +84,14 @@
],
"actions": [
{
"id": "407aea0a-2b16-4d77-8043-2c43b27e4810",
"path": "odrives.odrive0.axis0.requested_state",
"val": 3
},
{
"id": "91b2c1b3-f1bb-4473-9e7a-dd89615cecc9",
"path": "odrives.odrive0.axis0.requested_state",
"val": 8
},
{
"id": "ad0ebe2a-a495-4e33-9cb8-b2ab17dc3a83",
"actionType": "Action",
"id": "a699c462-cf8d-4b4e-aedf-0b200e84f97a",
"path": "odrives.odrive0.axis0.controller.pos_setpoint",
"val": 0
},
{
"id": "d7abba09-b0aa-438a-8220-6126e467004e",
"actionType": "Action",
"id": "db267ae4-fdf4-4770-a2d3-eb61de026659",
"path": "odrives.odrive0.axis0.controller.pos_setpoint",
"val": 50000
}
@@ -1,5 +1,5 @@
{
"name": "Config",
"name": "Tuning",
"component": "Dashboard",
"id": "deadb33f",
"controls": [
@@ -11,18 +11,6 @@
"controlType": "CtrlNumeric",
"path": "odrives.odrive0.axis0.controller.config.vel_limit"
},
{
"controlType": "CtrlNumeric",
"path": "odrives.odrive0.config.brake_resistance"
},
{
"controlType": "CtrlNumeric",
"path": "odrives.odrive0.axis0.motor.config.pole_pairs"
},
{
"controlType": "CtrlNumeric",
"path": "odrives.odrive0.axis0.encoder.config.cpr"
},
{
"controlType": "CtrlSlider",
"path": "odrives.odrive0.axis0.controller.config.pos_gain"
@@ -36,8 +24,58 @@
"path": "odrives.odrive0.axis0.controller.config.vel_integrator_gain"
},
{
"controlType": "CtrlFunction",
"path": "odrives.odrive0.axis0.clear_errors"
"controlType": "CtrlEnum",
"path": "odrives.odrive0.axis0.requested_state",
"options": [
{
"text": "Undefined",
"value": 0
},
{
"text": "Idle",
"value": 1
},
{
"text": "Starup Sequence",
"value": 2
},
{
"text": "Full Calibration Sequence",
"value": 3
},
{
"text": "Motor Calibration",
"value": 4
},
{
"text": "Sensorless Control",
"value": 5
},
{
"text": "Encoder Index Search",
"value": 6
},
{
"text": "Encoder Offset Calibration",
"value": 7
},
{
"text": "Closed Loop Control",
"value": 8
},
{
"text": "Lockin Spin",
"value": 9
},
{
"text": "Encoder Direction Find",
"value": 10
},
{
"text": "Homing",
"value": 11
}
]
},
{
"controlType": "CtrlFunction",
@@ -46,22 +84,14 @@
],
"actions": [
{
"id": "407aea0a-2b16-4d77-8043-2c43b27e4810",
"path": "odrives.odrive0.axis0.requested_state",
"val": 3
},
{
"id": "91b2c1b3-f1bb-4473-9e7a-dd89615cecc9",
"path": "odrives.odrive0.axis0.requested_state",
"val": 8
},
{
"id": "ad0ebe2a-a495-4e33-9cb8-b2ab17dc3a83",
"actionType": "Action",
"id": "a699c462-cf8d-4b4e-aedf-0b200e84f97a",
"path": "odrives.odrive0.axis0.controller.input_pos",
"val": 0
},
{
"id": "d7abba09-b0aa-438a-8220-6126e467004e",
"actionType": "Action",
"id": "db267ae4-fdf4-4770-a2d3-eb61de026659",
"path": "odrives.odrive0.axis0.controller.input_pos",
"val": 10
}
+9 -2
View File
@@ -1,10 +1,10 @@
<template>
<div class="card action-card">
<button class="close-button" @click=deleteAction>X</button>
<span class="ctrlName">{{path}}:</span>
<span class="ctrlName">{{shortPath}}:</span>
<div class="right">
<input v-on:change="newVal" :placeholder="initVal"/>
<button class="action-button close-button" @click="putVal">Go</button>
<button class="action-button close-button" @click="putVal">Send</button>
</div>
</div>
</template>
@@ -30,6 +30,13 @@ export default {
this.value = this.initVal;
}
},
computed: {
shortPath() {
let keys = this.path.split('.');
keys.shift();
return keys.join('.');
}
},
methods: {
newVal: function (e) {
let input = e.target.value;
+95
View File
@@ -0,0 +1,95 @@
<template>
<div class="card action-card">
<button class="close-button" @click=deleteAction>X</button>
<span class="ctrlName">{{shortPath}}:</span>
<div class="right">
<select class="action-enum" v-model="value" @change="newVal">
<option v-for="option in options" :key="option.value" :value="option.value">
{{ option.text }}
</option>
</select>
<button class="action-button close-button" @click="putVal">Send</button>
</div>
</div>
</template>
<script>
import { putVal } from "../../lib/odrive_utils.js";
export default {
name: "ActionEnum",
props: {
id: String,
path: String,
initVal: Number,
dashID: String,
options: Array,
},
data: function () {
return {
value: 0,
};
},
created() {
if (this.initVal !== undefined) {
this.value = this.initVal;
}
},
computed: {
shortPath() {
let keys = this.path.split('.');
keys.shift();
return keys.join('.');
}
},
methods: {
newVal: function (e) {
console.log(this.selected);
this.value = parseFloat(e.target.value);
this.$store.commit("setActionVal", {dashID: this.dashID, actionID: this.id, val: this.value});
},
putVal: function () {
let keys = this.path.split(".");
keys.shift();
console.log('path = ' + keys.join('.') + ", val = " + this.value);
putVal(keys.join('.'), this.value);
},
deleteAction: function() {
// commit a mutation to remove this action from the dashboard
this.$store.commit("removeActionFromDash", {dashID: this.dashID, actionID: this.id});
}
},
};
</script>
<style scoped>
input {
border-style: none;
border-bottom: 1px solid grey;
width: 5rem;
margin-left: 0.5rem;
margin-right: 0.5rem;
text-align: center;
}
.action-card {
display: flex;
/* border: 1px solid lightcoral; */
box-sizing: border-box;
}
.action-button {
margin-right: 0;
}
.right {
margin-left: auto;
}
.action-enum {
border: none;
border-bottom: 1px solid grey;
background-color: var(--fg-color);
text-align-last: right;
}
</style>
+17 -2
View File
@@ -3,7 +3,8 @@
<button class="close-button" @click=deleteCtrl>X</button>
<span class="ctrlName">{{name}}:</span>
<div class="right">
<span class="ctrlVal">{{value}}</span>
<span class="ctrlVal" v-if="!writeAccess">{{value}}</span>
<span class="ctrlVal" v-if="writeAccess">{{fakeValue}}</span>
<input
class="ctrlInput"
v-if="writeAccess"
@@ -16,7 +17,7 @@
</template>
<script>
import { getVal, getReadonly, putVal } from "../../lib/odrive_utils.js";
import { getVal, getReadonly, putVal, fetchParam } from "../../lib/odrive_utils.js";
export default {
name: "CtrlBoolean",
@@ -26,6 +27,11 @@ export default {
odrives: Object,
dashID: String,
},
data() {
return {
fakeValue: undefined,
}
},
computed: {
value: function () {
let keys = this.path.split(".");
@@ -48,12 +54,21 @@ export default {
let keys = this.path.split('.');
keys.shift();
putVal(keys.join('.'), e.target.checked);
fetchParam(keys.join('.'));
this.fakeValue = e.target.checked;
},
deleteCtrl: function() {
// commit a mutation in the store with the relevant information
this.$store.commit("removeCtrlFromDash", {dashID: this.dashID, path: this.path});
}
},
created() {
// update parameter value on component creation
let keys = this.path.split('.');
keys.shift();
fetchParam(keys.join('.'));
this.fakeValue = getVal(keys.join('.'));
}
};
</script>
+6 -2
View File
@@ -3,7 +3,6 @@
<button class="close-button" @click=deleteCtrl>X</button>
<span class="ctrlName">{{name}}:</span>
<div class="right">
<!-- <input v-if="writeAccess" type="number" v-on:change="putVal" /> -->
<select class="ctrl-enum" v-model="selected" @change="putVal">
<option v-for="option in options" :key="option.value" :value="option.value">
{{ option.text }}
@@ -14,7 +13,7 @@
</template>
<script>
import { getVal, getReadonly, putVal } from "../../lib/odrive_utils.js";
import { getVal, getReadonly, putVal, fetchParam } from "../../lib/odrive_utils.js";
export default {
name: "CtrlNumeric",
@@ -65,6 +64,11 @@ export default {
},
},
created() {
// update parameter value on component creation
let keys = this.path.split('.');
keys.shift();
fetchParam(keys.join('.'));
this.selected = this.value;
console.log(this.value);
}
+9 -3
View File
@@ -3,14 +3,14 @@
<button class="close-button" @click=deleteCtrl>X</button>
<span class="ctrlName">{{name}}:</span>
<div class="right">
<span class="ctrlVal">{{value}}</span>
<input v-if="writeAccess" v-on:change="putVal" />
<span v-if="!writeAccess" class="ctrlVal">{{value}}</span>
<input v-if="writeAccess" :placeholder="value" v-on:change="putVal" />
</div>
</div>
</template>
<script>
import { getVal, getReadonly, putVal } from "../../lib/odrive_utils.js";
import { getVal, getReadonly, putVal, fetchParam } from "../../lib/odrive_utils.js";
export default {
name: "CtrlNumeric",
@@ -58,6 +58,12 @@ export default {
this.$store.commit("removeCtrlFromDash", {dashID: this.dashID, path: this.path});
}
},
created() {
// update parameter value on component creation
let keys = this.path.split('.');
keys.shift();
fetchParam(keys.join('.'));
},
};
</script>
+3 -3
View File
@@ -75,11 +75,11 @@ export default {
let initVal = () => {
let keys = this.path.split(".");
keys.shift(); // don't need first key here
return parseFloat(getVal(keys.join('.'))).toFixed(3);
return getVal(keys.join('.'));
};
this.value = initVal();
this.max = this.value * 4;
this.min = this.value / 4;
this.max = parseFloat((this.value * 4).toFixed(3));
this.min = parseFloat((this.value / 4).toFixed(3));
this.data = Array.from(Array(101), (_, i) => this.min + (this.max-this.min) / 100 * i);
},
};
+9 -10
View File
@@ -1,7 +1,7 @@
import Vue from 'vue';
import Vuex from 'vuex';
import ConfigDashOld from "./assets/dashboards/Config_0_4_12.json";
import ConfigDashNew from "./assets/dashboards/Config_0_5_1.json";
import TuningDashOld from "./assets/dashboards/Tuning_0_4_12.json";
import TuningDashNew from "./assets/dashboards/Tuning_0_5_1.json";
import * as socketio from "./comms/socketio";
import {filterBy, deleteBy } from "./lib/utils.js";
//import { v4 as uuidv4 } from "uuid";
@@ -27,7 +27,6 @@ export default new Vuex.Store({
name: "Start",
component: "Start",
},
//{ name: "Config", id: uuidv4(), component: "Dashboard", controls: [], actions: [], plots: [] }
],
timeSampleStart: 0,
sampledProperties: [], // make this an object where the full path is a key and the value is the sampled var
@@ -46,23 +45,23 @@ export default new Vuex.Store({
state.odrives = odrives;
if (state.firstConn == false) {
// first time we're getting odrive data, add correct config page
let ConfigDash;
let TuningDash;
if (state.odrives.odrive0.fw_version_minor.val == "5") {
ConfigDash = ConfigDashNew;
TuningDash = TuningDashNew;
}
else if (state.odrives.odrive0.fw_version_minor.val == "4") {
ConfigDash = ConfigDashOld;
TuningDash = TuningDashOld;
}
else {
ConfigDash = ConfigDashNew;
TuningDash = TuningDashNew;
}
state.dashboards.push({
name: "Wizard",
component: "Wizard",
});
state.dashboards.push(ConfigDash);
state.dashboards.push(TuningDash);
// plots will have variables associated, add them to sampled variables list
for (const plot of ConfigDash.plots) {
for (const plot of TuningDash.plots) {
for (const plotVar of plot.vars) {
//addsampledprop(path);
let path = plotVar.path;
@@ -275,7 +274,7 @@ export default new Vuex.Store({
// create object of only ODrive parameters that are writeable and numeric
let writeAbleNumeric = filterBy(context.state.odrives, ((o) => o['readonly'] == false && ['float', 'int', 'bool'].includes(o['type'])));
deleteBy(writeAbleNumeric, ((o) => o.constructor == Object && Object.keys(o).length == 0))
context.commit('setOdriveConfigs', {full: fullTree,
functions: fcns,
params: params,
+22 -6
View File
@@ -35,13 +35,15 @@
<div class="add-button card" @click="addComponent('function')">Add Function</div>
</div>
<template v-for="(action, index) in dash.actions">
<action
<component
:is="action.actionType"
:id="action.id"
:key="index + '-action'"
:path="action.path"
:odrives="odrives"
:initVal="action.val"
:dashID="dash.id"
:options="action.options"
/>
</template>
<div class="add-button card" @click="addComponent('action')">Add Action</div>
@@ -74,6 +76,7 @@ import CtrlSlider from "../components/controls/CtrlSlider.vue";
import CtrlEnum from "../components/controls/CtrlEnum.vue";
import Plot from "../components/plots/Plot.vue";
import Action from "../components/actions/Action.vue";
import ActionEnum from "../components/actions/ActionEnum.vue"
import { JSONView } from "vue-json-component";
import { v4 as uuidv4 } from "uuid";
@@ -264,6 +267,7 @@ export default {
CtrlEnum,
Plot,
Action,
ActionEnum,
"json-view": JSONView,
},
props: ["dash", "odrives"],
@@ -385,11 +389,23 @@ export default {
{
// add an action to the current dash
let id = uuidv4();
this.dash.actions.push({
id: id,
path: e.path,
val: undefined,
});
console.log("action, key = " + e.key);
if (Object.keys(odriveEnums).includes(e.key)){
this.dash.actions.push({
actionType: "ActionEnum",
id: id,
path: e.path,
options: odriveEnums[e.key],
})
}
else {
this.dash.actions.push({
actionType: "Action",
id: id,
path: e.path,
val: undefined,
});
}
}
break;
case "slider":
+50 -29
View File
@@ -82,6 +82,18 @@ export default {
// require special handling. This function is used for those events
pageEventHandler(e) {
this.choiceMade = false;
let clear = () => {
let paths = [
"odrive0." + e.axis + ".error",
"odrive0." + e.axis + ".motor.error",
"odrive0." + e.axis + ".encoder.error",
"odrive0." + e.axis + ".controller.error",
];
for (const path of paths) {
putVal(path, 0);
}
console.log("clearing error for " + e.axis);
};
if (e.data == "motor calibration") {
// set a timeout to grab axis resistance and inductance values
fetchParam("odrive0." + e.axis + ".error");
@@ -125,18 +137,6 @@ export default {
this.choiceMade = true;
}
};
let clear = () => {
let paths = [
"odrive0." + e.axis + ".error",
"odrive0." + e.axis + ".motor.error",
"odrive0." + e.axis + ".encoder.error",
"odrive0." + e.axis + ".controller.error",
];
for (const path of paths) {
putVal(path, 0);
}
console.log("clearing error for " + e.axis);
};
let updateCalInfo = () => {
// parse error code, update calibration information
let motorError = getVal("odrive0." + e.axis + ".motor.error");
@@ -154,12 +154,14 @@ export default {
fetchParam("odrive0." + e.axis + ".current_state");
fetchParam("odrive0." + e.axis + ".motor.config.phase_resistance");
fetchParam("odrive0." + e.axis + ".motor.config.phase_inductance");
fetchParam("odrive0." + e.axis + ".motor.is_calibrated");
console.log();
if (
getVal("odrive0." + e.axis + ".current_state") ==
odriveEnums.AXIS_STATE_MOTOR_CALIBRATION
) {
// still calibrating
console.log("waiting for motor cal to finish");
setTimeout(() => this.wait(), 100);
this.calibrating = true;
} else if (getVal("odrive0." + e.axis + ".error") != 0) {
@@ -169,16 +171,21 @@ export default {
// clear errors, display info.
updateCalInfo();
clear();
} else {
} else if (getVal("odrive0." + e.axis + ".motor.is_calibrated") == true){
// calibration is over
apply();
this.calibrating = false;
this.calStatus = true;
}
else {
setTimeout(() => this.wait(), 100);
console.log("waiting for motor cal to finish");
}
};
fetchParam("odrive0." + e.axis + ".current_state");
fetchParam("odrive0." + e.axis + ".motor.config.phase_resistance");
fetchParam("odrive0." + e.axis + ".motor.config.phase_inductance");
fetchParam("odrive0." + e.axis + ".motor.is_calibrated");
// wait for at least a second for comms to update state of ODrive
setTimeout(() => this.wait(), 1000);
} else if (e.data == "encoder calibration") {
@@ -201,19 +208,22 @@ export default {
this.wait = function () {
fetchParam("odrive0." + e.axis + ".current_state");
fetchParam("odrive0." + e.axis + ".encoder.error");
fetchParam("odrive0." + e.axis + ".encoder.is_ready");
if (
getVal("odrive0." + e.axis + ".current_state") ==
odriveEnums.AXIS_STATE_ENCODER_OFFSET_CALIBRATION
) {
setTimeout(() => this.wait(), 100);
console.log("waiting for encoder cal to finish...");
setTimeout(() => this.wait(), 100);
this.calibrating = true;
} else if (getVal("odrive0." + e.axis + ".error") != 0) {
} else if (getVal("odrive0." + e.axis + ".encoder.error") != 0) {
putVal("odrive0." + e.axis + ".encoder.config.cpr", oldCPR);
console.log("applying old CPR, error detected");
clear();
this.calibrating = false;
this.calStatus = false;
} else {
} else if (getVal("odrive0." + e.axis + ".encoder.is_ready") == true){
putVal("odrive0." + e.axis + ".encoder.config.cpr", oldCPR);
console.log("applying old CPR");
this.choiceMade = true;
@@ -221,8 +231,14 @@ export default {
this.calibrating = false;
this.calStatus = true;
}
else {
console.log("waiting for encoder cal to finish...");
setTimeout(() => this.wait(), 100);
}
};
fetchParam("odrive0." + e.axis + ".current_state");
fetchParam("odrive0." + e.axis + ".encoder.error");
fetchParam("odrive0." + e.axis + ".encoder.is_ready");
setTimeout(() => this.wait(), 1000);
}
},
@@ -240,27 +256,22 @@ export default {
// for encoders, wait for calibration to finish unless encoder.is_ready == true
this.choiceMade = true;
if (
e.choice == "ODrive D5065" ||
e.choice == "ODrive D6374" ||
e.choice == "Other motor"
this.currentStep == pages.Motor_0 || this.currentStep == pages.Motor_1
) {
let axis;
if (this.currentStep == pages.Motor_0) axis = "axis0";
if (this.currentStep == pages.Motor_1) axis = "axis1";
if (getVal("odrive0." + axis + ".motor.is_calibrated") == "False") {
if (getVal("odrive0." + axis + ".motor.is_calibrated") == false) {
this.choiceMade = false;
}
}
if (
e.choice == "CUI AMT102V" ||
e.choice == "Hall Effect" ||
e.choice == "Incremental" ||
e.choice == "IncrementalIndex"
this.currentStep == pages.Encoder_0 || this.currentStep == pages.Encoder_1
) {
let axis;
if (this.currentStep == pages.Encoder_0) axis = "axis0";
if (this.currentStep == pages.Encoder_1) axis = "axis1";
if (getVal("odrive0." + axis + ".encoder.is_ready") == "False") {
if (getVal("odrive0." + axis + ".encoder.is_ready") == false) {
this.choiceMade = false;
}
}
@@ -317,20 +328,30 @@ export default {
this.choiceMade = false;
},
},
created() {
// when wizard is active, we want to poll for certain values
let update = () => {
fetchParam("odrive0.axis0.motor.is_calibrated");
fetchParam("odrive0.axis1.motor.is_calibrated");
fetchParam("odrive0.axis0.encoder.is_ready");
fetchParam("odrive0.axis1.encoder.is_ready");
setTimeout(() => update(), 1000);
};
update();
},
beforeDestroy() {
for (const page of Object.keys(pages)) {
pages[page].choiceMade = false;
}
let erase = (obj) => {
Object.keys(obj).forEach((key) => {
if (typeof obj[key] == 'object' && obj[key] != null) {
if (typeof obj[key] == "object" && obj[key] != null) {
erase(obj[key]);
}
else {
} else {
obj[key] = null;
}
});
}
};
erase(this.wizardConfig);
},
};