Skip to content
Merged
Show file tree
Hide file tree
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 Jul 12, 2025
d18189c
Update config
danic85 Jul 12, 2025
60d524a
Added SC servo examples + compatibility
danic85 Jul 13, 2025
3e4dfc0
Configure initial positions
danic85 Jul 14, 2025
0be65a3
Allow other poses to be stored and accessed
danic85 Jul 14, 2025
91fac95
Added change_id script
danic85 Aug 3, 2025
69f2d7c
Calibrate servos on boot
danic85 Oct 4, 2025
9a57f8a
adjustments
danic85 Oct 4, 2025
0cf906e
Dynamic servo calibration + center on change_id
danic85 Oct 5, 2025
8d62b54
Controller support and WIP recording
danic85 Dec 13, 2025
f02d0db
Working with Pi
danic85 Dec 13, 2025
b052ed0
Adjust config
danic85 Dec 13, 2025
6841f63
Cleanup
danic85 Dec 14, 2025
c1ed384
Working input recorder
danic85 Dec 14, 2025
5e503e5
Support servo control (WIP - calibration needed)
danic85 Dec 14, 2025
008c369
Callibration + allow modules to be disabled on test environments
danic85 Dec 15, 2025
af0fdb2
Disable test
danic85 Dec 15, 2025
40040c8
Add documentation and tests
danic85 Dec 16, 2025
f645caa
Fix test
danic85 Dec 16, 2025
8a22781
Timeout controller connection after 30 seconds
danic85 Dec 16, 2025
d81c07c
Enable on robot
danic85 Dec 16, 2025
6a84d43
Fix for environment input to resolve pi issue
danic85 Dec 17, 2025
4803d58
Calibrate new leg position
danic85 Dec 17, 2025
dc4cb27
Improvements to gamepad controller modules. Temperature alert in disp…
danic85 Dec 18, 2025
d48ccd8
Fix tests
danic85 Dec 18, 2025
4a5a0ee
Fixes and improvements to loop and temperature management
danic85 Dec 21, 2025
5349956
Fix tests
danic85 Dec 21, 2025
cd4331b
Resolve PR comments
danic85 Dec 21, 2025
File filter

Filter by extension

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
danic85 committed Jul 12, 2025
commit 4c8c7d98c07bad2b57b90e58c97b924ae64fd14f
131 changes: 131 additions & 0 deletions modules/actuators/bus_servo/STServo_examples/change_id.py
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 *
Comment thread
danic85 marked this conversation as resolved.
Resolved

# 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()
76 changes: 76 additions & 0 deletions modules/actuators/bus_servo/STServo_examples/ping.py
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
Comment thread
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()
80 changes: 80 additions & 0 deletions modules/actuators/bus_servo/STServo_examples/read.py
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
Comment thread
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()
84 changes: 84 additions & 0 deletions modules/actuators/bus_servo/STServo_examples/read_all.py
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()
Loading