Skip to content

Commit 639d111

Browse files
authored
Merge pull request #53 from 2lian/dev_shami
merge dev_shami into main
2 parents 7a4f7c0 + 1041439 commit 639d111

File tree

15 files changed

+630
-21
lines changed

15 files changed

+630
-21
lines changed

launch_stack.bash

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ colcon build --cmake-args -Wno-dev
77
# colcon test --packages-select easy_robot_control
88
# colcon test-result --verbose
99
. install/setup.bash
10+
. "${ROS2_INTERFACE_INSTALL_PATH}"/setup.bash
1011
export RCUTILS_CONSOLE_OUTPUT_FORMAT="{message}"
1112
export NUMBA_CACHE_DIR="./numba_cache" # this will compile numba in a permanant file
1213

13-
ros2 launch moonbot_zero_tuto myrobot.launch.py MS_up_to_level:=4
14+
ros2 launch realman_interface realman_75.py MS_up_to_level:=3

src/easy_robot_control/easy_robot_control/EliaNode.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,7 @@ def __init__(self, name: str):
367367
def wait_for_lower_level(
368368
self, more_services: Iterable[str] = set(), all_requiered: bool = False
369369
):
370-
"""You cdan overload this or use the launch setting to wait for a service"""
370+
"""You can overload this or use the launch setting to wait for a service"""
371371
self.declare_parameter("services_to_wait", [""])
372372
from_prams = set(
373373
self.get_parameter("services_to_wait")

src/easy_robot_control/easy_robot_control/gait_key_dev.py

Lines changed: 166 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,8 @@
6262
# VVV Settings to tweek
6363
#
6464
# LEGNUMS_TO_SCAN = [2,4]
65-
LEGNUMS_TO_SCAN = [1, 2, 3, 4]
66-
TRANSLATION_SPEED = 50 # mm/s ; full stick will send this speed
65+
LEGNUMS_TO_SCAN = [75, 16]
66+
TRANSLATION_SPEED = 30 # mm/s ; full stick will send this speed
6767
ROTATION_SPEED = np.deg2rad(5) # rad/s ; full stick will send this angular speed
6868
ALLOWED_DELTA_XYZ = 50 # mm ; ik2 commands cannot be further than ALOWED_DELTA_XYZ away
6969
# from the current tip position
@@ -81,7 +81,7 @@
8181

8282
TRICYCLE_FLIPPED: List[int] = []
8383

84-
MAX_JOINT_SPEED = 0.15
84+
MAX_JOINT_SPEED = 0.3
8585
#
8686
# ^^^ Settings to tweek
8787

@@ -93,7 +93,9 @@
9393
# type def V
9494
ANY: Final[str] = "ANY"
9595
ALWAYS: Final[str] = "ALWAYS"
96-
KeyCodeModifier = Tuple[int, Union[int, Literal["ANY"]]] # keyboard input: key + modifier
96+
KeyCodeModifier = Tuple[
97+
int, Union[int, Literal["ANY"]]
98+
] # keyboard input: key + modifier
9799
JoyBits = int # 32 bits to represent all buttons pressed or not
98100
ButtonName = Literal[ # type with all possible buttons
99101
"NONE",
@@ -126,7 +128,9 @@
126128
Literal["ALWAYS"], # functions associated with "ALWAYS" string will always execute
127129
]
128130
NakedCall = Callable[[], Any]
129-
InputMap = Dict[UserInput, List[NakedCall]] # User input are linked to a list of function
131+
InputMap = Dict[
132+
UserInput, List[NakedCall]
133+
] # User input are linked to a list of function
130134

131135
# Namespace
132136
operator = str(environ.get("OPERATOR"))
@@ -148,6 +152,51 @@
148152
}
149153
ALPHAB_TO_STICKER = {v: k for k, v in STICKER_TO_ALPHAB.items()}
150154

