|
3 | 3 | import subprocess
|
4 | 4 | import click
|
5 | 5 | from .hal import HAL
|
| 6 | +from typing import List, Tuple |
6 | 7 |
|
7 | 8 | DEFAULT_IP = "192.168.42.1"
|
8 | 9 |
|
@@ -47,13 +48,13 @@ def ping(ip: str) -> None:
|
47 | 48 | @cli.command()
|
48 | 49 | @click.argument("ip", default=DEFAULT_IP)
|
49 | 50 | def get_positions(ip: str) -> None:
|
50 |
| - """Get current positions of all servos.""" |
| 51 | + """Get current positions and speeds of all servos.""" |
51 | 52 | hal = HAL(ip)
|
52 | 53 | try:
|
53 | 54 | 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}") |
57 | 58 | except Exception as e:
|
58 | 59 | click.echo(f"An error occurred: {str(e)}")
|
59 | 60 | finally:
|
@@ -231,5 +232,41 @@ def get_video_stream_urls(ip: str) -> None:
|
231 | 232 | finally:
|
232 | 233 | hal.close()
|
233 | 234 |
|
| 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 | + |
234 | 271 | if __name__ == "__main__":
|
235 | 272 | cli()
|
0 commit comments