From e89266a6542111e83ccb82f2bd7ae66c380f7fdf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tobias=20J=C3=BClg?= Date: Mon, 27 Jul 2026 20:42:41 -0700 Subject: [PATCH] fix(franka cli): untangle home and gripper - home and gripper are now separate in the cli - both no longer require setting of password --- extensions/rcs_fr3/src/rcs_fr3/__main__.py | 19 +++-- extensions/rcs_fr3/src/rcs_fr3/desk.py | 76 ++++++++++--------- .../rcs_panda/src/rcs_panda/__main__.py | 17 +++-- extensions/rcs_panda/src/rcs_panda/desk.py | 68 +++++++++-------- 4 files changed, 99 insertions(+), 81 deletions(-) diff --git a/extensions/rcs_fr3/src/rcs_fr3/__main__.py b/extensions/rcs_fr3/src/rcs_fr3/__main__.py index 8382efff..daa5179b 100644 --- a/extensions/rcs_fr3/src/rcs_fr3/__main__.py +++ b/extensions/rcs_fr3/src/rcs_fr3/__main__.py @@ -21,13 +21,19 @@ @fr3_app.command() def home( ip: Annotated[str, typer.Argument(help="IP of the robot")], - shut: Annotated[bool, typer.Option("-s", help="Should the robot be shut down")] = False, - unlock: Annotated[bool, typer.Option("-u", help="unlocks the robot")] = False, - fh: Annotated[bool, typer.Option("-h", help="franka hand open")] = False, ): """Moves the FR3 to home position""" - user, pw = load_creds_franka_desk() - rcs_fr3.desk.home(ip, user, pw, shut, unlock, fh) + rcs_fr3.desk.home(ip) + + +# griper command +@fr3_app.command() +def gripper( + ip: Annotated[str, typer.Argument(help="IP of the robot")], + close_gripper: Annotated[bool, typer.Option("-c", help="close gripper")] = False, +): + """Opens or closes the gripper""" + rcs_fr3.desk.gripper(ip, close_gripper) @fr3_app.command() @@ -36,8 +42,7 @@ def info( include_gripper: Annotated[bool, typer.Option("-g", help="includes gripper")] = False, ): """Prints info about the robots current joint position and end effector pose, optionally also the gripper.""" - user, pw = load_creds_franka_desk() - rcs_fr3.desk.info(ip, user, pw, include_gripper) + rcs_fr3.desk.info(ip, include_gripper) @fr3_app.command() diff --git a/extensions/rcs_fr3/src/rcs_fr3/desk.py b/extensions/rcs_fr3/src/rcs_fr3/desk.py index 5636a9f2..32d6c0ed 100644 --- a/extensions/rcs_fr3/src/rcs_fr3/desk.py +++ b/extensions/rcs_fr3/src/rcs_fr3/desk.py @@ -45,45 +45,49 @@ def load_creds_franka_desk(postfix: str = "") -> tuple[str, str]: return os.environ[username_key], os.environ[password_key] -def home(ip: str, username: str, password: str, shut: bool, unlock: bool = False, fh: bool = False): - with Desk.fci(ip, username, password, unlock=unlock): +def home(ip: str): + default_env = DefaultFR3HardwareEnv() + default_env.ip = ip + env_cfg = default_env.config() + robot_cfg = env_cfg.robot_cfg + robot_cfg.speed_factor = 0.2 + f = rcs_fr3.hw.Franka(robot_cfg) + f.move_home() + + +def gripper(ip: str, close_gripper: bool): + + default_env = DefaultFR3HardwareEnv() + default_env.ip = ip + env_cfg = default_env.config() + config_hand = env_cfg.gripper_cfg + assert isinstance(config_hand, rcs_fr3.hw.FHConfig) + g = rcs_fr3.hw.FrankaHand(config_hand) + if close_gripper: + g.shut() + else: + g.open() + + +def info(ip: str, include_hand: bool = False): + robot_cfg = rcs_fr3.hw.FR3Config(ip=ip) + robot_cfg.speed_factor = 0.2 + f = rcs_fr3.hw.Franka(robot_cfg) + print("Robot info:") + print("Current cartesian position:") + print(f.get_cartesian_position()) + print("Current joint position:") + print(f.get_joint_position()) + if include_hand: default_env = DefaultFR3HardwareEnv() default_env.ip = ip env_cfg = default_env.config() - robot_cfg = env_cfg.robot_cfg - robot_cfg.speed_factor = 0.2 - f = rcs_fr3.hw.Franka(robot_cfg) - if fh: - config_hand = env_cfg.gripper_cfg - assert isinstance(config_hand, rcs_fr3.hw.FHConfig) - g = rcs_fr3.hw.FrankaHand(config_hand) - if shut: - g.shut() - else: - g.open() - f.move_home() - - -def info(ip: str, username: str, password: str, include_hand: bool = False): - with Desk.fci(ip, username, password): - robot_cfg = rcs_fr3.hw.FR3Config(ip=ip) - robot_cfg.speed_factor = 0.2 - f = rcs_fr3.hw.Franka(robot_cfg) - print("Robot info:") - print("Current cartesian position:") - print(f.get_cartesian_position()) - print("Current joint position:") - print(f.get_joint_position()) - if include_hand: - default_env = DefaultFR3HardwareEnv() - default_env.ip = ip - env_cfg = default_env.config() - config_hand = env_cfg.gripper_cfg - assert isinstance(config_hand, rcs_fr3.hw.FHConfig) - g = rcs_fr3.hw.FrankaHand(config_hand) - print("Gripper info:") - print("Current normalized width:") - print(g.get_normalized_width()) + config_hand = env_cfg.gripper_cfg + assert isinstance(config_hand, rcs_fr3.hw.FHConfig) + g = rcs_fr3.hw.FrankaHand(config_hand) + print("Gripper info:") + print("Current normalized width:") + print(g.get_normalized_width()) def lock(ip: str, username: str, password: str): diff --git a/extensions/rcs_panda/src/rcs_panda/__main__.py b/extensions/rcs_panda/src/rcs_panda/__main__.py index b9e65e4e..b4550dbf 100644 --- a/extensions/rcs_panda/src/rcs_panda/__main__.py +++ b/extensions/rcs_panda/src/rcs_panda/__main__.py @@ -21,12 +21,18 @@ @panda_app.command() def home( ip: Annotated[str, typer.Argument(help="IP of the robot")], - shut: Annotated[bool, typer.Option("-s", help="Should the robot be shut down")] = False, - unlock: Annotated[bool, typer.Option("-u", help="unlocks the robot")] = False, ): """Moves the panda to home position""" - user, pw = load_creds_franka_desk() - rcs_panda.desk.home(ip, user, pw, shut, unlock) + rcs_panda.desk.home(ip) + + +@panda_app.command() +def gripper( + ip: Annotated[str, typer.Argument(help="IP of the robot")], + close_gripper: Annotated[bool, typer.Option("-c", help="close gripper")] = False, +): + """Opens or closes the gripper""" + rcs_panda.desk.gripper(ip, close_gripper) @panda_app.command() @@ -35,8 +41,7 @@ def info( include_gripper: Annotated[bool, typer.Option("-g", help="includes gripper")] = False, ): """Prints info about the robots current joint position and end effector pose, optionally also the gripper.""" - user, pw = load_creds_franka_desk() - rcs_panda.desk.info(ip, user, pw, include_gripper) + rcs_panda.desk.info(ip, include_gripper) @panda_app.command() diff --git a/extensions/rcs_panda/src/rcs_panda/desk.py b/extensions/rcs_panda/src/rcs_panda/desk.py index 724f3d31..f64f8d96 100644 --- a/extensions/rcs_panda/src/rcs_panda/desk.py +++ b/extensions/rcs_panda/src/rcs_panda/desk.py @@ -45,44 +45,48 @@ def load_creds_franka_desk(postfix: str = "") -> tuple[str, str]: return os.environ[username_key], os.environ[password_key] -def home(ip: str, username: str, password: str, shut: bool, unlock: bool = False): - with Desk.fci(ip, username, password, unlock=unlock): +def home(ip: str): + default_env = DefaultPandaHardwareEnv() + default_env.ip = ip + env_cfg = default_env.config() + robot_cfg = env_cfg.robot_cfg + robot_cfg.speed_factor = 0.2 + f = rcs_panda.hw.Franka(robot_cfg) + f.move_home() + + +def gripper(ip: str, close_gripper: bool): + default_env = DefaultPandaHardwareEnv() + default_env.ip = ip + env_cfg = default_env.config() + config_hand = env_cfg.gripper_cfg + assert isinstance(config_hand, rcs_panda.hw.FHConfig) + g = rcs_panda.hw.FrankaHand(config_hand) + if close_gripper: + g.shut() + else: + g.open() + + +def info(ip: str, include_hand: bool = False): + robot_cfg = rcs_panda.hw.PandaConfig(ip=ip) + robot_cfg.speed_factor = 0.2 + f = rcs_panda.hw.Franka(robot_cfg) + print("Robot info:") + print("Current cartesian position:") + print(f.get_cartesian_position()) + print("Current joint position:") + print(f.get_joint_position()) + if include_hand: default_env = DefaultPandaHardwareEnv() default_env.ip = ip env_cfg = default_env.config() - robot_cfg = env_cfg.robot_cfg - robot_cfg.speed_factor = 0.2 - f = rcs_panda.hw.Franka(robot_cfg) config_hand = env_cfg.gripper_cfg assert isinstance(config_hand, rcs_panda.hw.FHConfig) g = rcs_panda.hw.FrankaHand(config_hand) - if shut: - g.shut() - else: - g.open() - f.move_home() - - -def info(ip: str, username: str, password: str, include_hand: bool = False): - with Desk.fci(ip, username, password): - robot_cfg = rcs_panda.hw.PandaConfig(ip=ip) - robot_cfg.speed_factor = 0.2 - f = rcs_panda.hw.Franka(robot_cfg) - print("Robot info:") - print("Current cartesian position:") - print(f.get_cartesian_position()) - print("Current joint position:") - print(f.get_joint_position()) - if include_hand: - default_env = DefaultPandaHardwareEnv() - default_env.ip = ip - env_cfg = default_env.config() - config_hand = env_cfg.gripper_cfg - assert isinstance(config_hand, rcs_panda.hw.FHConfig) - g = rcs_panda.hw.FrankaHand(config_hand) - print("Gripper info:") - print("Current normalized width:") - print(g.get_normalized_width()) + print("Gripper info:") + print("Current normalized width:") + print(g.get_normalized_width()) def lock(ip: str, username: str, password: str):