Miscellaneous Changes - #5
Conversation
vdikov
left a comment
There was a problem hiding this comment.
Thanks @cuttestkittensrule ,
Really nice touches here. I have added a few comments.
I like how the PR is organized in meaningful, chunk-size, self-explanatory commits. What I was wondering is how you can address my comments without corrupting this commits organization. Could you just "amend" the commits when addressing my comments, so these commits keep the same logical chunk-size structure and are addressing my comments? I believe you could just git commit --amend against the individual commits, but haven't used it myself yet.
| module.periodic(); | ||
| } | ||
| } finally { | ||
| odometryLock.unlock(); |
There was a problem hiding this comment.
It would be a good idea to propose this change upstream (as well):
I'd be curious to see if the Mechanical Advantage team engages in an useful discussion when you do so. I'm wondering if they might have some reasons to believe this might not be needed.
| boolean isFlipped = | ||
| DriverStation.getAlliance().isPresent() | ||
| && DriverStation.getAlliance().get() == Alliance.Red; | ||
| DriverStation.getAlliance().map((alliance) -> alliance == Alliance.Red).orElse(false); |
There was a problem hiding this comment.
Oh, interesting catch.
Please add a comment in the code as well that calling DriverStation.getAlliance() more than once should be avoided (I.e., add the commit comment as a code comment so that code readers can see it, even when they don't review commits history).
Also, this could be even simpler (and avoid the Optional.map(...) syntax, which could be a bit confusing for novice Java readers):
// Note: we must avoid expressions that call DriverStation.getAlliance() more than once
// since its return value can change any time, including mid-expression evaluation, and
// that could lead to run-time errors.
boolean isFlipped = DriverStation.getAlliance().orElse(Alliance.Blue) == Alliance.Red;
There was a problem hiding this comment.
This is likely not necessary, as if the robot is not connected to FMS, it will use the alliance from the driverstation.
| // See https://www.chiefdelphi.com/t/driverstation-getalliance-in-gradle-test/ | ||
| if (!HAL.initialize(500, 0)) { | ||
| throw new IllegalStateException("Could not initialize Hardware Abstraction Layer"); | ||
| } | ||
| DriverStationSim.setEnabled(true); | ||
| DriverStationSim.notifyNewData(); | ||
| SimHooks.setHALRuntimeType(RuntimeType.kSimulation.value); | ||
|
|
||
| CommandScheduler commandScheduler = CommandScheduler.getInstance(); | ||
| commandScheduler.enable(); | ||
| commandScheduler.cancelAll(); | ||
| commandScheduler.unregisterAllSubsystems(); |
There was a problem hiding this comment.
This set of operations looks non-trivial to me. How did we come up with it?
Were we referring to a unit-test guide for WPILib code somewhere?
I see bits and pieces of this routine might be coming from https://www.chiefdelphi.com/t/driverstation-getalliance-in-gradle-test/ . If that's the case, elaborate a bit more in the comment.
Ie, instead of just // See https://www.chie..., you can say something like // Initialization based on https://www.chiefdelphi.com/t/driverstation-getalliance-in-gradle-test/
There was a problem hiding this comment.
This is copied from lib2813. I would have used it straight from lib2813, but we are going to use so little of it anyways that it isn't really worth it. We can probably just use the lib2813 version when we put it on maven central
There was a problem hiding this comment.
Gotcha. So leave a comment like "Code forked from testing/src/main/java/com/team2813/lib2813/testing/junit/jupiter/WPILibExtension.java")
Otherwise, this code appears miraculously in the current repo with no prior logs or reference on how it came to be, and what was it designed to solve in the first place.
There was a problem hiding this comment.
Is this where the TOCTOU vulnerability is fixed?
There was a problem hiding this comment.
Also please add some comments to these.
There was a problem hiding this comment.
@spderman3333 The TOCTOU error is fixed in the commit "Prevent TOCTOU error". This set of changes is part of some backend stuff from lib2813 for testing, which I opted to copy over instead of adding the lib2813 submodule just for two files related to testing. I could add some comments, but I don't think it will be super useful since we are likely going to delete these files soon.
There was a problem hiding this comment.
@vdikov updated this comment in the lib2813 version of this file in Prospect-Robotics/lib2813#121. Requested a review from you.
|
@vdikov You can only |
Makes sure it is canceled if something other than teleop is started, so nothing weird happens
TOCTOU -> time of check/time of use. The Driver station alliance could theorhetically change from having an alliance to not having an alliance in between the DriverStation#getAlliance() call, especially with JNI being involved, and could throw an exception. To prevent this, it is called only once, and then converted to the information on if it should be flipped. You could change this to be the same as before, but with storing the driver station alliance in a variable, and it would work.
…a periodic cycle without crashing
f9863a7 to
54991b8
Compare
| boolean isFlipped = | ||
| DriverStation.getAlliance().isPresent() | ||
| && DriverStation.getAlliance().get() == Alliance.Red; | ||
| DriverStation.getAlliance().map((alliance) -> alliance == Alliance.Red).orElse(false); |
There was a problem hiding this comment.
This is likely not necessary, as if the robot is not connected to FMS, it will use the alliance from the driverstation.
There was a problem hiding this comment.
This is an unnecessary change, and just makes the code slightly harder to read.
I'd argue that lambdas are more readable than method references.
There was a problem hiding this comment.
I can change the method references back to lambdas if you want me to, but we definitely need to make the InstantCommands depend on the Intake subsystem, since they didn't do that before
| @Override | ||
| public void autonomousPeriodic() {} | ||
|
|
||
| /** This function is called once when teleop is enabled. */ |
There was a problem hiding this comment.
Is it necessary to remove the comment here? It doesn't really harm the readability of the file.
There was a problem hiding this comment.
This comment wasn't removed, it still exists where the teleopInit functon is. As for why this comment isn't in front of autonomousExit(), it is because it would be inaccurate for autonomousExit().
If you enable git commit --fixup=[sha1 of commit to amend]
git rebase -i mainDetails here (well worth a read; I didn't know about the Rebasing now might make it harder for reviewers to see the changes that were made in response to comments, so it might be better to do the side-note: rebasing is usually fine on branches you own, but rebasing shared branches can cause problems. |
Got it. Probably not worth it to overcomplicate it then. I was hoping it would be much more like If we could somehow switch to Jujutsu which I imagine handles this better, and end up with a simpler playbook for the students, that might be the path forward. I have personally not tried Jujutsu yet, so I'm just speculating this would looks simpler with it. |
|
@cuttestkittensrule , what's the status of this PR? Are there any blocking / fundamentally unresolvable comments left? If it looks like there's just little / trivial amount of work left, please consider pushing through and merging it. FWIW, I see that this PR is improving things and it would be a shame to let it go to waste. Also, I just want to point out that by now we have multiple people spending time on it - you putting it together, in the first place, but also three reviewers who went through review it. Reviewing a PR is non-trivial work. It would be gratifying to all of us to see it merge :) And conversely, if there's something unsurmountable preventing us from landing it - please bring it up. Understanding what it is, learning from it - that's going to be also a win and a good return of everyone's invested time. Just let's not leave it rot or go to waste. |
|
I think @vdikov should re-review this too, but it could be merged. |
Add a handful of improvements. The commit names pretty much explain what they do. Here is a short list of changes:
gradlewscript executableautonomousExitRobotContainerand running a single periodic run don't throw an exception.Generally, the commits are very small and removed from each other, so if we don't want to implement one of these changes, we can just revert it :)