Skip to content
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

Add/Fix pdp.GetAllCurrents() #6025

Merged
merged 7 commits into from
May 24, 2024
Merged

Conversation

scarmain
Copy link
Contributor

@scarmain scarmain commented Dec 9, 2023

For logging purposes, logging all the PDP channels ends up with 16/24 CAN frame requests for all the currents. Using the functions provided by the low level drivers, we can get this down to 3/4 requests.

I implemented the JNI interface to support both PDPs now (it was capped at 16 channels), and added support for both C++ and Java. I also implemented GetNumChannels() in C++ to have more identical interfaces between C++/Java.

This change is in support of #5314, but not really part of it. I would love to move this to a DataLogBuffer like the driver station data, but the PDP doesn't have a periodic function to run the data logging. Also, it might be nice to change the initSendable functions to use these buffered reads instead of individual channel reads it does now (not exactly sure how to do this).

@scarmain scarmain requested review from a team as code owners December 9, 2023 17:45
hal/src/main/native/cpp/jni/PowerDistributionJNI.cpp Outdated Show resolved Hide resolved
wpilibc/src/main/native/cpp/PowerDistribution.cpp Outdated Show resolved Hide resolved
wpilibc/src/main/native/cpp/PowerDistribution.cpp Outdated Show resolved Hide resolved
wpilibc/src/main/native/cpp/PowerDistribution.cpp Outdated Show resolved Hide resolved
Copy link
Contributor Author

@scarmain scarmain left a comment

Choose a reason for hiding this comment

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

Updated with new commit

@scarmain
Copy link
Contributor Author

scarmain commented Dec 9, 2023

/format

@@ -87,6 +94,17 @@ double PowerDistribution::GetCurrent(int channel) const {
return current;
}

std::vector<double> PowerDistribution::GetAllCurrents() const {
Copy link
Member

Choose a reason for hiding this comment

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

@PeterJohnson should we make this be a SmallVector too? This could be a pretty hot path.

Copy link
Contributor Author

@scarmain scarmain Dec 10, 2023

Choose a reason for hiding this comment

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

I choose std::vector as it was the return type of all the NetworkTables get__Array() like GetDoubleArray(). I'm neutral either way.

The API call here should be the vector/SmallVector though, as I don't see anywhere in the C++ APIs that we return arrays.

Honestly, if speed was a concern, I think in the JNI service, we could go back to my initial prototype of just a straight double[24] array. We don't need a vector there as we could just allocate to the biggest PDP size, and the HAL filling the array means it doesn't need to be initialized too. Since it doesn't leave the function, we don't need the dynamic sizing there. I just didn't see as much array support in C++ (and I'm not a native C++ developer).

Copy link
Member

@PeterJohnson PeterJohnson Dec 11, 2023

Choose a reason for hiding this comment

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

So typically how we do this is we have both a vector and a SmallVector overload of the same function. So you would keep the current function and add a SmallVector-taking one: std::span<double> GetAllCurrents(wpi::SmallVectorImpl<double>& buf).

@scarmain
Copy link
Contributor Author

Also, should I improve the LiveWindow to use this new function, saving 75% reads? I think the way you would do this is use the SetUpdateTable() like ADXL345_I2C instead of the individual builders.

@PeterJohnson
Copy link
Member

Re: Sendable, I think the right way to do this (although we would need to update dashboards to match) is to change it from individual topics to one DoubleArray topic.

@scarmain
Copy link
Contributor Author

I made a new version, where the initSendable now uses the GetAllCurrents() function. Let me know and I can merge this in too. I think this is the best compromise without having to rewrite all the dashboards so close to kickoff.

scarmain@6b0f490

@calcmogul calcmogul added component: wpilibj WPILib Java component: wpilibc WPILib C++ component: hal Hardware Abstraction Layer labels Dec 16, 2023
@Gold856
Copy link
Contributor

Gold856 commented Dec 17, 2023

I don't like how it changes PowerDistribution to use NTSendable instead of Sendable. Logging Sendables with DataLog is something that would be desirable, and the more classes that use NTSendable, the harder it'll be to migrate. Although, work on that has been suspended until we think more about telemetry. Since there's another easy to implement, but breaking solution, I'm okay with taking on a little bit of tech debt here to avoid breaking stuff, as long as we pay it off by properly implementing it after this season.

@PeterJohnson PeterJohnson merged commit c62396c into wpilibsuite:main May 24, 2024
25 checks passed
chauser pushed a commit to chauser/allwpilib that referenced this pull request May 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: hal Hardware Abstraction Layer component: wpilibc WPILib C++ component: wpilibj WPILib Java
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants