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

Lidar parsing #50

Merged
merged 13 commits into from
Dec 5, 2024
Merged

Lidar parsing #50

merged 13 commits into from
Dec 5, 2024

Conversation

Mmoyv27
Copy link
Contributor

@Mmoyv27 Mmoyv27 commented Oct 20, 2024

Added the lidar_parser module

Copy link
Contributor

@ashum68 ashum68 left a comment

Choose a reason for hiding this comment

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

Reviewed.

I think we can make an optimization to how we return a complete oscillation. instead of creating a LidarOscillation in a separate function and assigning it to a variable (extra memory) we can directly return it inside of process_reading(). i.e. if ... : return lidar_oscillation.LidarOscillation.create(self.lidar_readings) and then reinitialize lidar_readings

Also, it seems like run is just a wrapper for process reading so we can just move the contents of process_reading into the run function


from modules import lidar_detection
from modules import lidar_oscillation
from modules import decision
Copy link
Contributor

Choose a reason for hiding this comment

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

remove decision import - not needed here

Copy link
Contributor

Choose a reason for hiding this comment

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

Module to parse LiDAR data, detect oscillations, and return oscillation objects.
"""

from modules import lidar_oscillation
Copy link
Contributor

Choose a reason for hiding this comment

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

small nit - put this in alphabetical order

__create_key = object()

@classmethod
def create(cls) -> "tuple[bool, LidarParser | None]":
Copy link
Contributor

Choose a reason for hiding this comment

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

no need for a create method for this module

"""
Process a single LidarDetection.
"""
if not self.__run:
Copy link
Contributor

Choose a reason for hiding this comment

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

why do we need this check? the run function is called in a loop not just once

self.current_oscillation = None

self.last_angle = None
self.direction = None
Copy link
Contributor

Choose a reason for hiding this comment

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

let's create an enum class for the direction of the lidar scan

Feeding LidarParser continuously with a stream of LidarDetection
"""

result, parser = lidar_parser.LidarParser.create()
Copy link
Contributor

Choose a reason for hiding this comment

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

no create method

if lidar_data is None:
break

parser.run(lidar_data)
Copy link
Contributor

Choose a reason for hiding this comment

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

this should return a result and either none or a lidar osciallation


parser.run(lidar_data)

result, oscillation = parser.run(detection_in_queue)
Copy link
Contributor

Choose a reason for hiding this comment

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

the run function accepts a LidarDetection as a parameter. so we don't pass the queue to the run function.

Feeding LidarParser continuously with a stream of LidarDetection
"""

result, parser = lidar_parser.LidarParser()
Copy link
Contributor

Choose a reason for hiding this comment

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

this doesn't return a result - just the parser

controller.check_pause()

lidar_reading: lidar_detection.LidarDetection = detection_in_queue.queue.get()
if lidar_reading is None: # Do we want this line?
Copy link
Contributor

Choose a reason for hiding this comment

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

remove this comment

Process a single LidarDetection and return the oscillation if complete.
"""

if lidar_detection is None:
Copy link
Contributor

Choose a reason for hiding this comment

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

worker ensures lidar_detection is not None

controller: worker_controller.WorkerController,
) -> None:
"""
Feeding LidarParser continuously with a stream of LidarDetection
Copy link
Contributor

Choose a reason for hiding this comment

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

small nit - add a period

from modules import lidar_detection
from modules.lidar_parser import lidar_parser

ANGLE_UP = 15.0
Copy link
Contributor

Choose a reason for hiding this comment

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

these can just be hard-coded

lidar_parser_instance.run(lidar_detection_up)
lidar_parser_instance.run(higher_angle_detection_up)
result, oscillation = lidar_parser_instance.run(lidar_detection_down)
assert result
Copy link
Contributor

Choose a reason for hiding this comment

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

check list length (i.e. len == 2) and check whether the oscillation contains only the readings going up i.e. it sees 15 and 20 degrees. (lidar_oscillation.readings[0].angle == 15)

Copy link
Contributor

Choose a reason for hiding this comment

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

  1. expected = lidar_detection.create(5, 10)
  2. oscillation = parser.run()
  3. assert expected.angle == oscillation.readings[0].angle

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've implemented this in the test_oscillation_detected_up_down

result, oscillation = lidar_parser_instance.run(lidar_detection_down)
assert result
assert oscillation is not None
assert len(lidar_parser_instance.lidar_readings) == 0
Copy link
Contributor

Choose a reason for hiding this comment

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

store last reading after direction switch


for i in range(4):
if i % 2 == 0:
result, oscillation = lidar_parser_instance.run(higher_angle_detection_up)
Copy link
Contributor

Choose a reason for hiding this comment

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

check len

Copy link
Contributor

@ashum68 ashum68 left a comment

Choose a reason for hiding this comment

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

reviewed

@@ -188,6 +187,7 @@ def test_no_oscillation_with_single_reading(
result, oscillation = lidar_parser_instance.run(lidar_detection_up)
assert not result
assert oscillation is None
assert lidar_parser_instance.lidar_readings[0].angle == 15.0
Copy link
Contributor

Choose a reason for hiding this comment

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

we want to check that the returned oscillation has the angle 15 in it not the instance which is the test case that you created.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

oscillation not being returned here, as solo angle being provided to our lidar_parser instance. so the last assert basically looks at the leftovers, that the 15 degree ange is being processed, but not returned

@@ -102,6 +99,8 @@ def test_oscillation_detected_up_to_down(
result, oscillation = lidar_parser_instance.run(lidar_detection_down)
assert result
assert oscillation is not None
assert len(oscillation.readings) == 2
assert lidar_parser_instance.lidar_readings[0].angle == -15.0
Copy link
Contributor

Choose a reason for hiding this comment

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

check that the oscillation has this angle in it, not the instance that you created

Copy link
Contributor

@ashum68 ashum68 left a comment

Choose a reason for hiding this comment

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

LGTM

@Mmoyv27 Mmoyv27 merged commit c084f26 into main Dec 5, 2024
1 check passed
@Mmoyv27 Mmoyv27 deleted the lidar_parsing branch December 5, 2024 05:12
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.

2 participants