[Improve] Improve camera backend and add motor read retries #2152
+17
−7
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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