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

RSDK-7753: Remove non-blocking GoFor functionality on 9/1 #4335

Merged
merged 10 commits into from
Sep 12, 2024

Conversation

martha-johnston
Copy link
Contributor

@martha-johnston martha-johnston commented Aug 30, 2024

Removed revolutions == 0 functionality from all the motors.

Now I'm wondering if there should be a check that errors if you pass in 0 revolutions? As I was going through I checked there would be no divided by zero issues, and it seems fine (but let me know if I missed any). I don't feel strongly about adding an error for every GoFor but I see the benefit of it so let me know what you think.

Copy link
Contributor

Warning your change may break code samples. If your change modifies any of the following functions please contact @viamrobotics/fleet-management. Thanks!

component function
base IsMoving
board GPIOPinByName
camera Properties
encoder Properties
motor IsMoving
sensor Readings
servo Position
arm EndPosition
audio MediaProperties
gantry Lengths
gripper IsMoving
input_controller Controls
movement_sensor LinearAcceleration
power_sensor Power
pose_tracker Poses
motion GetPose
vision GetProperties

@viambot viambot added the safe to test This pull request is marked safe to test from a trusted zone label Aug 30, 2024
@randhid randhid requested review from JohnN193 and removed request for penguinland August 30, 2024 13:20
Copy link
Member

@randhid randhid left a comment

Choose a reason for hiding this comment

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

There are a bunch of division-by-zero cases everywhere now. Please add tests for the math that explicitly test for that and do not pass if the numbers resulting from terminal actuating calls (GoFor/GoTo), do not return infinite or NaN float returns from their calcualtions.

components/motor/motor.go Outdated Show resolved Hide resolved
components/motor/gpio/mathutils.go Outdated Show resolved Hide resolved
components/motor/gpio/mathutils.go Show resolved Hide resolved
components/motor/gpio/encoded.go Show resolved Hide resolved
components/motor/fake/motor.go Outdated Show resolved Hide resolved
components/motor/dimensionengineering/sabertooth.go Outdated Show resolved Hide resolved
@viambot viambot added safe to test This pull request is marked safe to test from a trusted zone and removed safe to test This pull request is marked safe to test from a trusted zone labels Sep 3, 2024
@@ -1,15 +1,16 @@
package dimensionengineering_test
package dimensionengineering
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I changed this package to easier test goForMath because a lot of other motor packages don't use this _test convention, but I am open to changing it back if there's a good reason to do so. It's not fully clear to me what this is useful for.

Copy link
Member

Choose a reason for hiding this comment

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

This is actually a convention for making sure your test file is in a separate package which forces you to write good tests of the functionality of your exported APIs from that package. If you don't need any of the private functions in the dimensionengineering package to be tested now, please change it back.

https://stackoverflow.com/questions/19998250/proper-package-naming-for-testing-with-the-go-language/31443271#31443271

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure I can revert this and remove the goForMath tests if you'd prefer

Copy link
Member

Choose a reason for hiding this comment

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

If you don't need any of the private functions in the dimensionengineering package to be tested now, please change it back.

You are testing private function now, so don't change it back.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sorry I missed this before changing it, but I added GoFor tests so I think it should be fine now

Copy link
Member

Choose a reason for hiding this comment

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

Even better!

@viambot viambot added safe to test This pull request is marked safe to test from a trusted zone and removed safe to test This pull request is marked safe to test from a trusted zone labels Sep 3, 2024
@viambot viambot added safe to test This pull request is marked safe to test from a trusted zone and removed safe to test This pull request is marked safe to test from a trusted zone labels Sep 3, 2024
Copy link
Member

@JohnN193 JohnN193 left a comment

Choose a reason for hiding this comment

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

seems like a bunch of GoFor cases do not handle the case when rpm is set to 0. I think we should handle that in this pr since we are already touching the GoForMath function