155+
STICKER_TO_ALPHAB_LEG75: Dict[int, int] = {
156+
1: 0,
157+
2: 1,
158+
3: 2,
159+
4: 3,
160+
5: 4,
161+
6: 5,
162+
7: 6,
163+
}
164+
165+
ALPHAB_TO_STICKER_LEG75 = {v: k for k, v in STICKER_TO_ALPHAB_LEG75.items()}
166+
167+
STICKER_TO_ALPHAB_LEG16_ARM: Dict[int, int] = {
168+
1: 2,
169+
2: 1,
170+
3: 0, # first 1 to 6 is remap for launch without the gripper
171+
4: 3,
172+
5: 4,
173+
6: 5,
174+
# 1: 13,
175+
# 2: 12,
176+
# 3: 0, # second 1 to 6 is remap for launch with gripper
177+
# 4: 14,
178+
# 5: 15,
179+
# 6: 16,
180+
}
181+
182+
ALPHAB_TO_STICKER_LEG16_ARM = {v: k for k, v in STICKER_TO_ALPHAB_LEG16_ARM.items()}
183+
184+
STICKER_TO_ALPHAB_LEG16_GRIP: Dict[int, int] = {
185+
1: 1,
186+
2: 2,
187+
3: 3,
188+
4: 4,
189+
5: 5, # gripper joints (too many)
190+
6: 6,
191+
7: 7,
192+
8: 8,
193+
9: 9,
194+
# 10: 10, # palm finger 1
195+
# 11: 11, # palm finger 2
196+
}
197+
198+
ALPHAB_TO_STICKER_LEG16_GRIP = {v: k for k, v in STICKER_TO_ALPHAB_LEG16_GRIP.items()}
199+
151200
BUTT_BITS: Dict[ButtonName, int] = { # button name to bit position
152201
# butts
153202
"x": 0,
@@ -177,7 +226,9 @@
177226
}
178227
BITS_BUTT: Dict[int, ButtonName] = {v: k for k, v in BUTT_BITS.items()}
179228
# Bitmask of each button
180-
BUTT_INTS: Dict[ButtonName, JoyBits] = {butt: 1 << bit for butt, bit in BUTT_BITS.items()}
229+
BUTT_INTS: Dict[ButtonName, JoyBits] = {
230+
butt: 1 << bit for butt, bit in BUTT_BITS.items()
231+
}
181232
BUTT_INTS["NONE"] = 0
182233
INTS_BUTT: Dict[JoyBits, ButtonName] = {v: k for k, v in BUTT_INTS.items()}
183234

@@ -359,7 +410,10 @@ def __init__(self, name: str = "keygait_node"):
359410
self.Alias = "K"
360411

361412
self.leg_aliveCLI: Dict[int, Client] = dict(
362-
[(l, self.create_client(Empty, f"leg{l}/leg_alive")) for l in LEGNUMS_TO_SCAN]
413+
[
414+
(l, self.create_client(Empty, f"leg{l}/leg_alive"))
415+
for l in LEGNUMS_TO_SCAN
416+
]
363417
)
364418
self.legs: Dict[int, Leg] = {}
365419

@@ -377,7 +431,6 @@ def __init__(self, name: str = "keygait_node"):
377431
)
378432
self.next_scan_ind = 0
379433
self.selected_joint: Union[int, str, None] = None
380-
self.selected_joint_joy: Union[int, None] = None
381434
self.selected_legs: List[int] = []
382435

