-
Notifications
You must be signed in to change notification settings - Fork 110
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
RSDK-7753: Remove non-blocking GoFor functionality on 9/1 #4335
Conversation
Warning your change may break code samples. If your change modifies any of the following functions please contact @viamrobotics/fleet-management. Thanks!
|
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.
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.
fc73392
to
45e8019
Compare
@@ -1,15 +1,16 @@ | |||
package dimensionengineering_test | |||
package dimensionengineering |
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.
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.
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 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.
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.
Sure I can revert this and remove the goForMath tests if you'd prefer
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.
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.
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.
sorry I missed this before changing it, but I added GoFor tests so I think it should be fine now
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.
Even better!
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.
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
if rpm*revolutions == 0.0 { | ||
dir = 0.0 |
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.
not familiar with this motor, but is it okay for the GoFor call to not do anything?
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.
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?
return powerPct, 0 | ||
dir := 1.0 | ||
if rpm*revolutions == 0.0 { | ||
dir = 0.0 |
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.
similar recommendation, we can return early here, especially because the logic below breaks when rpm == 0
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.
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.
components/motor/fake/motor.go
Outdated
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 |
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.
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.
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 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.
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 |
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.
kk still not the biggest fan of having math/codepaths within goForMath
s 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
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
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 |
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 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.
components/motor/motor.go
Outdated
// 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 | ||
} |
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.
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.
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.
LGTM now!
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.