Comment on lines 553 to 554
if rpm*revolutions == 0.0 {
dir = 0.0
Copy link
Member

Choose a reason for hiding this comment

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

not familiar with this motor, but is it okay for the GoFor call to not do anything?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

seems fine to me? but now I did add a check to gofor, which is before this point, so we shouldn't get here anyways, but I thought I should leave the 0 case in case goForMath is called directly somewhere else at a future point in time?

components/motor/fake/motor.go Show resolved Hide resolved
components/motor/gpio/basic.go Show resolved Hide resolved
components/motor/gpio/mathutils.go Show resolved Hide resolved
components/motor/gpio/mathutils.go Show resolved Hide resolved
components/motor/gpio/mathutils.go Show resolved Hide resolved
return powerPct, 0
dir := 1.0
if rpm*revolutions == 0.0 {
dir = 0.0
Copy link
Member

Choose a reason for hiding this comment

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

similar recommendation, we can return early here, especially because the logic below breaks when rpm == 0

Copy link
Member

@randhid randhid left a comment

Choose a reason for hiding this comment

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

Let's go a bit further and standardize the rpm and revolution checks for zero and return early with an error in GoFor. I think that's cleaner code-wise.

Comment on lines 262 to 270
dir := 1.0
if rpm*revolutions == 0.0 {
dir = 0.0
} else if rpm*revolutions < 0.0 {
dir = -1.0
}

if revolutions == 0 {
powerPct := rpm / maxRPM
return powerPct, 0, 1
if rpm == 0 {
return 0, 0, dir
Copy link
Member

Choose a reason for hiding this comment

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

let's make the checking functions helpers so we don't have to update them everywhere, we already have Errors and error helpers in motor.go, the check for 0 rpm and 0 revolutions is now the same., so we shouldn't copy/past identical code.

Copy link
Member

@randhid randhid Sep 11, 2024

Choose a reason for hiding this comment

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

This comment was not addressed.

EDIT: I was not re-requested for review, you only committed, sorry! Was in a github PR review zone this morning.

components/motor/gpio/mathutils.go Show resolved Hide resolved
@martha-johnston martha-johnston changed the title Remove non-blocking GoFor functionality on 9/1 RSDK-7753: Remove non-blocking GoFor functionality on 9/1 Sep 11, 2024
@viambot viambot added safe to test This pull request is marked safe to test from a trusted zone and removed safe to test This pull request is marked safe to test from a trusted zone labels Sep 11, 2024
@viambot viambot added safe to test This pull request is marked safe to test from a trusted zone and removed safe to test This pull request is marked safe to test from a trusted zone labels Sep 12, 2024
@viambot viambot removed the safe to test This pull request is marked safe to test from a trusted zone label Sep 12, 2024
@viambot viambot added the safe to test This pull request is marked safe to test from a trusted zone label Sep 12, 2024
@martha-johnston
Copy link
Contributor Author

I added a new check for if the revolutions is 0, and I added a new helper for getting the direction to reduce repeated code. I think this covers a lot of the similar comments but I'll go through it again and let me know if there's more

Copy link
Member

@JohnN193 JohnN193 left a comment

Choose a reason for hiding this comment

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

kk still not the biggest fan of having math/codepaths within goForMaths that could potentially give invalid outputs, but it shouldn't be an issue that users hit.

maybe at a future date we could try unifying goForMath functions into a generic set of helpers? like adding a GoForMathDuration and GoForMathEncoded helpers, that way we won't need to change every function in drivers we support

@martha-johnston
Copy link
Contributor Author

kk still not the biggest fan of having math/codepaths within goForMaths that could potentially give invalid outputs, but it shouldn't be an issue that users hit.

I don't think it should be an issue because still the outputs aren't invalid, so if for some reason they are hit, it should just result in no movement

maybe at a future date we could try unifying goForMath functions into a generic set of helpers? like adding a GoForMathDuration and GoForMathEncoded helpers, that way we won't need to change every function in drivers we support

I agree that would be best, a lot have differences but I'm sure there's a way we could combine them. if that's something we're interested in seeing in this PR I can try and make it happen but it might just be a different ticket

@@ -1,15 +1,16 @@
package dimensionengineering_test
package dimensionengineering
Copy link
Member

Choose a reason for hiding this comment

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

This is actually a convention for making sure your test file is in a separate package which forces you to write good tests of the functionality of your exported APIs from that package. If you don't need any of the private functions in the dimensionengineering package to be tested now, please change it back.

https://stackoverflow.com/questions/19998250/proper-package-naming-for-testing-with-the-go-language/31443271#31443271

Comment on lines 211 to 220
// GetDirection returns the direction based on the rpm and revolutions
func GetDirection(rpm, revolutions float64) float64 {
dir := 1.0
if rpm*revolutions == 0.0 {
dir = 0.0
} else if rpm*revolutions < 0.0 {
dir = -1.0
}
return dir
}
Copy link
Member

Choose a reason for hiding this comment

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

Please rename this because GetDirection implies I'm getting the motor's direction as it is is moving, not getting the commanded Direction from the rpm and revolution requests.

@viambot viambot added safe to test This pull request is marked safe to test from a trusted zone and removed safe to test This pull request is marked safe to test from a trusted zone labels Sep 12, 2024
@viambot viambot added safe to test This pull request is marked safe to test from a trusted zone and removed safe to test This pull request is marked safe to test from a trusted zone labels Sep 12, 2024
Copy link
Member

@randhid randhid left a comment

Choose a reason for hiding this comment

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

LGTM now!

@viambot viambot added safe to test This pull request is marked safe to test from a trusted zone and removed safe to test This pull request is marked safe to test from a trusted zone labels Sep 12, 2024
@martha-johnston martha-johnston merged commit 40ab361 into viamrobotics:main Sep 12, 2024
19 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
safe to test This pull request is marked safe to test from a trusted zone
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants