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

Fix walking python bindings #596

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open

Fix walking python bindings #596

wants to merge 7 commits into from

Conversation

Flova
Copy link
Member

@Flova Flova commented Sep 25, 2024

The migration of the walking to the generate_parameter_library required a significant rework of the way parameters are set when the Python walk wrapper is used. Coincidentally the new approach simplifies the logic a bit, which is nice I guess.

I also added a few longer comments explaining the reasoning behind some design choices.

@Flova Flova added bug Something isn't working motion labels Sep 25, 2024
@Flova Flova self-assigned this Sep 25, 2024
The migration to gen_param_lib broke the way params are loaded when we use the pywrapper, this fixes it.
@Flova Flova changed the title Fix incorrect type hint in py walk bindings Fix walking python bindings Sep 25, 2024
@Flova
Copy link
Member Author

Flova commented Sep 25, 2024

@coderabbitai review

Copy link

coderabbitai bot commented Sep 25, 2024

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 3

🧹 Outside diff range and nitpick comments (4)
bitbots_motion/bitbots_quintic_walk/bitbots_quintic_walk_py/py_walk.py (3)

16-33: LGTM: Improved parameter handling and type safety.

The changes to the constructor are well-implemented:

  1. Separating walk_parameters and moveit_parameters allows for more granular control.
  2. The use of Optional[list[Parameter]] improves type safety.
  3. The serialize_parameters function elegantly handles parameter serialization.

Consider adding type hints to the serialize_parameters function for consistency:

def serialize_parameters(parameters: Optional[list[Parameter]]) -> list:
    if parameters is None:
        return []
    return list(map(serialize_message, parameters))

116-117: LGTM: Improved type safety with return type annotation.

The addition of the -> Phase return type annotation to the get_support_state method enhances code clarity and type safety.

Consider adding a type hint to the deserialize_message call for extra clarity:

return deserialize_message(self.py_walk_wrapper.get_support_state(), Phase)  # type: ignore

This helps silence potential type checker warnings about the deserialize_message function.


122-128: LGTM: Improved type safety with return type annotations.

The addition of return type annotations to both get_odom (-> Odometry) and publish_debug (-> None) methods enhances code clarity and type safety.

For the get_odom method, consider adding a type hint to the deserialize_message call for extra clarity:

result = deserialize_message(odom, Odometry)  # type: ignore

This helps silence potential type checker warnings about the deserialize_message function.

bitbots_motion/bitbots_quintic_walk/src/walk_pywrapper.cpp (1)

31-31: Rephrase comment to maintain professional tone

The comment on line 31 uses informal language ("does some bullshit"), which may be considered unprofessional. Consider rephrasing it to maintain a professional tone.

Apply this diff to rephrase the comment:

-  // reconfigure does not work, because moveit does some bullshit with their parameter declarations leading dynamic
+  // reconfigure does not work because MoveIt uses parameter declarations that interfere with dynamic
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 8c5fb4e and 38f538e.

📒 Files selected for processing (5)
  • bitbots_motion/bitbots_quintic_walk/bitbots_quintic_walk_py/py_walk.py (3 hunks)
  • bitbots_motion/bitbots_quintic_walk/include/bitbots_quintic_walk/walk_node.hpp (1 hunks)
  • bitbots_motion/bitbots_quintic_walk/include/bitbots_quintic_walk/walk_pywrapper.hpp (1 hunks)
  • bitbots_motion/bitbots_quintic_walk/src/walk_node.cpp (1 hunks)
  • bitbots_motion/bitbots_quintic_walk/src/walk_pywrapper.cpp (2 hunks)
🔇 Additional comments not posted (8)
bitbots_motion/bitbots_quintic_walk/include/bitbots_quintic_walk/walk_pywrapper.hpp (1)

26-27: Constructor signature update enhances flexibility but may require code updates

The changes to the PyWalkWrapper constructor are well-aligned with the PR objectives. The addition of moveit_parameter_msgs and the renaming of parameter_msgs to walk_parameter_msgs improve clarity and extend functionality. However, there are a few points to consider:

  1. Existing code explicitly passing parameter_msgs may need updates to use walk_parameter_msgs instead.
  2. The purpose and format of moveit_parameter_msgs should be documented, preferably with a comment above the constructor.
  3. Ensure that the corresponding implementation file (*.cpp) properly handles the new moveit_parameter_msgs.

To verify the impact of these changes, please run the following script:

✅ Verification successful

PyWalkWrapper constructor changes are correctly implemented and verified

The updates to the PyWalkWrapper constructor have been thoroughly verified:

  1. The new moveit_parameter_msgs parameter is properly handled in walk_pywrapper.cpp through deserialize_parameters(moveit_parameter_msgs).
  2. Default values for both walk_parameter_msgs and moveit_parameter_msgs maintain backward compatibility, ensuring existing code remains functional without modifications.
  3. No conflicting usages of the old parameter_msgs parameter were detected, mitigating potential integration issues.

No further actions are required.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for existing usages of the PyWalkWrapper constructor and potential impacts

# Search for PyWalkWrapper constructor calls
echo "Searching for PyWalkWrapper constructor calls:"
rg --type cpp "PyWalkWrapper\s*\(" -A 3

# Check if there's a corresponding cpp file for walk_pywrapper.hpp
echo "Checking for corresponding cpp file:"
fd -e cpp walk_pywrapper

# If cpp file exists, check if it handles moveit_parameter_msgs
if [ $? -eq 0 ]; then
  echo "Checking if cpp file handles moveit_parameter_msgs:"
  rg --type cpp "moveit_parameter_msgs" $(fd -e cpp walk_pywrapper)