383436
self.main_map: Final[InputMap] = (
@@ -421,12 +474,17 @@ def __init__(self, name: str = "keygait_node"):
421474

422475
self.joint_timer = self.create_timer(0.1, self.joint_control_joy)
423476

477+
self.launch_case = "HERO"
478+
self.joint_mapping = STICKER_TO_ALPHAB
479+
424480
# config
425481
self.config_index = 0 # current
426482
self.num_configs = 3 # total configs
427483
self.prev_config_button = False # prev config
428484

429-
self.sendTargetBody: Client = self.create_client(SendTargetBody, "go2_targetbody")
485+
self.sendTargetBody: Client = self.create_client(
486+
SendTargetBody, "go2_targetbody"
487+
)
430488
self.execute_in_cbk_group(self.makeTBclient, MutuallyExclusiveCallbackGroup())
431489

432490
self.recover_allCLI = [
@@ -488,6 +546,29 @@ def leg_scanTMRCBK(self):
488546

489547
return # stops scanning if all fails
490548

549+
def refresh_joint_mapping(self):
550+
"""joint mapping based on leg number (realguy or MoonbotH)"""
551+
if 75 in self.selected_legs:
552+
self.joint_mapping = STICKER_TO_ALPHAB_LEG75
553+
self.launch_case = "75"
554+
elif 16 in self.selected_legs:
555+
self.joint_mapping = STICKER_TO_ALPHAB_LEG16_ARM
556+
self.launch_case = "16"
557+
else:
558+
self.joint_mapping = STICKER_TO_ALPHAB
559+
self.launch_case = "HERO"
560+
# self.pinfo(self.joint_mapping)
561+
562+
def switch_to_grip_ur16(self):
563+
"""joint mapping based on leg number (realguy or MoonbotH)"""
564+
if 16 in self.selected_legs:
565+
self.joint_mapping = STICKER_TO_ALPHAB_LEG16_GRIP
566+
self.launch_case = "16"
567+
# self.pinfo(self.joint_mapping)
568+
else:
569+
self.joint_mapping = STICKER_TO_ALPHAB
570+
self.launch_case = "HERO"
571+
491572
@error_catcher
492573
def key_upSUBCBK(self, msg: Key):
493574
"""Executes when keyboard released"""
@@ -712,7 +793,30 @@ def dragon_back_right(self):
712793
main_leg.move(quat=rot, blocking=False)
713794

714795
def zero_without_grippers(self):
715-
angs = {
796+
angs_75 = {
797+
0: 0.0,
798+
1: 1.5708,
799+
2: 0.0,
800+
3: -1.5708,
801+
4: 0.0,
802+
5: 1.5708,
803+
6: 0.0,
804+
}
805+
angs_16 = {
806+
0: -1.5708,
807+
1: 0.0,
808+
2: 0.0,
809+
3: 0.0,
810+
4: 0.0,
811+
5: 0.0,
812+
# 13: 0.0,
813+
# 12: 0.0,
814+
# 0: -1.5708,
815+
# 14: 0.0,
816+
# 15: 0.0,
817+
# 16: 0.0,
818+
}
819+
angs_hero = {
716820
0: 0.0,
717821
3: 0.0,
718822
4: 0.0,
@@ -721,6 +825,12 @@ def zero_without_grippers(self):
721825
7: 0.0,
722826
8: 0.0,
723827
}
828+
if self.launch_case == "75":
829+
angs = angs_75
830+
elif self.launch_case == "16":
831+
angs = angs_16
832+
else:
833+
angs = angs_hero
724834
for leg in self.get_active_leg():
725835
# for leg in [self.legs[4]]:
726836
for num, ang in angs.items():
@@ -913,6 +1023,10 @@ def joy_released(self, button_name: ButtonName):
9131023
self.stop_all_joints()
9141024
# self.pinfo(f"released: {dic_key}")
9151025

1026+
def get_joint_index(self, selected_joint: int) -> Optional[int]:
1027+
# self.pinfo(f"yes: {self.joint_mapping}")
1028+
return self.joint_mapping.get(selected_joint)
1029+
9161030
@error_catcher
9171031
def joySUBCBK(self, msg: Joy):
9181032
"""Processes incomming joy messages.
@@ -938,7 +1052,6 @@ def joySUBCBK(self, msg: Joy):
9381052
return
9391053

9401054
def joint_control_joy(self):
941-
9421055
bits = self.joy_state.bits
9431056
if not self.any_pressed(bits, ["stickL", "stickR"]):
9441057
self.joint_timer.cancel()
@@ -967,7 +1080,7 @@ def joint_control_joy(self):
9671080
),
9681081
}
9691082

970-
joint_mapping = {
1083+
joint_mapping_default = {
9711084
("L1", "stickL_vert"): 1,
9721085
("L1", "stickL_horiz"): 2,
9731086
("L1", "stickR_vert"): 9,
@@ -979,6 +1092,33 @@ def joint_control_joy(self):
9791092
("L2", "stickL_vert"): 5,
9801093
}
9811094

1095+
joint_mapping_75 = {
1096+
("L1", "stickL_vert"): 1,
1097+
("L1", "stickL_horiz"): 2,
1098+
("L1", "stickR_vert"): 3,
1099+
("L1", "stickR_horiz"): 4,
1100+
("R1", "stickL_vert"): 5,
1101+
("R1", "stickL_horiz"): 6,
1102+
("R1", "stickR_vert"): 7,
1103+
}
1104+
1105+
joint_mapping_16 = {
1106+
("L1", "stickL_vert"): 1,
1107+
("L1", "stickL_horiz"): 2,
1108+
("L1", "stickR_vert"): 3,
1109+
("L1", "stickR_horiz"): 4,
1110+
("R1", "stickL_vert"): 5,
1111+
("R1", "stickL_horiz"): 6,
1112+
}
1113+
joint_mapping = joint_mapping_default
1114+
1115+
if self.launch_case == "75":
1116+
joint_mapping = joint_mapping_75
1117+
elif self.launch_case == "16":
1118+
joint_mapping = joint_mapping_16
1119+
else:
1120+
joint_mapping = joint_mapping_default
1121+
9821122
held_buttons = []
9831123
if self.any_pressed(bits, ["L1"]):
9841124
held_buttons.append("L1")
@@ -1003,7 +1143,7 @@ def joint_control_joy(self):
10031143
if selected_joint is None or stick_to_use is None:
10041144
return
10051145

1006-
joint_ind = STICKER_TO_ALPHAB.get(selected_joint)
1146+
joint_ind = self.get_joint_index(selected_joint)
10071147
if joint_ind is None:
10081148
return
10091149

@@ -1348,7 +1488,10 @@ def enter_dragon_mode(self) -> None:
13481488
(Key.KEY_DOWN, ANY): [self.dragon_base_lookdown],
13491489
# joystick mapping
13501490
("x", ANY): [self.default_dragon],
1351-
("left", BUTT_INTS["left"]): [self.dragon_back_right, self.dragon_front_left],
1491+
("left", BUTT_INTS["left"]): [
1492+
self.dragon_back_right,
1493+
self.dragon_front_left,
1494+
],
13521495
("right", BUTT_INTS["right"]): [
13531496
self.dragon_back_left,
13541497
self.dragon_front_right,
@@ -1476,6 +1619,9 @@ def enter_joint_mode(self) -> None:
14761619
Returns:
14771620
InputMap for joint control
14781621
"""
1622+
self.refresh_joint_mapping()
1623+
# self.pinfo(self.get_active_leg_keys(1))
1624+
14791625
self.pinfo(f"Joint Control Mode")
14801626
submap: InputMap = {
14811627
(Key.KEY_W, ANY): [lambda: self.set_joint_speed(MAX_JOINT_SPEED)],
@@ -1485,6 +1631,8 @@ def enter_joint_mode(self) -> None:
14851631
(Key.KEY_O, ANY): [lambda: self.minimal_wheel_speed(1000000)],
14861632
(Key.KEY_L, ANY): [lambda: self.minimal_wheel_speed(-10000000)],
14871633
(Key.KEY_P, ANY): [lambda: self.minimal_wheel_speed(0.0)],
1634+
# (Key.KEY_G, ANY): [self.switch_to_grip_ur16],
1635+
(Key.KEY_R, ANY): [self.refresh_joint_mapping],
14881636
# joy mapping
14891637
("stickL", BUTT_INTS["stickL"] + BUTT_INTS["L1"]): [self.joint_timer_start],
14901638
("stickR", BUTT_INTS["stickR"] + BUTT_INTS["L1"]): [self.joint_timer_start],
@@ -1505,7 +1653,7 @@ def enter_joint_mode(self) -> None:
15051653
(8, Key.KEY_9),
15061654
]
15071655
for n, keyb in one2nine_keys:
1508-
n = STICKER_TO_ALPHAB[n + 1]
1656+
n = self.get_joint_index(n + 1)
15091657
submap[(keyb, ANY)] = [lambda n=n: self.select_joint(n)]
15101658

15111659
self.sub_map = submap
@@ -1583,7 +1731,9 @@ def easy_mode(self):
15831731
("down", BUTT_INTS["down"] + BUTT_INTS["L2"]): [
15841732
lambda: self.dragon_wheel_speed(-100000)
15851733
],
1586-
("x", BUTT_INTS["x"] + BUTT_INTS["L2"]): [lambda: self.dragon_wheel_speed(0)],
1734+
("x", BUTT_INTS["x"] + BUTT_INTS["L2"]): [
1735+
lambda: self.dragon_wheel_speed(0)
1736+
],
15871737
# ("R2", ANY): [self.recover_legs],
15881738
# ("R2", BUTT_INTS["L2"] + BUTT_INTS["R2"]): [self.recover_all],
15891739
# ("L2", BUTT_INTS["L2"] + BUTT_INTS["R2"]): [self.recover_all],

src/easy_robot_control/easy_robot_control/gait_node.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ def __init__(self, joint_name: str, prefix: str, parent_leg: "Leg"):
7070
self.speed_set_angle_save: Optional[float] = None
7171
self.speedTMR = self.node.create_timer(0.05, self.speedTMRCBK)
7272
self.speedTMR.cancel()
73-
self.MAX_DELTA = np.deg2rad(7)
73+
self.MAX_DELTA = np.deg2rad(20)
7474

7575
def is_active(self):
7676
if self.state.time is None:

src/easy_robot_control/easy_robot_control/joint_state_interface.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,9 @@ def __init__(self):
417417

418418
self.wait_for_lower_level(["rviz_interface_alive"], all_requiered=False)
419419

420-
self.pinfo(f"""{bcolors.OKBLUE}Interface connected to motors :){bcolors.ENDC}""")
420+
self.pinfo(
421+
f"""{bcolors.OKBLUE}Interface connected to motors :){bcolors.ENDC}"""
422+
)
421423

422424
# V Params V
423425
# \ / #

src/easy_robot_control/launch/ur16e.launch.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
# leg number -> end effector (number or link name)
2020
LEGS_DIC = {
21-
1: "palm_straight",
21+
16: "palm_straight",
2222
}
2323

2424
lvl_builder = LevelBuilder(robot_name=ROBOT_NAME, leg_dict=LEGS_DIC)
416 KB
Binary file not shown.
218 KB
Binary file not shown.
244 KB
Binary file not shown.
199 KB
Binary file not shown.

0 commit comments

Comments
 (0)