mirror of
https://github.com/odriverobotics/ODrive.git
synced 2026-08-18 01:18:52 +08:00
Added CtrlEnum for parameter values that have enums associated with them
This commit is contained in:
@@ -0,0 +1,102 @@
|
||||
<template>
|
||||
<div class="card">
|
||||
<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" v-bind:key="option.value" v-bind:value="option.value">
|
||||
{{ option.text }}
|
||||
</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import { getVal, getReadonly, putVal } from "../../odrive_utils.js";
|
||||
|
||||
export default {
|
||||
name: "CtrlNumeric",
|
||||
//type checking here for properties
|
||||
props: {
|
||||
path: String,
|
||||
odrives: Object,
|
||||
dashID: String,
|
||||
options: Array,
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
selected: undefined,
|
||||
}
|
||||
},
|
||||
computed: {
|
||||
value: function () {
|
||||
let keys = this.path.split('.');
|
||||
keys.shift();
|
||||
return parseFloat(getVal(keys.join('.')));
|
||||
},
|
||||
name: function () {
|
||||
let keys = this.path.split(".");
|
||||
keys.shift();
|
||||
return keys.join(".");
|
||||
},
|
||||
writeAccess: function () {
|
||||
let keys = this.path.split(".");
|
||||
keys.shift(); // don't need first key here
|
||||
return getReadonly(keys.join('.')) === false;
|
||||
},
|
||||
},
|
||||
watch: {
|
||||
value: function(newVal) {
|
||||
this.selected = newVal;
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
putVal: function (e) {
|
||||
let keys = this.path.split('.');
|
||||
keys.shift();
|
||||
console.log("Calling putVal from CtrlEnum");
|
||||
putVal(keys.join('.'), parseFloat(e.target.value));
|
||||
},
|
||||
deleteCtrl: function() {
|
||||
// commit a mutation in the store with the relevant information
|
||||
this.$store.commit("removeCtrlFromDash", {dashID: this.dashID, path: this.path});
|
||||
},
|
||||
},
|
||||
created() {
|
||||
this.selected = this.value;
|
||||
console.log(this.value);
|
||||
}
|
||||
};
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.ctrlVal {
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
input {
|
||||
width: 5rem;
|
||||
font-family: inherit;
|
||||
border-style: none;
|
||||
border-bottom: 1px solid grey;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.right {
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
margin-left: auto;
|
||||
}
|
||||
|
||||
.card {
|
||||
display: flex;
|
||||
}
|
||||
|
||||
.ctrl-enum {
|
||||
border: none;
|
||||
border-bottom: 1px solid grey;
|
||||
background-color: var(--fg-color);
|
||||
}
|
||||
</style>
|
||||
+186
-4
@@ -24,6 +24,7 @@
|
||||
:key="index + '-control'"
|
||||
:path="control.path"
|
||||
:name="control.name"
|
||||
:options="control.options"
|
||||
:odrives="odrives"
|
||||
:dashID="dash.id"
|
||||
/>
|
||||
@@ -69,6 +70,7 @@ import CtrlBoolean from "../components/controls/CtrlBoolean.vue";
|
||||
import CtrlNumeric from "../components/controls/CtrlNumeric.vue";
|
||||
import CtrlFunction from "../components/controls/CtrlFunction.vue";
|
||||
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 { JSONView } from "vue-json-component";
|
||||
@@ -82,6 +84,175 @@ let plotColors = [
|
||||
"#d5241a", // red
|
||||
];
|
||||
|
||||
let odriveEnums = {
|
||||
// axis requested state
|
||||
requested_state: [
|
||||
{
|
||||
text: "AXIS_STATE_UNDEFINED",
|
||||
value: 0,
|
||||
},
|
||||
{
|
||||
text: "AXIS_STATE_IDLE",
|
||||
value: 1,
|
||||
},
|
||||
{
|
||||
text: "AXIS_STATE_STARTUP_SEQUENCE",
|
||||
value: 2,
|
||||
},
|
||||
{
|
||||
text: "AXIS_STATE_FULL_CALIBRATION_SEQUENCE",
|
||||
value: 3,
|
||||
},
|
||||
{
|
||||
text: "AXIS_STATE_MOTOR_CALIBRATION",
|
||||
value: 4,
|
||||
},
|
||||
{
|
||||
text: "AXIS_STATE_SENSORLESS_CONTROL",
|
||||
value: 5,
|
||||
},
|
||||
{
|
||||
text: "AXIS_STATE_ENCODER_INDEX_SEARCH",
|
||||
value: 6,
|
||||
},
|
||||
{
|
||||
text: "AXIS_STATE_ENCODER_OFFSET_CALIBRATION",
|
||||
value: 7,
|
||||
},
|
||||
{
|
||||
text: "AXIS_STATE_CLOSED_LOOP_CONTROL",
|
||||
value: 8,
|
||||
},
|
||||
{
|
||||
text: "AXIS_STATE_LOCKIN_SPIN",
|
||||
value: 9,
|
||||
},
|
||||
{
|
||||
text: "AXIS_STATE_ENCODER_DIR_FIND",
|
||||
value: 10,
|
||||
},
|
||||
{
|
||||
text: "AXIS_STATE_HOMING",
|
||||
value: 11,
|
||||
}
|
||||
],
|
||||
current_state: [
|
||||
{
|
||||
text: "AXIS_STATE_UNDEFINED",
|
||||
value: 0,
|
||||
},
|
||||
{
|
||||
text: "AXIS_STATE_IDLE",
|
||||
value: 1,
|
||||
},
|
||||
{
|
||||
text: "AXIS_STATE_STARTUP_SEQUENCE",
|
||||
value: 2,
|
||||
},
|
||||
{
|
||||
text: "AXIS_STATE_FULL_CALIBRATION_SEQUENCE",
|
||||
value: 3,
|
||||
},
|
||||
{
|
||||
text: "AXIS_STATE_MOTOR_CALIBRATION",
|
||||
value: 4,
|
||||
},
|
||||
{
|
||||
text: "AXIS_STATE_SENSORLESS_CONTROL",
|
||||
value: 5,
|
||||
},
|
||||
{
|
||||
text: "AXIS_STATE_ENCODER_INDEX_SEARCH",
|
||||
value: 6,
|
||||
},
|
||||
{
|
||||
text: "AXIS_STATE_ENCODER_OFFSET_CALIBRATION",
|
||||
value: 7,
|
||||
},
|
||||
{
|
||||
text: "AXIS_STATE_CLOSED_LOOP_CONTROL",
|
||||
value: 8,
|
||||
},
|
||||
{
|
||||
text: "AXIS_STATE_LOCKIN_SPIN",
|
||||
value: 9,
|
||||
},
|
||||
{
|
||||
text: "AXIS_STATE_ENCODER_DIR_FIND",
|
||||
value: 10,
|
||||
},
|
||||
{
|
||||
text: "AXIS_STATE_HOMING",
|
||||
value: 11,
|
||||
}
|
||||
],
|
||||
// encoder mode
|
||||
mode: [
|
||||
{
|
||||
text: "ENCODER_MODE_INCREMENTAL",
|
||||
value: 0,
|
||||
},
|
||||
{
|
||||
text: "ENCODER_MODE_HALL",
|
||||
value: 1,
|
||||
},
|
||||
{
|
||||
text: "ENCODER_MODE_SINCOS",
|
||||
value: 2,
|
||||
},
|
||||
{
|
||||
text: "ENCODER_MODE_SPI_ABS_CUI",
|
||||
value: 256,
|
||||
},
|
||||
{
|
||||
text: "ENCODER_MODE_SPI_ABS_AMS",
|
||||
value: 257,
|
||||
},
|
||||
{
|
||||
text: "ENCODER_MODE_SPI_ABS_AEAT",
|
||||
value: 258,
|
||||
},
|
||||
{
|
||||
text: "ENCODER_MODE_SPI_ABS_RLS",
|
||||
value: 259,
|
||||
},
|
||||
],
|
||||
// motor type
|
||||
motor_type: [
|
||||
{
|
||||
text: "MOTOR_TYPE_HIGH_CURRENT",
|
||||
value: 0,
|
||||
},
|
||||
{
|
||||
text: "MOTOR_TYPE_GIMBAL",
|
||||
value: 2,
|
||||
},
|
||||
{
|
||||
text: "MOTOR_TYPE_ACIM",
|
||||
value: 3,
|
||||
},
|
||||
],
|
||||
// controller control mode
|
||||
control_mode: [
|
||||
{
|
||||
text: "CONTROL_MODE_VOLTAGE_CONTROL",
|
||||
value: 0,
|
||||
},
|
||||
{
|
||||
text: "CONTROL_MODE_TORQUE_CONTROL",
|
||||
value: 1,
|
||||
},
|
||||
{
|
||||
text: "CONTROL_MODE_VELOCITY_CONTROL",
|
||||
value: 2,
|
||||
},
|
||||
{
|
||||
text: "CONTROL_MODE_POSITION_CONTROL",
|
||||
value: 3,
|
||||
},
|
||||
]
|
||||
}
|
||||
|
||||
export default {
|
||||
name: "Dashboard",
|
||||
components: {
|
||||
@@ -89,6 +260,7 @@ export default {
|
||||
CtrlNumeric,
|
||||
CtrlFunction,
|
||||
CtrlSlider,
|
||||
CtrlEnum,
|
||||
Plot,
|
||||
Action,
|
||||
"json-view": JSONView,
|
||||
@@ -133,6 +305,7 @@ export default {
|
||||
//when the parameter tree is open and a parameter is clicked,
|
||||
//add the clicked parameter to the list of controls for the
|
||||
//current dashboard
|
||||
console.log(e);
|
||||
switch (this.addCompType) {
|
||||
case "control":
|
||||
switch (typeof e.value) {
|
||||
@@ -144,10 +317,19 @@ export default {
|
||||
//this.$store.commit("addSampledProperty", e.path);
|
||||
break;
|
||||
case "number":
|
||||
this.dash.controls.push({
|
||||
controlType: "CtrlNumeric",
|
||||
path: e.path,
|
||||
});
|
||||
if (Object.keys(odriveEnums).includes(e.key)){
|
||||
this.dash.controls.push({
|
||||
controlType: "CtrlEnum",
|
||||
path: e.path,
|
||||
options: odriveEnums[e.key],
|
||||
})
|
||||
}
|
||||
else {
|
||||
this.dash.controls.push({
|
||||
controlType: "CtrlNumeric",
|
||||
path: e.path,
|
||||
});
|
||||
}
|
||||
//this.$store.commit("addSampledProperty", e.path);
|
||||
break;
|
||||
case "string":
|
||||
|
||||
Reference in New Issue
Block a user