-
Notifications
You must be signed in to change notification settings - Fork 0
Add Param List UI element #247
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
Open
chachmu
wants to merge
1
commit into
main
Choose a base branch
from
dev/chachmu/ui_play_params
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,120 @@ | ||
| <template> | ||
| <v-container v-if="this.getPlaysWithParams.length == 0"> | ||
| <v-col class="d-flex justify-center"> | ||
| <v-progress-circular indeterminate class="mx-auto"/> | ||
| </v-col> | ||
| </v-container> | ||
| <div v-else> | ||
| <v-btn block @click.stop="getParamValues" variant="outlined"> Refresh </v-btn> | ||
|
|
||
| <!-- Some of the responsive sizing could be a lot better here --> | ||
| <div v-for="[play_name, play] of this.getPlaysWithParams"> | ||
|
|
||
| <v-spacer class="pt-2"/> | ||
|
|
||
| <v-card :title="play.name" variant="outlined"> | ||
| <v-container | ||
| v-for="[param_name, param] of Object.entries(play.params)" | ||
| class="flex-grow-1 flex-shrink-0" | ||
| > | ||
|
|
||
| <v-row justify="start" align="center" style="flex-wrap: nowrap;"> | ||
| <v-spacer class="pr-2"/> | ||
| <div>{{ param_name + ": "}}</div> | ||
| <v-spacer class="pr-1"/> | ||
| <input type="text" | ||
| v-model="param.commanded_value" | ||
| class="flex-shrink-1" | ||
| style=" | ||
| max-width: 4em; | ||
| background-color: rgb(44, 44, 44); | ||
| " | ||
| /> | ||
| <v-spacer class="pr-1"/> | ||
| <v-btn justify="end" density="compact" @click="updateParam(param)"> | ||
| <v-icon icon="mdi-send" class="mx-0"/> | ||
| </v-btn> | ||
| </v-row> | ||
| </v-container> | ||
| </v-card> | ||
| </div> | ||
| </div> | ||
|
|
||
| </template> | ||
|
|
||
| <script lang="ts"> | ||
| import { ref, inject } from "vue"; | ||
| import { Param } from "@/param"; | ||
| import '@mdi/font/css/materialdesignicons.css' | ||
|
|
||
|
|
||
| export default { | ||
| inject: ['state'], | ||
| data() { | ||
| return { | ||
| selectedPlay: [] | ||
| } | ||
| }, | ||
| mounted() { | ||
| this.getParamValues(); | ||
|
|
||
| // TODO: This is bad but roslibjs doesn't seem to expose a way to | ||
| // wait for updates from the getParams functions | ||
| const self = this; | ||
| setTimeout(function(){ self.getParamValues() }, 3000); | ||
| }, | ||
| methods: { | ||
| getParamValues: function() { | ||
| // Update list of params | ||
| this.state.getSTPParams(); | ||
|
|
||
| // Get param values from ROS | ||
| for (const [play_name, play] of Object.entries(this.state.plays)) { | ||
| for (const [param_name, param] of Object.entries(play.params)) { | ||
| param.getValue(); | ||
| } | ||
| } | ||
| }, | ||
| updateParam(param: Param) { | ||
| param.setValue(param.commanded_value); | ||
| } | ||
| }, | ||
| computed: { | ||
| getPlaysWithParams: function() { | ||
| const play_array = Object.entries(this.state.plays) | ||
| if (play_array) { | ||
| return play_array.filter(function(play_object_entry) { | ||
| const play = play_object_entry[1]; | ||
| return Object.entries(play.params).length; | ||
| }); | ||
| } | ||
|
|
||
| return []; | ||
| }, | ||
| monitorParamValues: function() { | ||
| // This function is necessary to trigger rerendering when param values | ||
| // change | ||
| let param_values = {}; | ||
| for (const [play_name, play] of Object.entries(this.state.plays)) { | ||
| for (const [param_name, param] of Object.entries(play.params)) { | ||
| param_values[param_name] = param.commanded_value; | ||
| } | ||
| } | ||
|
|
||
| return param_values; | ||
| } | ||
| }, | ||
| watch: { | ||
| getPlaysWithParams: { | ||
| handler() { | ||
| }, | ||
| deep: true | ||
| }, | ||
| monitorParamValues: { | ||
| handler() { | ||
| }, | ||
| deep: true | ||
| } | ||
| } | ||
| } | ||
| </script> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| // Types used for params | ||
|
|
||
| import ROSLIB from "roslib"; | ||
|
|
||
| export class Param { | ||
| name: string; // Name of STP parameter (not the full ROS param path) | ||
| ros_param: ROSLIB.Param; | ||
| value: any = null; | ||
| commanded_value: any = null; // holds the input from the param ui component | ||
|
|
||
| constructor(name: string, ros_param: ROSLIB.Param) { | ||
| this.name = name; | ||
| this.ros_param = ros_param; | ||
| } | ||
|
|
||
| getValue() { | ||
| const self = this; // fix dumb javascript things | ||
|
|
||
| this.ros_param.get( | ||
| function(value){ | ||
| self.value = value; | ||
| self.commanded_value = value; | ||
| }); | ||
| } | ||
|
|
||
| setValue(value: any) { | ||
| const self = this; // fix dumb javascript things | ||
| this.ros_param.set(value, function(response) { | ||
| // For some reason roslibjs refuses to provide | ||
| // response information from parameter service calls | ||
| // if we ever fix it we can reenable this: | ||
| /* | ||
| if (response.success) { | ||
| self.value = value; | ||
| self.commanded_value = value; | ||
| } else { | ||
| console.log("Failed to set ", self.name, ": ", response); | ||
| self.commanded_value = self.value; // if failed reset the ui value | ||
| } | ||
| */ | ||
|
|
||
| // For now just assume success | ||
| self.value = value; | ||
| self.commanded_value = value; | ||
| }); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This appears to assume all parameters are at the play level. Parameters can be created anywhere in the STP tree, so in reality we might have something like this:
stp_parameters.StopPlay.EasyMoveTo.MaxVelocity.How hard would it be to show that full tree?