fi

Length of output: 2062

bitbots_motion/bitbots_quintic_walk/bitbots_quintic_walk_py/py_walk.py (5)

1-1: LGTM: Good addition of type hinting support.

The import of Optional from the typing module is a positive change. It indicates that type hinting will be used in the code, which enhances code readability and helps catch potential type-related issues early in development.


110-111: LGTM: Improved type safety with return type annotation.

The addition of the -> float return type annotation to the get_phase method enhances code clarity and type safety. This change is consistent with modern Python best practices.


113-114: LGTM: Enhanced type safety with return type annotation.

The addition of the -> float return type annotation to the get_freq method improves code clarity and type safety, aligning with modern Python coding standards.


119-120: LGTM: Enhanced type safety with boolean return type annotation.

The addition of the -> bool return type annotation to the is_left_support method improves code clarity and type safety, consistent with modern Python best practices.


Line range hint 1-138: Overall assessment: Significant improvements in type safety and parameter handling.

The changes made to this file align well with the PR objectives and enhance the overall quality of the code:

  1. The constructor modifications allow for more granular control over input parameters.
  2. The addition of return type annotations throughout the class improves type safety and code clarity.
  3. The new serialize_parameters function provides a clean way to handle parameter serialization.

These changes contribute to better maintainability and readability of the codebase. The migration to generate_parameter_library has been handled effectively, simplifying the underlying logic as mentioned in the PR objectives.

bitbots_motion/bitbots_quintic_walk/include/bitbots_quintic_walk/walk_node.hpp (1)

57-57: Verify the impact of the constructor parameter rename.

The constructor parameter has been renamed from parameters to moveit_parameters, which suggests a more specific use related to MoveIt. This change, combined with the removal of the onSetParameters method, indicates a shift in how parameters are handled in the WalkNode class.

To ensure this change doesn't introduce any issues, please run the following script to check for any remaining uses of the old parameter name:

Also, verify that all calls to the WalkNode constructor have been updated accordingly.

bitbots_motion/bitbots_quintic_walk/src/walk_node.cpp (1)

26-29: Verify that parameter overrides do not introduce unintended parameters

Using automatically_declare_parameters_from_overrides(true) with parameter_overrides in NodeOptions may cause all parameters in moveit_parameters to be automatically declared in the node's namespace. This could lead to conflicts or unintended behavior if parameter names overlap or are not correctly namespaced. Ensure that the parameters are uniquely named and properly scoped.

Run the following script to check for parameter name conflicts within the codebase:

This script searches for all instances where parameters are declared and lists any duplicates. If any duplicate parameter names are found, consider renaming them or adjusting their namespaces to prevent conflicts.

✅ Verification successful

Verification Successful: No Unintended Parameter Conflicts Detected

All parameter overrides are uniquely named and properly scoped. No duplicate parameter declarations were found, ensuring that automatically_declare_parameters_from_overrides(true) does not introduce unintended parameters.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for duplicate parameter names across all parameter declarations.

# Expected: No duplicate parameter names should be found.

# List all parameter names declared in the codebase
rg --type cpp --no-heading --line-number 'declare_parameter\("([^"]+)"' -o -r '$1' | sort | uniq -d

Length of output: 101


Script:

#!/bin/bash
# Description: Extract all parameters from moveit_parameters and check for uniqueness and proper namespacing.

# Extracting parameter names from moveit_parameters
rg --type cpp 'parameter_overrides\s*\(\s*[^)]*' -A 5 | \
grep -oP '"\K[^"]+(?=")' | sort | uniq -c | sort -nr

# Additionally, list all parameters declared in the node's namespace to check for conflicts
rg --type cpp 'declare_parameter\("([^"]+)"' -o -r '$1' | sort | uniq -d

Length of output: 291

@bit-bots bit-bots deleted a comment from coderabbitai bot Sep 25, 2024
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Copy link

coderabbitai bot commented Sep 26, 2024

Warning

Rate limit exceeded

@Flova has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 16 minutes and 49 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Files that changed from the base of the PR and between e3159a6 and 3d2c30b.

Walkthrough

The pull request introduces modifications to the PyWalk, WalkNode, and PyWalkWrapper classes within the bitbots_quintic_walk package. Key changes include the addition of new optional parameters for handling walk and MoveIt parameters, updates to method signatures with explicit return type annotations, and a reorganization of parameter handling logic in the constructors. The onSetParameters method has been removed from WalkNode, and new internal functions have been introduced for parameter serialization and deserialization.

Changes

Files Change Summary
bitbots_motion/bitbots_quintic_walk/.../py_walk.py Updated PyWalk constructor to accept walk_parameters and moveit_parameters. Added serialize_parameters function. Explicit return type annotations added to several methods.
bitbots_motion/bitbots_quintic_walk/.../walk_node.hpp Modified WalkNode constructor to replace parameters with moveit_parameters. Removed onSetParameters method.
bitbots_motion/bitbots_quintic_walk/.../walk_node.cpp Updated WalkNode constructor to handle moveit_parameters. Simplified parameter handling logic.
bitbots_motion/bitbots_quintic_walk/.../walk_pywrapper.hpp Modified PyWalkWrapper constructor to include moveit_parameter_msgs.
bitbots_motion/bitbots_quintic_walk/.../walk_pywrapper.cpp Updated PyWalkWrapper constructor to accept moveit_parameter_msgs. Introduced deserialize_parameters function for processing parameter messages. Updated binding in PYBIND11_MODULE.

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Flova and others added 2 commits September 26, 2024 14:48
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working motion
Projects
Status: 👀 In review
Development

Successfully merging this pull request may close these issues.

1 participant