Skip to content

Commit 30811d4

Browse files
committed
adjustable current for start_calibration
1 parent e7cc8f3 commit 30811d4

File tree

2 files changed

+23
-5
lines changed

2 files changed

+23
-5
lines changed

openlch/cli.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -143,14 +143,26 @@ def change_servo_id(old_id: int, new_id: int, ip: str) -> None:
143143

144144
@cli.command()
145145
@click.argument("servo_id", type=int)
146+
@click.option("--speed", "-s", type=int, default=300,
147+
help="Calibration speed in degrees per second. Default: 300")
148+
@click.option("--current", "-c", type=float, default=600.0,
149+
help="Current threshold in mA to detect end stops. Default: 600.0")
146150
@click.argument("ip", default=DEFAULT_IP)
147-
def start_calibration(servo_id: int, ip: str) -> None:
148-
"""Start calibration for a specific servo."""
151+
def start_calibration(servo_id: int, speed: int, current: float, ip: str) -> None:
152+
"""Start calibration for a specific servo.
153+
154+
The calibration process will move the servo until it detects end stops based on current draw.
155+
Use --speed to adjust movement speed and --current to adjust sensitivity."""
149156
hal = HAL(ip)
150157
try:
151-
success = hal.servo.start_calibration(servo_id)
158+
success = hal.servo.start_calibration(
159+
servo_id,
160+
calibration_speed=speed,
161+
current_threshold=current
162+
)
152163
if success:
153164
click.echo(f"Calibration started for servo {servo_id}")
165+
click.echo(f"Speed: {speed} deg/s, Current threshold: {current} mA")
154166
else:
155167
click.echo(f"Failed to start calibration for servo {servo_id}")
156168
except Exception as e:

openlch/hal.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,20 +138,26 @@ def change_id(self, old_id: int, new_id: int) -> bool:
138138
else:
139139
raise Exception(f"Error: {response.error.message} (Code: {response.error.code})")
140140

141-
def start_calibration(self, servo_id: int) -> bool:
141+
def start_calibration(self, servo_id: int, calibration_speed: int = 300, current_threshold: float = 600.0) -> bool:
142142
"""
143143
Start calibration for a specific servo.
144144
145145
Args:
146146
servo_id (int): The ID of the servo to calibrate.
147+
calibration_speed (int, optional): Speed of calibration movement in degrees per second. Defaults to 300.
148+
current_threshold (float, optional): Current threshold in mA to detect end stops. Defaults to 600.0.
147149
148150
Returns:
149151
bool: True if calibration started successfully, False otherwise.
150152
151153
Raises:
152154
Exception: If there's an error starting the calibration.
153155
"""
154-
request = hal_pb_pb2.ServoId(id=servo_id)
156+
request = hal_pb_pb2.CalibrationRequest(
157+
servo_id=servo_id,
158+
calibration_speed=calibration_speed,
159+
current_threshold=current_threshold
160+
)
155161
response = self.__stub.StartCalibration(request)
156162
if response.HasField('success'):
157163
return response.success

0 commit comments

Comments
 (0)