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

466 add radar sensor #522

Merged
merged 8 commits into from
Nov 24, 2024
Merged

466 add radar sensor #522

merged 8 commits into from
Nov 24, 2024

Conversation

Ralf524
Copy link
Collaborator

@Ralf524 Ralf524 commented Nov 24, 2024

Description

Added simple radar node and md file for documentation of radar sensor

Fixes # (466)

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?

No

Most important changes

radar node, md file

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

    • Introduced a new radar node for enhanced perception capabilities, processing radar data alongside existing sensors.
    • Added functionality for real-time distance measurement from radar data.
  • Documentation

    • Created a comprehensive guide for the radar node, including technical specifications, functionality, and future development plans.

@Ralf524 Ralf524 linked an issue Nov 24, 2024 that may be closed by this pull request
Copy link
Contributor

coderabbitai bot commented Nov 24, 2024

Walkthrough

The changes introduce a new radar node to the perception module's launch file and implement the corresponding processing class in a new Python file. The perception.launch file now includes a configuration for the radar_node.py, which processes radar data and publishes velocity information. Additionally, documentation detailing the radar sensor's functionality, specifications, and data outputs has been added.

Changes

File Change Summary
code/perception/launch/perception.launch Added a new <node> element for radar_node.py to process radar data with specified topics.
code/perception/src/radar_node.py Introduced RadarNode class with methods for processing PointCloud2 messages and publishing velocity.
doc/perception/radar_node.md Created documentation outlining radar sensor functionality, specifications, and data outputs.

Poem

In the meadow where sensors play,
A radar node joins the fray. 🌼
With data it gathers, swift and bright,
It shares its findings, a wondrous sight!
Hopping along, we cheer with glee,
For every point it brings to thee! 🐇✨


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between a8a585e and 9039a1f.

