Basic support for units

This commit is contained in:
PAJohnson
2020-09-25 20:28:07 -04:00
parent 0f14c7a7db
commit aa819895d3
7 changed files with 90 additions and 12 deletions
+1 -1
View File
@@ -63,7 +63,7 @@
{
"id": "d7abba09-b0aa-438a-8220-6126e467004e",
"path": "odrives.odrive0.axis0.controller.input_pos",
"val": 50000
"val": 10
}
],
"plots": [
@@ -3,12 +3,14 @@
<div class="left">
<span>Brake resistor value =</span>
<input type="number" v-on:change="setBR" placeholder="Change Me!" />
<span> Ohms</span>
<span class="unit"> [{{unit}}] </span>
</div>
</div>
</template>
<script>
import { getUnit } from '../../../odrive_utils.js';
export default {
name: "wizardBrake",
props: {
@@ -20,6 +22,13 @@ export default {
brake_resistance: undefined,
};
},
computed: {
unit() {
// goal is to return "Ohms" from odriveUnits
let path = "odrive0.config.brake_resistance";
return getUnit(this.$store.state.odrives.odrive0,path);
},
},
methods: {
setBR(e) {
console.log("from setBR " + e.target.value);
@@ -68,4 +77,8 @@ input::-webkit-inner-spin-button {
input[type="number"] {
-moz-appearance: textfield; /* Firefox */
}
.unit {
font-family: "Roboto Mono", monospace;
}
</style>
@@ -3,16 +3,18 @@
<div class="left">
<span>Motor Velocity Limit =</span>
<input type="number" v-on:change="setVelocityLimit" :placeholder="velocityLimit" />
<span class="unit">[{{velUnit}}]</span>
</div>
<div class="left">
<span>Motor Current Limit =</span>
<input type="number" v-on:change="setCurrentLimit" :placeholder="currentLimit" />
<span class="unit">[Amps]</span>
</div>
</div>
</template>
<script>
import { getVal } from "../../../odrive_utils.js"
import { getVal, getUnit } from "../../../odrive_utils.js"
export default {
name: "wizardMisc",
@@ -37,6 +39,10 @@ export default {
let path = "odrive0." + this.data.axis + ".motor.config.current_lim";
return parseFloat(getVal(path));
},
velUnit() {
let path = "odrive0." + this.data.axis + ".controller.config.vel_limit";
return getUnit(this.$store.state.odrives.odrive0,path)
},
},
methods: {
sendConfig() {
@@ -102,7 +108,7 @@ export default {
margin: 2rem;
}
.left {
margin-left: auto;
margin-right: auto;
}
input {
@@ -136,4 +142,9 @@ input[type="number"] {
.name {
text-align: center;
}
.unit {
font-family: "Roboto Mono", monospace;
}
</style>
@@ -10,11 +10,13 @@
</div>
<div class="left">
<span>Phase Resistance =</span>
<span>{{" " + resistance}} R</span>
<span>{{" " + resistance}}</span>
<span class="unit">[Ohms]</span>
</div>
<div class="left">
<span>Phase Inductace =</span>
<span>{{" " + inductance}} H</span>
<span>{{" " + inductance}}</span>
<span class="unit">[Henries]</span>
</div>
<span class="name">Other Motor</span>
</div>
@@ -159,7 +161,7 @@ export default {
margin: 2rem;
}
.left {
margin-left: auto;
margin-right: auto;
}
.name {
@@ -189,4 +191,8 @@ input[type="number"] {
.name {
text-align: center;
}
.unit {
font-family: "Roboto Mono", monospace;
}
</style>
+50
View File
@@ -64,4 +64,54 @@ export function callFcn(path, args) {
null,
request
);
}
export function odriveMinorVersion(odrive) {
// given an odrive object, return the minor version
return odrive.fw_version_minor.val;
}
export function getUnit(odrive, path) {
let unit = undefined;
for ( const key of Object.keys(odriveUnits[odriveMinorVersion(odrive)]) ) {
if (path.includes(key)) {
unit = odriveUnits[odriveMinorVersion(odrive)][key];
}
}
return unit;
}
// standins for wizard and gui unit displays
// TODO - convert between odrive api units and user-defined units like degrees and rpm
export let odriveUnits = {
"4": {
"config.brake_resistance": "ohms",
"controller.pos_setpoint": "counts",
"controller.vel_setpoint": "counts/s",
"controller.current_setpoint": "amps",
"controller.config.vel_limit": "counts/s",
"controller.config.vel_ramp_rate": "counts/s^2",
"encoder.pos_estimate": "counts",
"encoder.vel_estimate": "counts/s",
"trap_traj.config.vel_limit": "counts/s",
"trap_traj.config.accel_limit": "counts/s^2",
"trap_traj.config.decel_limit": "counts/s^2",
"motor.config.phase_resistance": "ohms",
"motor.config.phase_inductance": "henries",
},
"5": {
"config.brake_resistance": "ohms",
"controller.input_pos": "turns",
"controller.input_vel": "turns/s",
"controller.current_setpoint": "amps",
"controller.config.vel_limit": "turns/s",
"controller.config.vel_ramp_rate": "turns/s^2",
"encoder.pos_estimate": "turns",
"encoder.vel_estimate": "turns/s",
"trap_traj.config.vel_limit": "turns/s",
"trap_traj.config.accel_limit": "turns/s^2",
"trap_traj.config.decel_limit": "turns/s^2",
"motor.config.phase_resistance": "ohms",
"motor.config.phase_inductance": "henries",
}
}
+1
View File
@@ -413,6 +413,7 @@ export default {
.controls {
flex-grow: 1;
border-right: 1px solid lightgrey;
overflow-y: scroll;
}
.add-button {
+2 -5
View File
@@ -9,7 +9,7 @@
<div class="connected-container">
<input type="text" :class="{ notConnected: notConnected, connected: connected}" v-on:change="setUrl" :value="serverAddress">
</div>
<button class="show-msg-button" @click="showServerMessages = !showServerMessages;">Having Trouble? Click here for debug output</button>
<button class="show-msg-button" @click="showServerMessages = !showServerMessages;">Having trouble? Click here for debug output</button>
<div class="server-msgs" v-if="showServerMessages">
<div class="server-msg" v-for="(msg, index) in serverMessages" :key="msg + index">{{msg}}</div>
</div>
@@ -109,10 +109,7 @@ input:focus {
border: none;
background-color: var(--bg-color);
margin-top: 0.5rem;
}
.server-msgs {
margin-top: 2rem;
cursor: pointer;
}
.server-msg {