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

680 class and velocity intermediate layer #684

Merged
merged 6 commits into from
Feb 5, 2025

Conversation

SirMDA
Copy link
Collaborator

@SirMDA SirMDA commented Feb 4, 2025

Description

Added class and velocity into intermediate layer inclusive visualization.

Fixes #680

Type of change

Please delete options that are not relevant.

  • New feature (non-breaking change which adds functionality)

Does this PR introduce a breaking change?

Nope

Most important changes

Visualization is working, merging is working for cars and non typed objects.

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works (might be obsolete with CI later on)
  • New and existing unit tests pass locally with my changes (might be obsolete with CI later on)

Summary by CodeRabbit

  • New Features

    • Updated visualization panels with refreshed marker displays for enhanced debugging and scene clarity.
    • Introduced varied marker styles and color schemes for improved differentiation of objects, including vehicles and pedestrians.
    • Enhanced entity detection from sensor data for more accurate and meaningful visual representations.
    • Added an option to show extra marker details, offering clearer insights during visualization.
  • Refactor

    • Consolidated marker generation logic, streamlining the display process for a more consistent visualization experience.

Copy link
Contributor

coderabbitai bot commented Feb 4, 2025

Walkthrough

The changes update multiple components including RViz configuration, mapping entities, filtering logic, shape representations, and visualization processing. RViz panels are restructured with new marker entries and updated view parameters. In the mapping module, the Entity class and its subclasses gain additional marker generation methods and revised color settings. A new MarkerStyle enum is introduced in the shape module to allow flexible rendering styles. The data integration node now distinguishes between Pedestrian and Car objects with updated velocity computations, and the visualization logic is refactored to consolidate marker creation using a new flag.

Changes

File(s) Change Summary
code/agent/config/rviz_config.rviz Updated RViz configuration: removed /MarkerArray1 and /PointCloud21, added /Intermediate Visualization and /ACC Debug entries; updated camera visibility and switched view from rviz/Orbit to rviz/ThirdPersonFollower with new parameters.
code/mapping/ext.../entity.py Enhanced Entity and subclasses: updated marker colors (gray→white, Car to blue, Pedestrian to red), added methods (get_meta_markers, to_motion_marker, get_text_marker), and modified shape debug marker handling.
code/mapping/ext.../filter.py Updated LaneIndexFilter method signature with an explicit type (Map), and made minor formatting adjustments in GrowthMergingFilter.
code/mapping/ext.../shape.py Introduced new MarkerStyle enum; updated to_marker methods in Shape2D, Rectangle, Circle, and Polygon to accept a marker_style parameter and implement advanced polygon rendering logic.
code/mapping/src/mapping_data_integration.py Modified entity creation logic: now distinguishes between Pedestrian (object_class 4) and Car (object_class 10), and revises velocity computation by adding the hero's speed.
code/mapping_visualization/src/visualization.py Refactored marker creation in map_callback: centralized marker generation using a new show_meta_markers flag and removed the redundant create_marker_from_entity method.

Sequence Diagram(s)

sequenceDiagram
    participant S as Sensor Data
    participant MDI as MappingDataIntegrationNode
    participant E as Entity (Car/Pedestrian)
    participant V as Visualization

    S->>MDI: Send clustered points with object_class
    MDI->>MDI: Determine entity type (Car, Pedestrian, or generic Entity)
    MDI->>E: Instantiate entity and compute velocity
    E->>V: Generate marker via to_marker & get_meta_markers
    V->>V: Consolidate markers based on show_meta_markers flag
    V->>Display: Publish marker array
Loading

Assessment against linked issues