📒 Files selected for processing (1)
  • code/perception/launch/perception.launch (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • code/perception/launch/perception.launch

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.

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

🧹 Outside diff range and nitpick comments (3)
code/perception/src/radar_node.py (1)

1-64: Consider enhancing radar data processing capabilities

The current implementation only publishes minimum velocity, which might be limiting. Consider:

  1. Adding configuration options for velocity processing (min, max, average)
  2. Publishing additional radar data fields that might be useful for perception
  3. Adding filtering capabilities for noise reduction
  4. Including radar object detection and tracking functionality

This would make the radar node more versatile and useful for various perception tasks.

Would you like assistance in implementing any of these enhancements?

🧰 Tools
🪛 Ruff (0.7.0)

5-5: lidar_filter_utility imported but unused

Remove unused import: lidar_filter_utility

(F401)


10-10: sensor_msgs.msg.Image imported but unused

Remove unused import: sensor_msgs.msg.Image

(F401)

code/perception/launch/perception.launch (2)

83-86: Consider adding parameter documentation.

Consider adding inline documentation for the radar node parameters, similar to other nodes in this file (e.g., the vision node's model parameter documentation).

Add documentation like this:

  <node pkg="perception" type="radar_node.py" name="radar_node" output="screen">
+    <!-- 
+      point_cloud_topic: Topic for filtered RADAR PointCloud2 data
+      range_topic: Topic for processed RADAR range measurements
+    -->
    <param name="point_cloud_topic" value="/carla/hero/RADAR_filtered"/>
    <param name="range_topic" value="/carla/hero/RADAR_range"/>
  </node>

83-86: Consider adding control loop rate parameter.

Other perception nodes (kalman_filter, position_heading_publisher) include a control loop rate parameter. Consider whether the radar node would benefit from similar rate control.

Example addition:

  <node pkg="perception" type="radar_node.py" name="radar_node" output="screen">
+    <param name="control_loop_rate" value="$(arg control_loop_rate)" />
    <param name="point_cloud_topic" value="/carla/hero/RADAR_filtered"/>
    <param name="range_topic" value="/carla/hero/RADAR_range"/>
  </node>
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 662e3ab and ae01b8d.

📒 Files selected for processing (3)
  • code/perception/launch/perception.launch (1 hunks)
  • code/perception/src/radar_node.py (1 hunks)
  • doc/perception/radar_node.md (1 hunks)
🧰 Additional context used
🪛 Ruff (0.7.0)
code/perception/src/radar_node.py

5-5: lidar_filter_utility imported but unused

Remove unused import: lidar_filter_utility

(F401)


10-10: sensor_msgs.msg.Image imported but unused

Remove unused import: sensor_msgs.msg.Image

(F401)

🪛 LanguageTool
doc/perception/radar_node.md

[grammar] ~8-~8: It appears that a hyphen is missing in the noun “To-do” (= task) or did you mean the verb “to do”?
Context: ...data-output-for-each-detected-point) - Todo ## Radar offsets - x: 2 - y: ...

(TO_DO_HYPHEN)


[grammar] ~33-~33: It appears that a hyphen is missing in the noun “To-do” (= task) or did you mean the verb “to do”?
Context: ...ity - AzimuthAngle - ElevationAngle ## Todo - Discuss further processing of radar ...

(TO_DO_HYPHEN)

🔇 Additional comments (1)
code/perception/launch/perception.launch (1)

83-86: LGTM! Node configuration follows established patterns.

The radar node configuration is well-structured and follows the same pattern as the existing lidar node, maintaining consistency in the codebase.

Comment on lines 18 to 21
class RadarNode:
"""See doc/perception/lidar_distance_utility.md on
how to configute this node
"""
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Fix documentation reference and typo

The class documentation references an incorrect markdown file and contains a typo:

  1. References "lidar_distance_utility.md" instead of the radar documentation
  2. "configute" should be "configure"

Apply this diff:

class RadarNode:
-    """See doc/perception/lidar_distance_utility.md on
-    how to configute this node
+    """See doc/perception/radar_node.md on
+    how to configure this node
    """
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
class RadarNode:
"""See doc/perception/lidar_distance_utility.md on
how to configute this node
"""
class RadarNode:
"""See doc/perception/radar_node.md on
how to configure this node
"""

Comment on lines 62 to 64
if __name__ == "__main__":
lidar_distance = RadarNode()
lidar_distance.listener()
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Update variable name to match radar functionality

The variable name still references lidar instead of radar.

Apply this diff:

if __name__ == "__main__":
-    lidar_distance = RadarNode()
-    lidar_distance.listener()
+    radar_node = RadarNode()
+    radar_node.listener()
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if __name__ == "__main__":
lidar_distance = RadarNode()
lidar_distance.listener()
if __name__ == "__main__":
radar_node = RadarNode()
radar_node.listener()

Comment on lines 23 to 33
def callback(self, data):
"""Callback function, filters a PontCloud2 message
by restrictions defined in the launchfile.

Publishes a Depth image for the specified camera angle.
Each angle has do be delt with differently since the signs of the
coordinate system change with the view angle.

:param data: a PointCloud2
"""

Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Update method documentation to reflect radar functionality

The documentation describes lidar-related functionality (depth images) instead of radar velocity processing.

Apply this diff:

    def callback(self, data):
-        """Callback function, filters a PontCloud2 message
-            by restrictions defined in the launchfile.
-
-            Publishes a Depth image for the specified camera angle.
-            Each angle has do be delt with differently since the signs of the
-            coordinate system change with the view angle.
-
-        :param data: a PointCloud2
+        """Process radar PointCloud2 data and publish minimum velocity.
+
+        Extracts velocity information from radar data and publishes
+        the minimum velocity as a Float32 message.
+
+        Args:
+            data: PointCloud2 message containing radar data with velocity field
        """
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
def callback(self, data):
"""Callback function, filters a PontCloud2 message
by restrictions defined in the launchfile.
Publishes a Depth image for the specified camera angle.
Each angle has do be delt with differently since the signs of the
coordinate system change with the view angle.
:param data: a PointCloud2
"""
def callback(self, data):
"""Process radar PointCloud2 data and publish minimum velocity.
Extracts velocity information from radar data and publishes
the minimum velocity as a Float32 message.
Args:
data: PointCloud2 message containing radar data with velocity field
"""

Comment on lines 38 to 59
def listener(self):
"""
Initializes the node and it's publishers
"""
# run simultaneously.
rospy.init_node("lidar_distance")
self.bridge = CvBridge()

# publisher for radar dist_array
self.dist_array_radar_publisher = rospy.Publisher(
rospy.get_param("~image_distance_topic", "/paf/hero/Radar/velocity"),
Float32,
queue_size=10,
)

rospy.Subscriber(
rospy.get_param("~source_topic", "/carla/hero/RADAR"),
PointCloud2,
self.callback,
)

rospy.spin()
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Update node name and remove unused CvBridge

The listener method contains remnants from lidar code:

  1. Incorrect node name "lidar_distance"
  2. Unused CvBridge initialization

Apply this diff:

    def listener(self):
        """
        Initializes the node and it's publishers
        """
-        # run simultaneously.
-        rospy.init_node("lidar_distance")
-        self.bridge = CvBridge()
+        rospy.init_node("radar_velocity")

        # publisher for radar dist_array
        self.dist_array_radar_publisher = rospy.Publisher(
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
def listener(self):
"""
Initializes the node and it's publishers
"""
# run simultaneously.
rospy.init_node("lidar_distance")
self.bridge = CvBridge()
# publisher for radar dist_array
self.dist_array_radar_publisher = rospy.Publisher(
rospy.get_param("~image_distance_topic", "/paf/hero/Radar/velocity"),
Float32,
queue_size=10,
)
rospy.Subscriber(
rospy.get_param("~source_topic", "/carla/hero/RADAR"),
PointCloud2,
self.callback,
)
rospy.spin()
def listener(self):
"""
Initializes the node and it's publishers
"""
rospy.init_node("radar_velocity")
# publisher for radar dist_array
self.dist_array_radar_publisher = rospy.Publisher(
rospy.get_param("~image_distance_topic", "/paf/hero/Radar/velocity"),
Float32,
queue_size=10,
)
rospy.Subscriber(
rospy.get_param("~source_topic", "/carla/hero/RADAR"),
PointCloud2,
self.callback,
)
rospy.spin()

Comment on lines 1 to 16
#!/usr/bin/env python
import rospy
import ros_numpy
import numpy as np
import lidar_filter_utility
from sensor_msgs.msg import PointCloud2

# from mpl_toolkits.mplot3d import Axes3D
# from itertools import combinations
from sensor_msgs.msg import Image as ImageMsg
from cv_bridge import CvBridge

from std_msgs.msg import Float32

# from matplotlib.colors import LinearSegmentedColormap

Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Clean up imports and remove lidar-related dependencies

The imports section contains several issues:

  1. Unused imports flagged by static analysis: lidar_filter_utility and ImageMsg
  2. Commented out imports that should be removed
  3. Lidar-related imports in a radar node suggesting possible copy-paste errors

Apply this diff to clean up the imports:

#!/usr/bin/env python
import rospy
import ros_numpy
import numpy as np
-import lidar_filter_utility
from sensor_msgs.msg import PointCloud2
-
-# from mpl_toolkits.mplot3d import Axes3D
-# from itertools import combinations
-from sensor_msgs.msg import Image as ImageMsg
from cv_bridge import CvBridge
-
from std_msgs.msg import Float32
-
-# from matplotlib.colors import LinearSegmentedColormap
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
#!/usr/bin/env python
import rospy
import ros_numpy
import numpy as np
import lidar_filter_utility
from sensor_msgs.msg import PointCloud2
# from mpl_toolkits.mplot3d import Axes3D
# from itertools import combinations
from sensor_msgs.msg import Image as ImageMsg
from cv_bridge import CvBridge
from std_msgs.msg import Float32
# from matplotlib.colors import LinearSegmentedColormap
#!/usr/bin/env python
import rospy
import ros_numpy
import numpy as np
from sensor_msgs.msg import PointCloud2
from cv_bridge import CvBridge
from std_msgs.msg import Float32
🧰 Tools
🪛 Ruff (0.7.0)

5-5: lidar_filter_utility imported but unused

Remove unused import: lidar_filter_utility

(F401)


10-10: sensor_msgs.msg.Image imported but unused

Remove unused import: sensor_msgs.msg.Image

(F401)

Comment on lines +34 to +36
coordinates = ros_numpy.point_cloud2.pointcloud2_to_array(data)
msg = np.min(coordinates["Velocity"])
self.dist_array_radar_publisher.publish(msg)
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Add error handling for radar data processing

The callback lacks validation and error handling for the radar data processing.

Apply this diff to add proper error handling:

-        coordinates = ros_numpy.point_cloud2.pointcloud2_to_array(data)
-        msg = np.min(coordinates["Velocity"])
-        self.dist_array_radar_publisher.publish(msg)
+        try:
+            coordinates = ros_numpy.point_cloud2.pointcloud2_to_array(data)
+            if "Velocity" not in coordinates.dtype.names:
+                rospy.logerr("Radar data missing Velocity field")
+                return
+            if len(coordinates) == 0:
+                rospy.logwarn("Received empty radar data")
+                return
+            msg = np.min(coordinates["Velocity"])
+            self.dist_array_radar_publisher.publish(msg)
+        except Exception as e:
+            rospy.logerr(f"Error processing radar data: {e}")
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
coordinates = ros_numpy.point_cloud2.pointcloud2_to_array(data)
msg = np.min(coordinates["Velocity"])
self.dist_array_radar_publisher.publish(msg)
try:
coordinates = ros_numpy.point_cloud2.pointcloud2_to_array(data)
if "Velocity" not in coordinates.dtype.names:
rospy.logerr("Radar data missing Velocity field")
return
if len(coordinates) == 0:
rospy.logwarn("Received empty radar data")
return
msg = np.min(coordinates["Velocity"])
self.dist_array_radar_publisher.publish(msg)
except Exception as e:
rospy.logerr(f"Error processing radar data: {e}")

Comment on lines +84 to +85
<param name="point_cloud_topic" value="/carla/hero/RADAR_filtered"/>
<param name="range_topic" value="/carla/hero/RADAR_range"/>
Copy link
Contributor

Choose a reason for hiding this comment

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

💡 Codebase verification

Warning: RADAR topics mismatch detected

The RADAR topics referenced in perception.launch (/carla/hero/RADAR_filtered and /carla/hero/RADAR_range) don't match the actual topics used in the radar_node.py implementation:

  • radar_node.py subscribes to /carla/hero/RADAR
  • radar_node.py publishes to /paf/hero/Radar/velocity

Additionally, the node doesn't use the parameters point_cloud_topic and range_topic defined in the launch file.

  • Update perception.launch to use correct topics:
    <param name="source_topic" value="/carla/hero/RADAR"/>
    <param name="image_distance_topic" value="/paf/hero/Radar/velocity"/>
  • Or modify radar_node.py to use the launch file parameters
🔗 Analysis chain

Verify the existence of RADAR topics.

The node references filtered RADAR data topics. Let's verify these topics exist in the system.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Search for RADAR topic definitions and usage
# Expected: Find corresponding topic definitions in sensor setup or CARLA configuration

# Search for RADAR topic definitions
rg -l "RADAR_filtered|RADAR_range" --type python --type xml

# Search for any RADAR-related configurations
fd -e yaml -e xml -e json | xargs rg "RADAR" -l

Length of output: 175


Script:

#!/bin/bash
# Let's check the content of the dev_objects.json to understand RADAR configuration
cat code/agent/config/dev_objects.json

# Let's also search for any RADAR-related topics in launch files
find . -name "*.launch" -type f -exec grep -l "RADAR" {} \;

# Search for any RADAR-related code in Python files (using find since rg doesn't support python)
find . -name "*.py" -type f -exec grep -l "RADAR" {} \;

Length of output: 6497


Script:

#!/bin/bash
# Let's check the radar_node.py to understand how these topics are used
cat code/perception/src/radar_node.py

# Also check the perception launch file to see the full context
cat code/perception/launch/perception.launch

Length of output: 5362

Copy link
Collaborator

@michalal7 michalal7 left a comment

Choose a reason for hiding this comment

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

Consider implementing the recommended changes suggested by CodeRabbitAI for the perception.launch file. Approved, as it is working fine and updates are already in progress under issue #454.

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.

Add radar sensor
2 participants