From 30811d4041ec7d5de0d45847b4746cd21d9d388e Mon Sep 17 00:00:00 2001 From: Denys Bezmenov Date: Sat, 2 Nov 2024 18:17:35 -0700 Subject: [PATCH] adjustable current for start_calibration --- openlch/cli.py | 18 +++++++++++++++--- openlch/hal.py | 10 ++++++++-- 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/openlch/cli.py b/openlch/cli.py index 9c0555c..1b61ba5 100644 --- a/openlch/cli.py +++ b/openlch/cli.py @@ -143,14 +143,26 @@ def change_servo_id(old_id: int, new_id: int, ip: str) -> None: @cli.command() @click.argument("servo_id", type=int) +@click.option("--speed", "-s", type=int, default=300, + help="Calibration speed in degrees per second. Default: 300") +@click.option("--current", "-c", type=float, default=600.0, + help="Current threshold in mA to detect end stops. Default: 600.0") @click.argument("ip", default=DEFAULT_IP) -def start_calibration(servo_id: int, ip: str) -> None: - """Start calibration for a specific servo.""" +def start_calibration(servo_id: int, speed: int, current: float, ip: str) -> None: + """Start calibration for a specific servo. + + The calibration process will move the servo until it detects end stops based on current draw. + Use --speed to adjust movement speed and --current to adjust sensitivity.""" hal = HAL(ip) try: - success = hal.servo.start_calibration(servo_id) + success = hal.servo.start_calibration( + servo_id, + calibration_speed=speed, + current_threshold=current + ) if success: click.echo(f"Calibration started for servo {servo_id}") + click.echo(f"Speed: {speed} deg/s, Current threshold: {current} mA") else: click.echo(f"Failed to start calibration for servo {servo_id}") except Exception as e: diff --git a/openlch/hal.py b/openlch/hal.py index f2c0164..c9a6ea6 100644 --- a/openlch/hal.py +++ b/openlch/hal.py @@ -138,12 +138,14 @@ def change_id(self, old_id: int, new_id: int) -> bool: else: raise Exception(f"Error: {response.error.message} (Code: {response.error.code})") - def start_calibration(self, servo_id: int) -> bool: + def start_calibration(self, servo_id: int, calibration_speed: int = 300, current_threshold: float = 600.0) -> bool: """ Start calibration for a specific servo. Args: servo_id (int): The ID of the servo to calibrate. + calibration_speed (int, optional): Speed of calibration movement in degrees per second. Defaults to 300. + current_threshold (float, optional): Current threshold in mA to detect end stops. Defaults to 600.0. Returns: bool: True if calibration started successfully, False otherwise. @@ -151,7 +153,11 @@ def start_calibration(self, servo_id: int) -> bool: Raises: Exception: If there's an error starting the calibration. """ - request = hal_pb_pb2.ServoId(id=servo_id) + request = hal_pb_pb2.CalibrationRequest( + servo_id=servo_id, + calibration_speed=calibration_speed, + current_threshold=current_threshold + ) response = self.__stub.StartCalibration(request) if response.HasField('success'): return response.success