-
Notifications
You must be signed in to change notification settings - Fork 2.8k
[Improve] Improve camera backend and add motor read retries #2152
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
base: main
Are you sure you want to change the base?
Conversation
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.
Pull Request Overview
This PR improves camera compatibility on Windows and adds retry logic for motor position reads to increase robustness. The changes focus on enhancing hardware reliability and error handling.
- Switch Windows camera backend from MSMF to DirectShow for better compatibility
- Replace camera dimension validation errors with warnings and automatic adjustment
- Add retry logic (5 attempts) to motor position reads for SO101 leader and follower robots
Reviewed Changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
File | Description |
---|---|
src/lerobot/cameras/utils.py | Changes Windows OpenCV backend from MSMF to DirectShow |
src/lerobot/cameras/opencv/camera_opencv.py | Replaces dimension validation errors with warnings and auto-adjustment |
src/lerobot/teleoperators/so101_leader/so101_leader.py | Adds retry logic to motor position reads |
src/lerobot/robots/so101_follower/so101_follower.py | Adds retry logic to motor position reads |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
if self.rotation in [cv2.ROTATE_90_CLOCKWISE, cv2.ROTATE_90_COUNTERCLOCKWISE]: | ||
self.width, self.height = self.capture_height, self.capture_width | ||
else: | ||
self.width, self.height = self.capture_width, self.capture_height |
Copilot
AI
Oct 9, 2025
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.
[nitpick] This dimension update logic should be extracted into a separate method to improve code organization and reusability. The logic for determining output dimensions based on rotation could be used elsewhere in the camera handling code.
if self.rotation in [cv2.ROTATE_90_CLOCKWISE, cv2.ROTATE_90_COUNTERCLOCKWISE]: | |
self.width, self.height = self.capture_height, self.capture_width | |
else: | |
self.width, self.height = self.capture_width, self.capture_height | |
self.width, self.height = self._get_output_dimensions(self.capture_width, self.capture_height, self.rotation) | |
Returns the output dimensions (width, height) based on the capture dimensions and rotation. | |
""" | |
if rotation in [cv2.ROTATE_90_CLOCKWISE, cv2.ROTATE_90_COUNTERCLOCKWISE]: | |
return capture_height, capture_width | |
else: | |
return capture_width, capture_height |
Copilot uses AI. Check for mistakes.
What this does
This pull request improves camera compatibility, error handling, and motor position reading robustness.
Camera compatibility and error handling
Switched the default OpenCV backend for Windows from
cv2.CAP_MSMF
tocv2.CAP_DSHOW
inget_cv2_backend
, improving camera support and stability.Updated
_validate_width_and_height
incamera_opencv.py
:Motor position reading robustness
Added a
num_retry=5
parameter tosync_read("Present_Position")
calls in:so101_follower.py
so101_leader.py
This adds retries for more reliable motor position reads.
(diff 1, diff 2)
How it was tested
Verified camera behavior on Windows setup:
Tested new retry logic by simulating communication drops:
Confirmed that no regressions occurred in existing camera or motor tests.
How to checkout & try?
To verify the lerobot-teleoperate connection retry, please use the following command.
The sync will be much smoother and will successfully connect most of the time
The sync will be much smoother and will successfully connect most of the time. I have mostly connected and failed without retry (I think that maybe some latency for some hardware)
For camera, please verify the camera