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
Next
Next commit
WIP bus servo management
- Loading branch information
commit 4c8c7d98c07bad2b57b90e58c97b924ae64fd14f
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
131 changes: 131 additions & 0 deletions
131
modules/actuators/bus_servo/STServo_examples/change_id.py
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 |
|---|---|---|
| @@ -0,0 +1,131 @@ | ||
| #!/usr/bin/env python | ||
| # | ||
| # ********* Change Servo ID Example ********* | ||
| # | ||
| # Works for both STS (ST3215) and SCSCL (SC09) servos. | ||
| # Requires each servo to be connected individually. | ||
| # RUN THIS BEFORE USING THE SERVOS IN ANY OTHER EXAMPLE! | ||
| # | ||
|
|
||
| import sys | ||
| import os | ||
|
|
||
| if os.name == 'nt': | ||
| import msvcrt | ||
| def getch(): | ||
| return msvcrt.getch().decode() | ||
| else: | ||
| import tty, termios | ||
| fd = sys.stdin.fileno() | ||
| old_settings = termios.tcgetattr(fd) | ||
| def getch(): | ||
| try: | ||
| tty.setraw(sys.stdin.fileno()) | ||
| ch = sys.stdin.read(1) | ||
| finally: | ||
| termios.tcsetattr(fd, termios.TCSADRAIN, old_settings) | ||
| return ch | ||
|
|
||
| sys.path.append("..") | ||
| from STservo_sdk import * | ||
|
|
||
| # User config | ||
| SERVO_TYPE = input("Enter servo type (STS for ST3215, SCSCL for SC09): ").strip().upper() | ||
| SERVO_ID = int(input("Enter current servo ID (1-253): ")) | ||
| BAUDRATE = 1000000 | ||
| DEVICENAME = '/dev/ttyACM0' # Change as needed | ||
|
|
||
| # Initialize PortHandler | ||
| portHandler = PortHandler(DEVICENAME) | ||
|
|
||
| # Select correct packet handler | ||
| if SERVO_TYPE == "STS": | ||
| packetHandler = sts(portHandler) | ||
| ID_ADDR = 5 | ||
| elif SERVO_TYPE == "SCSCL": | ||
| packetHandler = scscl(portHandler) | ||
| ID_ADDR = 5 | ||
| else: | ||
| print("Unknown servo type.") | ||
| sys.exit(1) | ||
|
|
||
| # Open port | ||
| if portHandler.openPort(): | ||
| print("Succeeded to open the port") | ||
| else: | ||
| print("Failed to open the port") | ||
| print("Press any key to terminate...") | ||
| getch() | ||
| sys.exit(1) | ||
|
|
||
| # Set baudrate | ||
| if portHandler.setBaudRate(BAUDRATE): | ||
| print("Succeeded to change the baudrate") | ||
| else: | ||
| print("Failed to change the baudrate") | ||
| print("Press any key to terminate...") | ||
| getch() | ||
| portHandler.closePort() | ||
| sys.exit(1) | ||
|
|
||
| while True: | ||
| print("Press any key to continue! (or press ESC to quit!)") | ||
| if getch() == chr(0x1b): | ||
| break | ||
|
|
||
| # Read present position/speed (optional, for feedback) | ||
| try: | ||
| if SERVO_TYPE == "STS": | ||
| pos, spd, comm_result, err = packetHandler.ReadPosSpeed(SERVO_ID) | ||
| else: | ||
| pos, spd, comm_result, err = packetHandler.ReadPosSpeed(SERVO_ID) | ||
| if comm_result == COMM_SUCCESS: | ||
| print(f"[ID:{SERVO_ID:03d}] PresPos:{pos} PresSpd:{spd}") | ||
| else: | ||
| print(packetHandler.getTxRxResult(comm_result)) | ||
| if err != 0: | ||
| print(packetHandler.getRxPacketError(err)) | ||
| except Exception as e: | ||
| print(f"Could not read servo: {e}") | ||
|
|
||
| # Get new ID | ||
| try: | ||
| new_id = int(input("Enter new ID (1-253): ")) | ||
| except Exception: | ||
| print("Invalid input.") | ||
| continue | ||
| if new_id < 1 or new_id > 253: | ||
| print("Invalid ID. Please enter a value between 1 and 253.") | ||
| continue | ||
|
|
||
| # Unlock EEPROM | ||
| unlock_result, unlock_error = packetHandler.unLockEprom(SERVO_ID) | ||
| if unlock_result != COMM_SUCCESS or unlock_error != 0: | ||
| print("Failed to unlock EEPROM: %s %s" % ( | ||
| packetHandler.getTxRxResult(unlock_result), | ||
| packetHandler.getRxPacketError(unlock_error) | ||
| )) | ||
| continue | ||
|
|
||
| # Write new ID | ||
| write_result, write_error = packetHandler.write1ByteTxRx(SERVO_ID, ID_ADDR, new_id) | ||
| if write_result != COMM_SUCCESS or write_error != 0: | ||
| print("Failed to change ID: %s %s" % ( | ||
| packetHandler.getTxRxResult(write_result), | ||
| packetHandler.getRxPacketError(write_error) | ||
| )) | ||
| continue | ||
|
|
||
| # Lock EEPROM | ||
| lock_result, lock_error = packetHandler.LockEprom(new_id) | ||
| if lock_result != COMM_SUCCESS or lock_error != 0: | ||
| print("Failed to lock EEPROM: %s %s" % ( | ||
| packetHandler.getTxRxResult(lock_result), | ||
| packetHandler.getRxPacketError(lock_error) | ||
| )) | ||
| continue | ||
|
|
||
| print(f"{SERVO_TYPE} servo ID changed successfully to {new_id}") | ||
| SERVO_ID = new_id | ||
|
|
||
| portHandler.closePort() | ||
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 |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
| #!/usr/bin/env python | ||
| # | ||
| # ********* Ping Example ********* | ||
| # | ||
| # | ||
| # Available STServo model on this example : All models using Protocol STS | ||
| # This example is tested with a STServo and an URT | ||
| # | ||
|
|
||
| import sys | ||
| import os | ||
|
|
||
| if os.name == 'nt': | ||
| import msvcrt | ||
| def getch(): | ||
| return msvcrt.getch().decode() | ||
| else: | ||
| import sys, tty, termios | ||
| fd = sys.stdin.fileno() | ||
| old_settings = termios.tcgetattr(fd) | ||
| def getch(): | ||
| try: | ||
| tty.setraw(sys.stdin.fileno()) | ||
| ch = sys.stdin.read(1) | ||
| finally: | ||
| termios.tcsetattr(fd, termios.TCSADRAIN, old_settings) | ||
| return ch | ||
|
|
||
| sys.path.append("..") | ||
| from STservo_sdk import * # Uses STServo SDK library | ||
|
danic85 marked this conversation as resolved.
Resolved
|
||
|
|
||
| # Default setting | ||
| STS_ID = 1 # STServo ID : 1 | ||
| BAUDRATE = 1000000 # STServo default baudrate : 1000000 | ||
| DEVICENAME = '/dev/ttyACM0' # Check which port is being used on your controller | ||
| # ex) Windows: "COM1" Linux: "/dev/ttyUSB0" Mac: "/dev/tty.usbserial-*" | ||
|
|
||
| # Initialize PortHandler instance | ||
| # Set the port path | ||
| # Get methods and members of PortHandlerLinux or PortHandlerWindows | ||
| portHandler = PortHandler(DEVICENAME) | ||
|
|
||
| # Initialize PacketHandler instance | ||
| # Get methods and members of Protocol | ||
| packetHandler = sts(portHandler) | ||
| # Open port | ||
| if portHandler.openPort(): | ||
| print("Succeeded to open the port") | ||
| else: | ||
| print("Failed to open the port") | ||
| print("Press any key to terminate...") | ||
| getch() | ||
| quit() | ||
|
|
||
|
|
||
| # Set port baudrate | ||
| if portHandler.setBaudRate(BAUDRATE): | ||
| print("Succeeded to change the baudrate") | ||
| else: | ||
| print("Failed to change the baudrate") | ||
| print("Press any key to terminate...") | ||
| getch() | ||
| quit() | ||
|
|
||
| # Try to ping the STServo | ||
| # Get STServo model number | ||
| sts_model_number, sts_comm_result, sts_error = packetHandler.ping(STS_ID) | ||
| if sts_comm_result != COMM_SUCCESS: | ||
| print("%s" % packetHandler.getTxRxResult(sts_comm_result)) | ||
| else: | ||
| print("[ID:%03d] ping Succeeded. STServo model number : %d" % (STS_ID, sts_model_number)) | ||
| if sts_error != 0: | ||
| print("%s" % packetHandler.getRxPacketError(sts_error)) | ||
|
|
||
| # Close port | ||
| portHandler.closePort() | ||
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 |
|---|---|---|
| @@ -0,0 +1,80 @@ | ||
| #!/usr/bin/env python | ||
| # | ||
| # ********* Gen Write Example ********* | ||
| # | ||
| # | ||
| # Available STServo model on this example : All models using Protocol STS | ||
| # This example is tested with a STServo and an URT | ||
| # | ||
|
|
||
| import sys | ||
| import os | ||
|
|
||
| if os.name == 'nt': | ||
| import msvcrt | ||
| def getch(): | ||
| return msvcrt.getch().decode() | ||
|
|
||
| else: | ||
| import sys, tty, termios | ||
| fd = sys.stdin.fileno() | ||
| old_settings = termios.tcgetattr(fd) | ||
| def getch(): | ||
| try: | ||
| tty.setraw(sys.stdin.fileno()) | ||
| ch = sys.stdin.read(1) | ||
| finally: | ||
| termios.tcsetattr(fd, termios.TCSADRAIN, old_settings) | ||
| return ch | ||
|
|
||
| sys.path.append("..") | ||
| from STservo_sdk import * # Uses STServo SDK library | ||
|
danic85 marked this conversation as resolved.
Resolved
|
||
|
|
||
| # Default setting | ||
| STS_ID = 1 # STServo ID : 1 | ||
| BAUDRATE = 1000000 # STServo default baudrate : 1000000 | ||
| DEVICENAME = '/dev/ttyACM0' # Check which port is being used on your controller | ||
| # ex) Windows: "COM1" Linux: "/dev/ttyUSB0" Mac: "/dev/tty.usbserial-*" | ||
|
|
||
| # Initialize PortHandler instance | ||
| # Set the port path | ||
| # Get methods and members of PortHandlerLinux or PortHandlerWindows | ||
| portHandler = PortHandler(DEVICENAME) | ||
|
|
||
| # Initialize PacketHandler instance | ||
| # Get methods and members of Protocol | ||
| packetHandler = sts(portHandler) | ||
|
|
||
| # Open port | ||
| if portHandler.openPort(): | ||
| print("Succeeded to open the port") | ||
| else: | ||
| print("Failed to open the port") | ||
| print("Press any key to terminate...") | ||
| getch() | ||
| quit() | ||
|
|
||
| # Set port baudrate | ||
| if portHandler.setBaudRate(BAUDRATE): | ||
| print("Succeeded to change the baudrate") | ||
| else: | ||
| print("Failed to change the baudrate") | ||
| print("Press any key to terminate...") | ||
| getch() | ||
| quit() | ||
|
|
||
| while 1: | ||
| print("Press any key to continue! (or press ESC to quit!)") | ||
| if getch() == chr(0x1b): | ||
| break | ||
| # Read STServo present position | ||
| sts_present_position, sts_present_speed, sts_comm_result, sts_error = packetHandler.ReadPosSpeed(STS_ID) | ||
| if sts_comm_result != COMM_SUCCESS: | ||
| print(packetHandler.getTxRxResult(sts_comm_result)) | ||
| else: | ||
| print("[ID:%03d] PresPos:%d PresSpd:%d" % (STS_ID, sts_present_position, sts_present_speed)) | ||
| if sts_error != 0: | ||
| print(packetHandler.getRxPacketError(sts_error)) | ||
|
|
||
| # Close port | ||
| portHandler.closePort() | ||
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 |
|---|---|---|
| @@ -0,0 +1,84 @@ | ||
| #!/usr/bin/env python | ||
| # | ||
| # ********* Gen Write Example ********* | ||
| # | ||
| # | ||
| # Available STServo model on this example : All models using Protocol STS | ||
| # This example is tested with a STServo and an URT | ||
| # | ||
|
|
||
| import sys | ||
| import os | ||
|
|
||
| if os.name == 'nt': | ||
| import msvcrt | ||
| def getch(): | ||
| return msvcrt.getch().decode() | ||
|
|
||
| else: | ||
| import sys, tty, termios | ||
| fd = sys.stdin.fileno() | ||
| old_settings = termios.tcgetattr(fd) | ||
| def getch(): | ||
| try: | ||
| tty.setraw(sys.stdin.fileno()) | ||
| ch = sys.stdin.read(1) | ||
| finally: | ||
| termios.tcsetattr(fd, termios.TCSADRAIN, old_settings) | ||
| return ch | ||
|
|
||
| sys.path.append("..") | ||
| from STservo_sdk import * # Uses STServo SDK library | ||
|
|
||
| # Default setting | ||
| STS_ID = 1 # STServo ID : 1 | ||
| BAUDRATE = 1000000 # STServo default baudrate : 1000000 | ||
| DEVICENAME = '/dev/ttyACM0' # Check which port is being used on your controller | ||
| # ex) Windows: "COM1" Linux: "/dev/ttyUSB0" Mac: "/dev/tty.usbserial-*" | ||
| SERVO_CNT = 20 # Number of servos to read | ||
|
|
||
| # Initialize PortHandler instance | ||
| # Set the port path | ||
| # Get methods and members of PortHandlerLinux or PortHandlerWindows | ||
| portHandler = PortHandler(DEVICENAME) | ||
|
|
||
| # Initialize PacketHandler instance | ||
| # Get methods and members of Protocol | ||
| packetHandler = sts(portHandler) | ||
|
|
||
| # Open port | ||
| if portHandler.openPort(): | ||
| print("Succeeded to open the port") | ||
| else: | ||
| print("Failed to open the port") | ||
| print("Press any key to terminate...") | ||
| getch() | ||
| quit() | ||
|
|
||
| # Set port baudrate | ||
| if portHandler.setBaudRate(BAUDRATE): | ||
| print("Succeeded to change the baudrate") | ||
| else: | ||
| print("Failed to change the baudrate") | ||
| print("Press any key to terminate...") | ||
| getch() | ||
| quit() | ||
|
|
||
| # Instead of a single ID, define a range to scan | ||
| STS_ID_RANGE = range(1, SERVO_CNT) # Typical servo ID range (1-SERVO_CNT) | ||
|
|
||
| while 1: | ||
| print("Press any key to continue! (or press ESC to quit!)") | ||
| if getch() == chr(0x1b): | ||
| break | ||
| print("Scanning for %d servos..." % SERVO_CNT) | ||
| for STS_ID in STS_ID_RANGE: | ||
| sts_present_position, sts_present_speed, sts_comm_result, sts_error = packetHandler.ReadPosSpeed(STS_ID) | ||
| if sts_comm_result == COMM_SUCCESS: | ||
| print(f"[ID:{STS_ID:03d}] PresPos:{sts_present_position} PresSpd:{sts_present_speed}") | ||
| if sts_error != 0: | ||
| print(packetHandler.getRxPacketError(sts_error)) | ||
| print("Scan complete.") | ||
|
|
||
| # Close port | ||
| portHandler.closePort() |
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.