Skip to content

Commit

Permalink
adjustable current for start_calibration
Browse files Browse the repository at this point in the history
  • Loading branch information
hatomist committed Nov 3, 2024
1 parent e7cc8f3 commit 30811d4
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
18 changes: 15 additions & 3 deletions openlch/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
10 changes: 8 additions & 2 deletions openlch/hal.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,20 +138,26 @@ 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.
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
Expand Down

0 comments on commit 30811d4

Please sign in to comment.