Objective Addressed Explanation
Add velocity, class, and color-coded visualization in the intermediate layer [#680]

Suggested reviewers

  • SirMDA

Poem

In lines of code I joyfully bound,
With markers and colors all around.
I hop through panels, swift and keen,
Adding velocity and hues unseen.
A rabbit’s cheer for changes so sound! 🐇💻

Tip

🌐 Web search-backed reviews and chat
  • We have enabled web search-based reviews and chat for all users. This feature allows CodeRabbit to access the latest documentation and information on the web.
  • You can disable this feature by setting web_search: false in the knowledge_base settings.
  • Please share any feedback in the Discord discussion.
✨ Finishing Touches
  • 📝 Generate Docstrings (Beta)

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 generate docstrings to generate docstrings for this PR. (Beta)
  • @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.

@SirMDA SirMDA requested a review from Zelberor February 4, 2025 16:49
Copy link
Contributor

@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: 0

🧹 Nitpick comments (9)
code/mapping/src/mapping_data_integration.py (1)

331-366: Use enums or constants for object_class values and reduce duplication.
Hardcoding class identifiers (4 for Pedestrian, 10 for Car) makes the code harder to maintain. Consider using an enum-like structure for readability and future extensibility. Additionally, creating each entity type repeats many lines of configuration (e.g., shape, transform, timestamp, etc.). Refactoring into a small helper method or factory could reduce duplication.

code/mapping/launch/mapping.launch (1)

24-25: Ensure debug settings are not deployed to production.
Switching the node to debug_wrapper.py is helpful for local debugging. However, confirm that these debugging arguments (e.g., --debug_port) are disabled or removed in production environments to avoid exposing debug ports.

code/mapping_visualization/src/visualization.py (3)

12-12: Remove unused rospy import.
Static analysis indicates that rospy is never referenced. Deleting this unused import will keep the code clean.

- import rospy
🧰 Tools
🪛 Ruff (0.8.2)

12-12: rospy imported but unused

Remove unused import: rospy

(F401)


14-14: Remove unused Car and Pedestrian imports.
Currently, you don’t appear to differentiate these specific classes in this file. If you only need the generic Entity, removing the extra imports will simplify the code.

- from mapping_common.entity import Entity, Car, Pedestrian
+ from mapping_common.entity import Entity
🧰 Tools
🪛 Ruff (0.8.2)

14-14: mapping_common.entity.Entity imported but unused

Remove unused import

(F401)


14-14: mapping_common.entity.Car imported but unused

Remove unused import

(F401)


14-14: mapping_common.entity.Pedestrian imported but unused

Remove unused import

(F401)


16-16: Remove unused Point2 import.
Point2 is not used in this file. Removing it reduces clutter.

- from mapping_common.transform import Point2
🧰 Tools
🪛 Ruff (0.8.2)

16-16: mapping_common.transform.Point2 imported but unused

Remove unused import: mapping_common.transform.Point2

(F401)

code/mapping/ext_modules/mapping_common/filter.py (1)

10-10: Consider removing unused imports if not needed for type checking.

The imports Car and Pedestrian from .entity are currently unused in this file. If they're not needed for type checking, consider removing them.

-from .entity import ShapelyEntity, Entity, FlagFilter, Car, Pedestrian
+from .entity import ShapelyEntity, Entity, FlagFilter
🧰 Tools
🪛 Ruff (0.8.2)

10-10: .entity.Car imported but unused

Remove unused import

(F401)


10-10: .entity.Pedestrian imported but unused

Remove unused import

(F401)

code/mapping/ext_modules/mapping_common/shape.py (1)

267-286: Consider extracting magic numbers to named constants.

The marker configuration uses magic numbers for scale and dimensions. Consider extracting these to named constants for better maintainability.

+# At the top of the file
+LINE_THICKNESS = 0.05
+
 def to_marker(
     self,
     transform: Optional[Transform2D] = None,
     marker_style: MarkerStyle = MarkerStyle.CLOSED_OBJECT,
 ) -> Marker:
     m = super().to_marker(transform)
     if marker_style == MarkerStyle.LINESTRING:
         m.type = Marker.LINE_STRIP
-        m.scale.x = 0.05  # Line thickness
+        m.scale.x = LINE_THICKNESS
code/mapping/ext_modules/mapping_common/entity.py (2)

387-408: Consider adding validation for motion magnitude.

The motion marker generation could benefit from validation of the motion vector magnitude to avoid creating arrows for negligible motion.

 def to_motion_marker(self) -> Marker:
     assert self.motion is not None
+    # Skip arrows for negligible motion
+    if self.motion.linear_motion.length() < 0.1:  # m/s
+        return None
     m = Marker()
     m.type = Marker.ARROW

553-559: Consider extracting color values to constants.

The marker colors for Car and Pedestrian classes use magic numbers. Consider extracting these to named constants for better maintainability.

+# At the top of the file
+CAR_COLOR = (0, 0, 255)  # RGB
+PEDESTRIAN_COLOR = (220, 20, 60)  # RGB
+
 class Car(Entity):
     def to_marker(self) -> Marker:
         m = super().to_marker()
-        # [0, 0, 255],  # 10: Vehicles
-        m.color.r = 0
-        m.color.g = 0
-        m.color.b = 255 / 255
+        m.color.r = CAR_COLOR[0] / 255
+        m.color.g = CAR_COLOR[1] / 255
+        m.color.b = CAR_COLOR[2] / 255

Also applies to: 665-671

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c017650 and e84dcad.

📒 Files selected for processing (7)
  • code/agent/config/rviz_config.rviz (6 hunks)
  • code/mapping/ext_modules/mapping_common/entity.py (7 hunks)
  • code/mapping/ext_modules/mapping_common/filter.py (2 hunks)
  • code/mapping/ext_modules/mapping_common/shape.py (6 hunks)
  • code/mapping/launch/mapping.launch (1 hunks)
  • code/mapping/src/mapping_data_integration.py (3 hunks)
  • code/mapping_visualization/src/visualization.py (3 hunks)
🧰 Additional context used
🪛 Ruff (0.8.2)
code/mapping_visualization/src/visualization.py

12-12: rospy imported but unused

Remove unused import: rospy

(F401)


14-14: mapping_common.entity.Entity imported but unused

Remove unused import

(F401)


14-14: mapping_common.entity.Car imported but unused

Remove unused import

(F401)


14-14: mapping_common.entity.Pedestrian imported but unused

Remove unused import

(F401)


16-16: mapping_common.transform.Point2 imported but unused

Remove unused import: mapping_common.transform.Point2

(F401)

code/mapping/ext_modules/mapping_common/filter.py

10-10: .entity.Car imported but unused

Remove unused import

(F401)


10-10: .entity.Pedestrian imported but unused

Remove unused import

(F401)

⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Build and push image
🔇 Additional comments (10)
code/mapping/src/mapping_data_integration.py (3)

12-12: Imports look correct and complete.
All imported classes and functions (Entity, Flags, Car, Motion2D, Pedestrian) appear to be used throughout this file, so there’s no immediate concern about unused imports. Good job!


281-283: Verify array length consistency.
When de-referencing objectclassarray[indexarray == label][0], ensure that objectclassarray and indexarray always match in length and indexes. If there's a mismatch or empty slice, an index out-of-bounds error could occur.


327-328: Confirm the updated motion logic.
Adding the hero speed to the cluster’s motion vector may alter your object-tracking behavior. Verify that this correctly reflects your intended relative or absolute motion modeling.

code/mapping_visualization/src/visualization.py (2)

39-39: Good use of a configurable toggle for meta markers.
Introducing self.show_meta_markers facilitates flexible visualization. Nicely done!


60-75: Marker creation flow looks solid.
Using a single loop to invoke to_marker() and optional meta markers is straightforward and readable. Great job!

code/agent/config/rviz_config.rviz (3)

7-8: LGTM! Display configuration updated for new visualization features.

The display configuration has been updated to show intermediate visualization and ACC debug markers, which aligns with the new visualization capabilities.


109-110: Verify if disabling Lidar visualization is intentional.

The Lidar visualization has been disabled. While this may reduce visual clutter, it could impact debugging capabilities.

Please confirm if disabling the Lidar visualization was intentional and won't impact debugging workflows.

Also applies to: 124-124


220-221: LGTM! Camera view settings optimized.

The camera view has been changed to ThirdPersonFollower with adjusted pitch and yaw settings, which should provide better visualization of the scene.

Also applies to: 237-239

code/mapping/ext_modules/mapping_common/shape.py (1)

20-24: LGTM! Well-structured enum for marker styles.

The MarkerStyle enum provides a clean abstraction for different marker visualization styles.

code/mapping/ext_modules/mapping_common/entity.py (1)

372-385: LGTM! Well-implemented meta marker generation.

The get_meta_markers method provides a clean way to generate additional visualization elements, including motion indicators and speed information.

Copy link
Collaborator

@Ralf524 Ralf524 left a comment

Choose a reason for hiding this comment

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

Remember to remove the debugger and any unused imports. The visualization looks great

Copy link
Contributor

@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: 0

🧹 Nitpick comments (1)
code/mapping/ext_modules/mapping_common/filter.py (1)

49-49: Add type annotations to the filter method.

For consistency with the base class and improved type safety, add type annotations to the method signature.

-    def filter(self, map):
+    def filter(self, map: Map) -> Map:
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e84dcad and 90082cd.

📒 Files selected for processing (2)
  • code/mapping/ext_modules/mapping_common/filter.py (1 hunks)
  • code/mapping_visualization/src/visualization.py (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • code/mapping_visualization/src/visualization.py
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Build and push image
🔇 Additional comments (3)
code/mapping/ext_modules/mapping_common/filter.py (3)

220-225: LGTM! Code simplification without functional changes.

The removal of explicit type annotations makes the code cleaner while maintaining the same functionality.


183-343: Consider adding unit tests for geometric edge cases.

The helper functions handle complex geometry operations with proper error handling. To ensure robustness, consider adding unit tests for edge cases such as:

  • Invalid polygons
  • Single point polygons after growing/shrinking
  • Counter-clockwise vs clockwise polygon orientations

Would you like me to help generate comprehensive unit tests for these edge cases?


229-239: Verify velocity handling in entity merging.

The code handles merging of various entity attributes but doesn't explicitly handle velocity. Given that this PR adds velocity functionality, consider how velocity should be handled during entity merging.

Let's check if velocity handling is implemented elsewhere:

@Ralf524 Ralf524 merged commit f8650b2 into main Feb 5, 2025
4 checks passed
@asamluka asamluka deleted the 680-class-and-velocity-intermediate-layer branch February 10, 2025 16:16
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.

[Feature]: Add class and velocity of object into intermediate layer and visualize
2 participants