-
Notifications
You must be signed in to change notification settings - Fork 0
Show completion time as metrics on the dashboard #16
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| """Helper class to detect if the robot is stuck.""" | ||
|
|
||
| import msgs | ||
|
|
||
|
|
||
| class StuckDetector: | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you think this is relatively generic? (toolkit?)
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was thinking about this, but probably every use-case is different enough so you cant use the same thing unless we make it complex with a lot of parameters. Might be better to have recepie-book or something with testing tricks like this. |
||
| """Helper class to detect if the robot is stuck.""" | ||
|
|
||
| def __init__(self, threshold: float = 0.1, max_no_progress_time: float = 3.0): | ||
| """Initialize the stuck detector. | ||
|
|
||
| Args: | ||
| threshold: Distance threshold in meters to consider as progress. | ||
| max_no_progress_time: Maximum time in seconds without progress before | ||
| considering the robot as stuck. | ||
|
|
||
| """ | ||
| self.threshold = threshold | ||
| self.max_no_progress_time = max_no_progress_time | ||
| self.last_position = None | ||
| self.last_progress_time = None | ||
|
|
||
| def step_is_stuck(self, position: msgs.Transform, current_time: float) -> bool: | ||
| """Update the detector with the current position. | ||
|
|
||
| Returns True if the robot is considered stuck. | ||
| """ | ||
| if self.last_position is None or self.last_progress_time is None: | ||
| self.last_position = position | ||
| self.last_progress_time = current_time | ||
| return False | ||
|
|
||
| distance_moved = ( | ||
| (position.x - self.last_position.x) ** 2 | ||
| + (position.y - self.last_position.y) ** 2 | ||
| + (position.z - self.last_position.z) ** 2 | ||
| ) ** 0.5 | ||
|
|
||
| if distance_moved >= self.threshold: | ||
| self.last_position = position | ||
| self.last_progress_time = current_time | ||
| return False | ||
| else: | ||
| if current_time - self.last_progress_time > self.max_no_progress_time: | ||
| print( | ||
| "Robot is stuck: no significant movement detected." | ||
| f" Distance moved: {distance_moved:.3f} m in" | ||
| f" {current_time - self.last_progress_time:.2f} s." | ||
| ) | ||
| return True | ||
|
|
||
| return False | ||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually thats a good point. Given we now have better support for usign
metrics.jsonmaybe we need a toolkit helper to actually help make / populate itThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That could be nice! Right now, i only add metrics from the test file, but mainly because it would need a more complex util to update metrics safely from multiple processes. It would be great if the toolkit could help with that.