Skip to content

[WIP] new bound state objects #7

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
wants to merge 2 commits into
base: Sussex
Choose a base branch
from
Open

[WIP] new bound state objects #7

wants to merge 2 commits into from

Conversation

tomlazar
Copy link
Member

No description provided.

@aaron97neu
Copy link
Contributor

LGTM, want to see testing. Add examples of how it would be used. Like the idea of starting a 'lib2202' submodule/maven dependency/folder we copy every year

@dlaufen
Copy link
Contributor

dlaufen commented Feb 23, 2022

Needs examples for simple data types: double/int/string.
How do we deal with a collection of values for a given sub-system or command's use.
Sub-system Input vs monitor only?

@dlaufen
Copy link
Contributor

dlaufen commented Feb 23, 2022

Rather than extending SubsystemBase could it be handled through an implements instead? Also see if you can make it take a type template Apply , should reduce the code and work for anything that has Supplier

@tomlazar
Copy link
Member Author

@dlaufen I only added the NtInput in the first one as a demo.

I added a demo to the example going forward, the subsystem I wrote doesn't need to be used when writing new ones, that subsystem takes care of updating the values. So like in the demo.

    class State {

        @NtInput(name = "set")
        public double SetPoint = 0;

        @NtOutput(name = "err")
        public double Error = 0;
        
        // @NtInput()
    }

    State left = NtBind.getInstance().bind(new State(), "left", this::onChanged);
    State right = NtBind.getInstance().bind(new State(), "right", this::onChanged);

    void onChanged() {
        System.out.println("SetPoint: " + left.SetPoint + ", err: " + left.Error);
        System.out.println("SetPoint: " + right.SetPoint + ", err: " + right.Error);
    }

using the static instance of NtBind you can name and attach as many versions of a state object as you want.

@tomlazar tomlazar marked this pull request as ready for review February 25, 2022 22:24
@aaron97neu
Copy link
Contributor

Code should be well commented
Add some API documentation in English showing what each method does, and what each argument for each method should be, and some full examples

Something like this

<TStateObject> TStateObject bind(TStateObject state, String name, Runnable onChange)
Binds object provided as state to the network table under label name. OnChange determines when it updates. Returns a thing that should be used for this

// We have a shooter and we want to output the flywheel error (variable name `f_speed`) to the network table 
//  and read the allowed flywheel tolerance (`f_tolerance`) from the network table. We also output the name 
//  of the flywheel (`f_name`) because we need a string example. The code would look something like this:


// TODO: Whatever sets up the nt thing with the name of the table and stuff
String f_name = "Red Flywheel"
double f_speed = 0;
int f_tolerance = 0;
State s = nt.bind(f_name, "Flywheel Name", State::Write); // ???
s = nt.bind(f_speed, "Flywheel Speed",  State::Write); // ???
s = nt.bind(f_tolerance, "Flywheel Tolance", State::Read); // ???

void Periodic(){
  f_speed = encoder.getSpeed();
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants