Skip to content

Commit 9ac40bd

Browse files
committed
cli for torque
1 parent 3782190 commit 9ac40bd

File tree

2 files changed

+42
-5
lines changed

2 files changed

+42
-5
lines changed

openlch/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
__version__ = "0.6.0"
1+
__version__ = "0.6.1"
22

33
from .hal import HAL

openlch/cli.py

Lines changed: 41 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import subprocess
44
import click
55
from .hal import HAL
6+
from typing import List, Tuple
67

78
DEFAULT_IP = "192.168.42.1"
89

@@ -47,13 +48,13 @@ def ping(ip: str) -> None:
4748
@cli.command()
4849
@click.argument("ip", default=DEFAULT_IP)
4950
def get_positions(ip: str) -> None:
50-
"""Get current positions of all servos."""
51+
"""Get current positions and speeds of all servos."""
5152
hal = HAL(ip)
5253
try:
5354
positions = hal.servo.get_positions()
54-
click.echo("Current positions:")
55-
for id, position in positions:
56-
click.echo(f"Servo {id}: {position}")
55+
click.echo("Current positions and speeds:")
56+
for id, position, speed in positions:
57+
click.echo(f"Servo {id}: Position = {position:.2f}, Speed = {speed:.2f}")
5758
except Exception as e:
5859
click.echo(f"An error occurred: {str(e)}")
5960
finally:
@@ -231,5 +232,41 @@ def get_video_stream_urls(ip: str) -> None:
231232
finally:
232233
hal.close()
233234

235+
@cli.command()
236+
@click.option("--settings", "-s", type=(int, float), multiple=True, required=True,
237+
help="Servo ID and torque value pairs (e.g., -s 1 0.5 -s 2 0.7)")
238+
@click.argument("ip", default=DEFAULT_IP)
239+
def set_torque(settings: List[Tuple[int, float]], ip: str) -> None:
240+
"""Set torque for multiple servos."""
241+
hal = HAL(ip)
242+
try:
243+
hal.servo.set_torque(settings)
244+
click.echo("Torque settings applied successfully:")
245+
for servo_id, torque in settings:
246+
click.echo(f"Servo {servo_id}: Torque = {torque:.2f}")
247+
except Exception as e:
248+
click.echo(f"An error occurred: {str(e)}")
249+
finally:
250+
hal.close()
251+
252+
@cli.command()
253+
@click.option("--settings", "-s", type=(int, click.Choice(['true', 'false'])), multiple=True, required=True,
254+
help="Servo ID and enable status pairs (e.g., -s 1 true -s 2 false)")
255+
@click.argument("ip", default=DEFAULT_IP)
256+
def set_torque_enable(settings: List[Tuple[int, str]], ip: str) -> None:
257+
"""Enable or disable torque for multiple servos."""
258+
hal = HAL(ip)
259+
try:
260+
# Convert 'true'/'false' strings to boolean values
261+
bool_settings = [(id, status.lower() == 'true') for id, status in settings]
262+
hal.servo.set_torque_enable(bool_settings)
263+
click.echo("Torque enable settings applied successfully:")
264+
for servo_id, status in bool_settings:
265+
click.echo(f"Servo {servo_id}: Torque {'enabled' if status else 'disabled'}")
266+
except Exception as e:
267+
click.echo(f"An error occurred: {str(e)}")
268+
finally:
269+
hal.close()
270+
234271
if __name__ == "__main__":
235272
cli()

0 commit comments

Comments
 (0)