Conversation
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request significantly enhances the robot simulator by introducing realistic bump physics. It allows the robot to interact with simulated terrain features, calculating changes in its 3D pose (pitch, roll, and Z-height) as it traverses bumps. This improvement provides a more accurate and immersive simulation environment for testing robot behavior. Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request introduces a new bump physics simulation feature, including the BumpPhysicsSim class to calculate the robot's 3D pose (height, pitch, and roll) based on terrain interaction, FieldConstants for defining field dimensions and bump regions, and SimAllianceUtils for alliance-specific mirroring in simulation. The Robot class now updates a terrainPose using this simulation, and RobotSim initializes and publishes the simulated pose. Feedback highlights a critical issue where terrainPose is used before being updated, potentially causing a NullPointerException, and a hardcoded delta time. Additionally, there are design concerns regarding the use of public static fields for terrainPose and bumpSim, which create tight coupling, and a suggestion to refactor a repeated calculation in BumpPhysicsSim into a constant in FieldConstants for improved clarity and performance.
|
/gemini review |
|
Warning Gemini encountered an error creating the review. You can try again by commenting |
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request introduces a new bump physics simulation feature, including BumpPhysicsSim, FieldSimConstants, and SimAllianceUtils to model robot movement over uneven terrain. The Robot and RobotSim classes are updated to integrate this simulation. Feedback indicates that the terrainPose in RobotSim is currently only calculated once and needs to be updated periodically within the updateSimulation() method for the simulation to function correctly. Additionally, an unused static Pose3d terrainPose field in the Robot class should be removed to avoid confusion, and several local variables in BumpPhysicsSim should be refactored to follow Java's camelCase naming conventions.
| } | ||
|
|
||
| /** Applies a flip without depending on the current alliance. */ | ||
| public static <T> T mirror(UnaryOperator<T> flipFunction, T blueValue) { |
There was a problem hiding this comment.
The use of a static boolean override state is thread-unsafe. While much of WPILib is single-threaded, if mirror() is called by a background thread (e.g., path loading, network tables update, or logging) at the same time another thread calls an apply() method, the shouldFlip() condition could read a corrupted or unintended state instead of the current alliance. This would lead to unpredictable mirror coordinate inversions.
Recommendation: Avoid static global state for overrides. Instead, pass the override state explicitly down the call stack as a parameter, or use a ThreadLocal if you cannot easily modify the method signatures that UnaryOperator operates on.
public class SimAllianceUtils {
- private static boolean override;
+ private static final ThreadLocal<Boolean> override = ThreadLocal.withInitial(() -> false);
private SimAllianceUtils() {}
private static boolean shouldFlip() {
- return AllianceUtils.isRed() || override;
+ return AllianceUtils.isRed() || override.get();
}
/** Applies a flip without depending on the current alliance. */
public static <T> T mirror(UnaryOperator<T> flipFunction, T blueValue) {
+ boolean previous = override.get();
try {
- override = true;
+ override.set(true);
return flipFunction.apply(blueValue);
} finally {
- override = false;
+ override.set(previous);
}
}
There is now a bump physics class based on team 503's Bump Physics: (https://github.com/githubAnish/robot-2026-rewrite/blob/main/src/main/java/org/frogforce503/lib/rebuilt/BumpPhysicsSim.java)
Probably could be made more efficient and might need some clean up.