Skip to content

Commit e89266a

Browse files
committed
fix(franka cli): untangle home and gripper
- home and gripper are now separate in the cli - both no longer require setting of password
1 parent 0ae96d9 commit e89266a

4 files changed

Lines changed: 99 additions & 81 deletions

File tree

extensions/rcs_fr3/src/rcs_fr3/__main__.py

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,19 @@
2121
@fr3_app.command()
2222
def home(
2323
ip: Annotated[str, typer.Argument(help="IP of the robot")],
24-
shut: Annotated[bool, typer.Option("-s", help="Should the robot be shut down")] = False,
25-
unlock: Annotated[bool, typer.Option("-u", help="unlocks the robot")] = False,
26-
fh: Annotated[bool, typer.Option("-h", help="franka hand open")] = False,
2724
):
2825
"""Moves the FR3 to home position"""
29-
user, pw = load_creds_franka_desk()
30-
rcs_fr3.desk.home(ip, user, pw, shut, unlock, fh)
26+
rcs_fr3.desk.home(ip)
27+
28+
29+
# griper command
30+
@fr3_app.command()
31+
def gripper(
32+
ip: Annotated[str, typer.Argument(help="IP of the robot")],
33+
close_gripper: Annotated[bool, typer.Option("-c", help="close gripper")] = False,
34+
):
35+
"""Opens or closes the gripper"""
36+
rcs_fr3.desk.gripper(ip, close_gripper)
3137

3238

3339
@fr3_app.command()
@@ -36,8 +42,7 @@ def info(
3642
include_gripper: Annotated[bool, typer.Option("-g", help="includes gripper")] = False,
3743
):
3844
"""Prints info about the robots current joint position and end effector pose, optionally also the gripper."""
39-
user, pw = load_creds_franka_desk()
40-
rcs_fr3.desk.info(ip, user, pw, include_gripper)
45+
rcs_fr3.desk.info(ip, include_gripper)
4146

4247

4348
@fr3_app.command()

extensions/rcs_fr3/src/rcs_fr3/desk.py

Lines changed: 40 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -45,45 +45,49 @@ def load_creds_franka_desk(postfix: str = "") -> tuple[str, str]:
4545
return os.environ[username_key], os.environ[password_key]
4646

4747

48-
def home(ip: str, username: str, password: str, shut: bool, unlock: bool = False, fh: bool = False):
49-
with Desk.fci(ip, username, password, unlock=unlock):
48+
def home(ip: str):
49+
default_env = DefaultFR3HardwareEnv()
50+
default_env.ip = ip
51+
env_cfg = default_env.config()
52+
robot_cfg = env_cfg.robot_cfg
53+
robot_cfg.speed_factor = 0.2
54+
f = rcs_fr3.hw.Franka(robot_cfg)
55+
f.move_home()
56+
57+
58+
def gripper(ip: str, close_gripper: bool):
59+
60+
default_env = DefaultFR3HardwareEnv()
61+
default_env.ip = ip
62+
env_cfg = default_env.config()
63+
config_hand = env_cfg.gripper_cfg
64+
assert isinstance(config_hand, rcs_fr3.hw.FHConfig)
65+
g = rcs_fr3.hw.FrankaHand(config_hand)
66+
if close_gripper:
67+
g.shut()
68+
else:
69+
g.open()
70+
71+
72+
def info(ip: str, include_hand: bool = False):
73+
robot_cfg = rcs_fr3.hw.FR3Config(ip=ip)
74+
robot_cfg.speed_factor = 0.2
75+
f = rcs_fr3.hw.Franka(robot_cfg)
76+
print("Robot info:")
77+
print("Current cartesian position:")
78+
print(f.get_cartesian_position())
79+
print("Current joint position:")
80+
print(f.get_joint_position())
81+
if include_hand:
5082
default_env = DefaultFR3HardwareEnv()
5183
default_env.ip = ip
5284
env_cfg = default_env.config()
53-
robot_cfg = env_cfg.robot_cfg
54-
robot_cfg.speed_factor = 0.2
55-
f = rcs_fr3.hw.Franka(robot_cfg)
56-
if fh:
57-
config_hand = env_cfg.gripper_cfg
58-
assert isinstance(config_hand, rcs_fr3.hw.FHConfig)
59-
g = rcs_fr3.hw.FrankaHand(config_hand)
60-
if shut:
61-
g.shut()
62-
else:
63-
g.open()
64-
f.move_home()
65-
66-
67-
def info(ip: str, username: str, password: str, include_hand: bool = False):
68-
with Desk.fci(ip, username, password):
69-
robot_cfg = rcs_fr3.hw.FR3Config(ip=ip)
70-
robot_cfg.speed_factor = 0.2
71-
f = rcs_fr3.hw.Franka(robot_cfg)
72-
print("Robot info:")
73-
print("Current cartesian position:")
74-
print(f.get_cartesian_position())
75-
print("Current joint position:")
76-
print(f.get_joint_position())
77-
if include_hand:
78-
default_env = DefaultFR3HardwareEnv()
79-
default_env.ip = ip
80-
env_cfg = default_env.config()
81-
config_hand = env_cfg.gripper_cfg
82-
assert isinstance(config_hand, rcs_fr3.hw.FHConfig)
83-
g = rcs_fr3.hw.FrankaHand(config_hand)
84-
print("Gripper info:")
85-
print("Current normalized width:")
86-
print(g.get_normalized_width())
85+
config_hand = env_cfg.gripper_cfg
86+
assert isinstance(config_hand, rcs_fr3.hw.FHConfig)
87+
g = rcs_fr3.hw.FrankaHand(config_hand)
88+
print("Gripper info:")
89+
print("Current normalized width:")
90+
print(g.get_normalized_width())
8791

