Skip to content

Conversation

onlycs
Copy link
Contributor

@onlycs onlycs commented Feb 21, 2025

image
image

Very simply, we get struct information by listening for all announced topics and if it is has type structschema, we store it and parse as-needed into a DynStructSchema (lib/services/struct_schemas/dyn_struct.dart). When we subscribe to or get data from a topic that uses a schema, we provide DynStructSchema along with the Uint8List to DynStruct which recursively parses struct fields and values.

I also made saving actually save to a file

@github-actions github-actions bot added GUI Changes to Elastic's UI workflows Changes to GitHub Workflows labels Feb 21, 2025
@github-actions github-actions bot removed the workflows Changes to GitHub Workflows label Feb 25, 2025
@Gold872
Copy link
Owner

Gold872 commented Mar 3, 2025

Leaving this comment here to let you know that this is on my list of things to review, it's just a lot of changes and will take a bit of time to go through, I should have some time next week

Excellent work though, I'm very impressed with the implementation!

Copy link
Owner

@Gold872 Gold872 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for taking so long to get to this!

I'm very impressed that you were able to get this implemented! In the past I've avoided adding struct decoding since it felt out of scope with Elastic, but with more recent (and planned) struct integration throughout WPILib it would make sense to have the ability to display (but not edit) individual struct fields.

That being said though, there's still some things I would like to have changed/fixed. Firstly, I'm a bit confused between the difference between NT4StructMeta and DynStructSchema. I'm also not sure if it entirely makes sense to have the widgets store the entire schema in its json, since it means that any time a struct field widget is created, it will assume that the schema has never changed. For example, if a widget is created with a struct schema for some type of Swerve State, but then the dashboard connects to a robot with a different struct that has the same name, the widget will always assume that it's the same which can cause invalid values to be displayed. It might make sense to instead store the name of the struct and its field, and have it looked up whenever a new value comes in.

Lastly, I would want to have unit tests for the schema parsing, decoding, and displaying. Right now that might not be easy to add since there's a lot of stuff still being changed around, but I would definitely want lots of these new features in unit tests before being merged. They can be a pain to write, but they've saved me from breaking a lot of important features.

@onlycs
Copy link
Contributor Author

onlycs commented Mar 21, 2025

Thanks for reviewing it and sorry for the late reply. Comps keep me busy!

DynStructSchema is a data class that contains the schema of the struct (i.e. fields and field names) NT4StructMeta contains a NT path to the root value (containing the entire struct and all of its data), a path to the subvalue (e.g. pose.rotation.value to get a Pose2d's angle in radians), and the schema of the struct it's using to parse. Basically, schema is for the struct as a whole and meta is for the value field in the struct which is used by elastic

I'm 80% sure the code as it stands will bail out by showing raw bytes if the schemas don't line up for some reason.

@onlycs
Copy link
Contributor Author

onlycs commented Apr 4, 2025

I went ahead and removed ntStructMeta from the multitopic widgets

@github-actions github-actions bot added dependencies Changes to Elastic's dependencies workflows Changes to GitHub Workflows and removed dependencies Changes to Elastic's dependencies workflows Changes to GitHub Workflows labels Apr 4, 2025
@Gold872
Copy link
Owner

Gold872 commented Apr 21, 2025

I just rebased this branch since the merges were getting very messy. I think I preserved the proper changes but I'm not entirely sure. Let me know when you would like me to re-review this, since I'd like to add this into the 2026 beta.

@onlycs
Copy link
Contributor Author

onlycs commented Apr 25, 2025

i was in the middle of adding typechecking to nt types so I committed those changes too. im going to mark this as a draft until i finish fixing tests

@onlycs onlycs marked this pull request as draft April 25, 2025 12:47
@onlycs
Copy link
Contributor Author

onlycs commented Apr 25, 2025

Also there's a problem where widgets in list layouts are too small. Dunno why that's happening; afaik I didn't change anything relating to that

@github-actions github-actions bot added the workflows Changes to GitHub Workflows label Apr 25, 2025
@github-actions github-actions bot added the dependencies Changes to Elastic's dependencies label May 26, 2025
@onlycs
Copy link
Contributor Author

onlycs commented May 26, 2025

i successfully managed to rebase this onto the new formatter branch

@onlycs onlycs marked this pull request as ready for review May 26, 2025 15:22
@onlycs onlycs requested a review from Gold872 May 26, 2025 20:55
@Gold872
Copy link
Owner

Gold872 commented May 26, 2025

Thanks for finishing this up! Before I can do another full review, could you undo the formatting changes? For a PR of this size it's much easier to review when the formatting remains the same since there's a lot of changes unrelated to the PR

Copy link
Owner

@Gold872 Gold872 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After a lot of work and reworking, this PR is now ready to be merged into main. Thank you for adding this feature. Although a lot of the code was changed, the initial implementation was a huge part of the PR.

Here's a list of the major changes that have been made:

  • Unit tests for everything
  • Modifying struct parsing and decoding to match WPILib's struct spec
  • Better error handling for edge cases
  • Several fixes relating to edge cases, saving/loading schemas, and handling user edits
  • Removing NTStructValue, instead using a dynamic type
  • Make SchemaManager an instance variable for NTConnection

There's several other minor changes that were also made, if you're interested, you can look through all of the commits made.

I do expect for there to be some issues that will pop up during beta, but the feature has been very stable throughout testing.

@Gold872 Gold872 merged commit 21e6c79 into Gold872:main Oct 3, 2025
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
GUI Changes to Elastic's UI
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants