Repository navigation
Bus servo management. Improvements to framework including temperature management #143
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
28 commits
Select commit
Hold shift + click to select a range
4c8c7d9
WIP bus servo management
danic85 d18189c
Update config
danic85 60d524a
Added SC servo examples + compatibility
danic85 3e4dfc0
Configure initial positions
danic85 0be65a3
Allow other poses to be stored and accessed
danic85 91fac95
Added change_id script
danic85 69f2d7c
Calibrate servos on boot
danic85 9a57f8a
adjustments
danic85 0cf906e
Dynamic servo calibration + center on change_id
danic85 8d62b54
Controller support and WIP recording
danic85 f02d0db
Working with Pi
danic85 b052ed0
Adjust config
danic85 6841f63
Cleanup
danic85 c1ed384
Working input recorder
danic85 5e503e5
Support servo control (WIP - calibration needed)
danic85 008c369
Callibration + allow modules to be disabled on test environments
danic85 af0fdb2
Disable test
danic85 40040c8
Add documentation and tests
danic85 f645caa
Fix test
danic85 8a22781
Timeout controller connection after 30 seconds
danic85 d81c07c
Enable on robot
danic85 6a84d43
Fix for environment input to resolve pi issue
danic85 4803d58
Calibrate new leg position
danic85 dc4cb27
Improvements to gamepad controller modules. Temperature alert in dispβ¦
danic85 d48ccd8
Fix tests
danic85 4a5a0ee
Fixes and improvements to loop and temperature management
danic85 5349956
Fix tests
danic85 cd4331b
Resolve PR comments
danic85 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Dynamic servo calibration + center on change_id
- Loading branch information
commit 0cf906e48f23a58a1b0e8729f67d24f90bbc0a8f
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,6 +2,8 @@ | |
|
|
||
| import sys | ||
| import os | ||
| import select | ||
| import time | ||
|
|
||
| if os.name == 'nt': | ||
| import msvcrt | ||
|
|
@@ -50,6 +52,7 @@ def __init__(self, **kwargs): | |
| self.baudrate = kwargs.get('baudrate', 1000000) | ||
| self.port = kwargs.get('port', '/dev/ttyACM0') # Change as needed, find with `ls /dev/ttyACM*` | ||
| self.calibrate_on_boot = kwargs.get('calibrate_on_boot', True) # Loop to show position for manual configuration | ||
| self.demonstrate_on_boot = kwargs.get('demonstrate_on_boot', False) # Move to min and max to demonstrate range | ||
| self.pos = self.start | ||
| self.speed = 2400 # 3073 | ||
| self.acceleration = 50 | ||
|
|
@@ -97,10 +100,20 @@ def setup_messaging(self): | |
| self.subscribe('system/exit', self.exit) | ||
|
|
||
| if self.calibrate_on_boot: | ||
| self.calibrate() # Log will show current position repeatedly to help with manual configuration | ||
| self.calibrate_dynamic() # Log will show current position repeatedly to help with manual configuration | ||
|
|
||
| self.pos = self.get_position() # Get initial position to avoid jumping from unknown position | ||
|
|
||
| if self.demonstrate_on_boot: | ||
| self.log(f"Demonstrating servo {self.identifier} movement") | ||
| if self.range is not None: | ||
| self.move(self.range[0]) | ||
| time.sleep(1) | ||
| self.move(self.range[1]) | ||
| time.sleep(1) | ||
| else: | ||
| self.log(f"Range not set for servo {self.identifier}, cannot demonstrate movement", level='warning') | ||
|
|
||
| # Move to start position | ||
| # if self.get_pose_value('stand') is not None: | ||
| # self.start = self.get_pose_value('stand') | ||
|
Comment on lines
+124
to
+125
|
||
|
|
@@ -148,7 +161,7 @@ def get_position(self): | |
| # Read STServo present position | ||
| sts_present_position, sts_present_speed, sts_comm_result, sts_error = self.packetHandler.ReadPosSpeed(self.index) | ||
| if not self.handle_errors(sts_comm_result, sts_error): | ||
| self.log("[ID:%03d] PresPos:%d PresSpd:%d" % (self.index, sts_present_position, sts_present_speed)) | ||
| # self.log("[ID:%03d] PresPos:%d PresSpd:%d" % (self.index, sts_present_position, sts_present_speed)) | ||
| return sts_present_position | ||
| else: | ||
| return self.sc_get_position_speed('position') | ||
|
|
@@ -234,12 +247,45 @@ def calibrate(self): | |
| max = self.get_position() | ||
| self.log(f"Captured maximum position: {max}") | ||
| self.range = (min, max) | ||
| if self.start < min or self.start > max: | ||
| if self.start is not None and (self.start < min or self.start > max): | ||
| self.start = (min + max) // 2 | ||
| self.log(f"Start position {self.start} out of new range, setting to midpoint {self.start}") | ||
| self.log(f"Updated range for {self.identifier}: {self.range}. Start position: {self.start}") | ||
|
|
||
|
|
||
| def calibrate_dynamic(self): | ||
| """ | ||
| Continuously log the current position to help with manual calibration. | ||
| Store min an max as they are found. | ||
| Complete on key press. and store in self.range | ||
| """ | ||
| self.log(f"Calibrating servo {self.identifier}. Move the servo to find min and max positions. Press any key to finish...") | ||
| min_pos = None | ||
| max_pos = None | ||
| try: | ||
| while True: | ||
| pos = self.get_position() | ||
| if min_pos is None or pos < min_pos: | ||
| min_pos = pos | ||
| if max_pos is None or pos > max_pos: | ||
| max_pos = pos | ||
| # Print on the same line, pad with spaces to clear previous content | ||
| print(f"\rCurrent position: {pos}, Min: {min_pos}, Max: {max_pos} ", end='', flush=True) | ||
| time.sleep(0.05) | ||
| if sys.stdin in select.select([sys.stdin], [], [], 0)[0]: | ||
| sys.stdin.read(1) # Consume the key so buffer is cleared | ||
| break | ||
| except KeyboardInterrupt: | ||
|
danic85 marked this conversation as resolved.
Resolved
|
||
| pass | ||
| print() # Move to next line after loop | ||
| if min_pos is not None and max_pos is not None: | ||
| self.range = (min_pos, max_pos) | ||
| self.log(f"Calibration complete for {self.identifier}. Range: {self.range}") | ||
| else: | ||
| self.log(f"No positions recorded during calibration for {self.identifier}.", level='warning') | ||
|
|
||
| if self.start is not None and (self.start < min_pos or self.start > max_pos): | ||
| self.start = (min_pos + max_pos) // 2 | ||
| self.log(f"Start position {self.start} out of new range, setting to midpoint {self.start}") | ||
|
|
||
|
|
||
|
|
||
|
|
||
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.
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.
Import of 'os' is not used.