8892

8993
def lock(ip: str, username: str, password: str):

extensions/rcs_panda/src/rcs_panda/__main__.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,18 @@
2121
@panda_app.command()
2222
def home(
2323
ip: Annotated[str, typer.Argument(help="IP of the robot")],
24-
shut: Annotated[bool, typer.Option("-s", help="Should the robot be shut down")] = False,
25-
unlock: Annotated[bool, typer.Option("-u", help="unlocks the robot")] = False,
2624
):
2725
"""Moves the panda to home position"""
28-
user, pw = load_creds_franka_desk()
29-
rcs_panda.desk.home(ip, user, pw, shut, unlock)
26+
rcs_panda.desk.home(ip)
27+
28+
29+
@panda_app.command()
30+
def gripper(
31+
ip: Annotated[str, typer.Argument(help="IP of the robot")],
32+
close_gripper: Annotated[bool, typer.Option("-c", help="close gripper")] = False,
33+
):
34+
"""Opens or closes the gripper"""
35+
rcs_panda.desk.gripper(ip, close_gripper)
3036

3137

3238
@panda_app.command()
@@ -35,8 +41,7 @@ def info(
3541
include_gripper: Annotated[bool, typer.Option("-g", help="includes gripper")] = False,
3642
):
3743
"""Prints info about the robots current joint position and end effector pose, optionally also the gripper."""
38-
user, pw = load_creds_franka_desk()
39-
rcs_panda.desk.info(ip, user, pw, include_gripper)
44+
rcs_panda.desk.info(ip, include_gripper)
4045

4146

4247
@panda_app.command()

extensions/rcs_panda/src/rcs_panda/desk.py

Lines changed: 36 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -45,44 +45,48 @@ def load_creds_franka_desk(postfix: str = "") -> tuple[str, str]:
4545
return os.environ[username_key], os.environ[password_key]
4646

4747

48-
def home(ip: str, username: str, password: str, shut: bool, unlock: bool = False):
49-
with Desk.fci(ip, username, password, unlock=unlock):
48+
def home(ip: str):
49+
default_env = DefaultPandaHardwareEnv()
50+
default_env.ip = ip
51+
env_cfg = default_env.config()
52+
robot_cfg = env_cfg.robot_cfg
53+
robot_cfg.speed_factor = 0.2
54+
f = rcs_panda.hw.Franka(robot_cfg)
55+
f.move_home()
56+
57+
58+
def gripper(ip: str, close_gripper: bool):
59+
default_env = DefaultPandaHardwareEnv()
60+
default_env.ip = ip
61+
env_cfg = default_env.config()
62+
config_hand = env_cfg.gripper_cfg
63+
assert isinstance(config_hand, rcs_panda.hw.FHConfig)
64+
g = rcs_panda.hw.FrankaHand(config_hand)
65+
if close_gripper:
66+
g.shut()
67+
else:
68+
g.open()
69+
70+
71+
def info(ip: str, include_hand: bool = False):
72+
robot_cfg = rcs_panda.hw.PandaConfig(ip=ip)
73+
robot_cfg.speed_factor = 0.2
74+
f = rcs_panda.hw.Franka(robot_cfg)
75+
print("Robot info:")
76+
print("Current cartesian position:")
77+
print(f.get_cartesian_position())
78+
print("Current joint position:")
79+
print(f.get_joint_position())
80+
if include_hand:
5081
default_env = DefaultPandaHardwareEnv()
5182
default_env.ip = ip
5283
env_cfg = default_env.config()
53-
robot_cfg = env_cfg.robot_cfg
54-
robot_cfg.speed_factor = 0.2
55-
f = rcs_panda.hw.Franka(robot_cfg)
5684
config_hand = env_cfg.gripper_cfg
5785
assert isinstance(config_hand, rcs_panda.hw.FHConfig)
5886
g = rcs_panda.hw.FrankaHand(config_hand)
59-
if shut:
60-
g.shut()
61-
else:
62-
g.open()
63-
f.move_home()
64-
65-
66-
def info(ip: str, username: str, password: str, include_hand: bool = False):
67-
with Desk.fci(ip, username, password):
68-
robot_cfg = rcs_panda.hw.PandaConfig(ip=ip)
69-
robot_cfg.speed_factor = 0.2
70-
f = rcs_panda.hw.Franka(robot_cfg)
71-
print("Robot info:")
72-
print("Current cartesian position:")
73-
print(f.get_cartesian_position())
74-
print("Current joint position:")
75-
print(f.get_joint_position())
76-
if include_hand:
77-
default_env = DefaultPandaHardwareEnv()
78-
default_env.ip = ip
79-
env_cfg = default_env.config()
80-
config_hand = env_cfg.gripper_cfg
81-
assert isinstance(config_hand, rcs_panda.hw.FHConfig)
82-
g = rcs_panda.hw.FrankaHand(config_hand)
83-
print("Gripper info:")
84-
print("Current normalized width:")
85-
print(g.get_normalized_width())
87+
print("Gripper info:")
88+
print("Current normalized width:")
89+
print(g.get_normalized_width())
8690

8791

8892
def lock(ip: str, username: str, password: str):

0 commit comments

Comments
 (0)