Skip to content

added physics for bump#154

Open
SnappleRamen wants to merge 5 commits intomainfrom
BumpPhysics
Open

added physics for bump#154
SnappleRamen wants to merge 5 commits intomainfrom
BumpPhysics

Conversation

@SnappleRamen
Copy link
Copy Markdown
Contributor

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.

@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, 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

  • Bump Physics Simulation: Introduced a new BumpPhysicsSim class to model robot interaction with terrain bumps, adapted from Team 503's implementation.
  • Simulation Integration: Integrated the bump physics simulation into the main Robot class's simulationPeriodic method, updating the robot's terrainPose based on bump interactions.
  • Field Definitions: Added FieldConstants to define key field dimensions and the geometry of the field bumps.
  • Alliance Utility: Included SimAllianceUtils to provide utilities for mirroring field elements based on the current alliance, crucial for accurate simulation across different alliances.
  • NetworkTables Publishing: Enhanced RobotSim to initialize the BumpPhysicsSim and publish the simulated terrainPose to NetworkTables for visualization.
Using Gemini Code Assist

The 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 /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

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

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

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.

Comment thread src/main/java/frc/robot/Robot.java Outdated
Comment thread src/main/java/frc/robot/Robot.java Outdated
Comment thread src/main/java/frc/robot/util/simulation/BumpPhysicsSim.java Outdated
Comment thread src/main/java/frc/robot/util/simulation/RobotSim.java Outdated
@SnappleRamen
Copy link
Copy Markdown
Contributor Author

/gemini review

@gemini-code-assist
Copy link
Copy Markdown
Contributor

Warning

Gemini encountered an error creating the review. You can try again by commenting /gemini review.

@koolpoolo
Copy link
Copy Markdown
Contributor

/gemini review

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

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.

Comment thread src/main/java/frc/robot/util/simulation/RobotSim.java Outdated
Comment thread src/main/java/frc/robot/Robot.java Outdated
Comment thread src/main/java/frc/robot/util/simulation/BumpPhysicsSim.java
}

/** Applies a flip without depending on the current alliance. */
public static <T> T mirror(UnaryOperator<T> flipFunction, T blueValue) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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);
      }
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants