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
Prev Previous commit
Next Next commit
Calibrate servos on boot
  • Loading branch information
danic85 committed Oct 4, 2025
commit 69f2d7c472862d142bbb31768ae3a58578a94164
12 changes: 10 additions & 2 deletions config/servo_waveshare.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@ servos:
enabled: true
path: "modules.actuators.bus_servo.servo.Servo" # Include class name here
instances:
- name: "leg_r_tilt"
model: 'ST3215'
id: 1
range: [744, 3136]
start: 2048
poses:
- stand: 1269
- sit: 2048
- centre: 2048
- name: "leg_r_hip"
model: 'ST3215'
id: 3
Expand All @@ -20,10 +29,9 @@ servos:
- stand: 2111
- sit: 723
- centre: 2048
# configure_on_boot: true
- name: "leg_r_ankle"
model: 'ST3215'
id: 1
id: 6
range: [0, 4095]
start: 2048
- name: "neck_pan"
Expand Down
2 changes: 1 addition & 1 deletion docs/BusServo.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Once the start position and range are set, move the flag to the next servo and r

Finally, remove the `configure_on_boot` flag from the configuration file and re-run the program to start using the servos with their configured positions.

## Subsriptions
## Subscriptions

The `Servo` class subscribes to the following topics:
`servo:<identifier>:mv` - to move the servo to a specific position relative to it's current position.
Expand Down
4 changes: 2 additions & 2 deletions modules/actuators/bus_servo/STServo_examples/read_all.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
import os
import sys


# Add parent directory to sys.path to import STservo_sdk from sibling folder
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))

if os.name == 'nt':
import msvcrt
Expand All @@ -29,7 +30,6 @@ def getch():
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

# Default setting
Expand Down
3 changes: 2 additions & 1 deletion modules/actuators/bus_servo/STServo_examples/read_write.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ def getch():
termios.tcsetattr(fd, termios.TCSADRAIN, old_settings)
return ch

sys.path.append("..")
# Add parent directory to sys.path to import STservo_sdk from sibling folder
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))
from STservo_sdk import * # Uses STServo SDK library
Comment thread
danic85 marked this conversation as resolved.
Resolved

# Default setting
Expand Down
3 changes: 2 additions & 1 deletion modules/actuators/bus_servo/STServo_examples/write.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ def getch():
termios.tcsetattr(fd, termios.TCSADRAIN, old_settings)
return ch

sys.path.append("..")
# Add parent directory to sys.path to import STservo_sdk from sibling folder
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))
from STservo_sdk import * # Uses STServo SDK library
Comment thread
danic85 marked this conversation as resolved.
Resolved

# Default setting
Expand Down
28 changes: 21 additions & 7 deletions modules/actuators/bus_servo/servo.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def __init__(self, **kwargs):
self.poses = kwargs.get('poses') # Dictionary of poses
self.baudrate = kwargs.get('baudrate', 1000000)
self.port = kwargs.get('port', '/dev/ttyACM0')
self.configure_on_boot = kwargs.get('configure_on_boot', False) # Loop to show position for manual configuration
self.calibrate_on_boot = kwargs.get('calibrate_on_boot', True) # Loop to show position for manual configuration
self.pos = self.start
self.speed = 2400 # 3073
self.acceleration = 50
Expand Down Expand Up @@ -96,9 +96,8 @@ def setup_messaging(self):
self.subscribe('servo:' + self.identifier + ':mv', self.move_relative)
self.subscribe('system/exit', self.exit)

if self.configure_on_boot:
while True:
self.get_position() # Log will show current position repeatedly to help with manual configuration
if self.calibrate_on_boot:
self.calibrate() # 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

Expand Down Expand Up @@ -149,7 +148,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" % (STS_ID, 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')
Expand Down Expand Up @@ -222,8 +221,23 @@ def get_pose_value(self, pose_name):
return pose[pose_name]
return None # or raise an exception if preferred



def calibrate(self):
"""
Move each servo to capture min and max positions for calibration.
"""
self.log(f"Move servo {self.identifier} to minimum position and press any key...")
getch() # Waits for a single key press
min = self.get_position()
self.log(f"Captured minimum position: {min}")
self.log(f"Move servo {self.identifier} to maximum position and press any key...")
getch() # Waits for a single key press
max = self.get_position()
self.log(f"Captured maximum position: {max}")
self.range = (min, max)
if 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}")



Expand Down