Add control scripts
This commit is contained in:
36
examples/hope_jr/vis/arm.py
Normal file
36
examples/hope_jr/vis/arm.py
Normal file
@@ -0,0 +1,36 @@
|
||||
import time
|
||||
import traceback
|
||||
|
||||
from lerobot.common.robots.hope_jr import HopeJrArm, HopeJrArmConfig
|
||||
from lerobot.common.utils.utils import move_cursor_up
|
||||
|
||||
# cfg = HopeJrArmConfig("/dev/tty.usbserial-140", id="right")
|
||||
cfg = HopeJrArmConfig("/dev/tty.usbserial-140", id="left")
|
||||
arm = HopeJrArm(cfg)
|
||||
display_len = max(len(key) for key in arm.action_features)
|
||||
|
||||
arm.connect()
|
||||
# arm.calibrate()
|
||||
arm.bus.disable_torque()
|
||||
try:
|
||||
while True:
|
||||
start = time.perf_counter()
|
||||
raw_obs = arm.bus.sync_read("Present_Position", normalize=False)
|
||||
norm_obs = {arm.bus.motors[name].id: val for name, val in raw_obs.items()}
|
||||
norm_obs = arm.bus._normalize(norm_obs)
|
||||
norm_obs = {arm.bus._id_to_name(id_): val for id_, val in norm_obs.items()}
|
||||
loop_s = time.perf_counter() - start
|
||||
|
||||
print("\n----------------------------------")
|
||||
print(f"{'NAME':<15} | {'RAW':>7} | {'NORM':>7}")
|
||||
for motor in arm.bus.motors:
|
||||
print(f"{motor:<15} | {raw_obs[motor]:>7} | {norm_obs[motor]:>7.2f}")
|
||||
print(f"\ntime: {loop_s * 1e3:.2f}ms ({1 / loop_s:.0f} Hz)")
|
||||
move_cursor_up(len(arm.bus.motors) + 5)
|
||||
|
||||
except KeyboardInterrupt:
|
||||
pass
|
||||
except Exception as e:
|
||||
traceback.print_exc(e)
|
||||
finally:
|
||||
arm.disconnect()
|
||||
33
examples/hope_jr/vis/exo.py
Normal file
33
examples/hope_jr/vis/exo.py
Normal file
@@ -0,0 +1,33 @@
|
||||
import time
|
||||
import traceback
|
||||
|
||||
from lerobot.common.teleoperators.homonculus import HomonculusArm, HomonculusArmConfig
|
||||
from lerobot.common.utils.utils import move_cursor_up
|
||||
|
||||
# cfg = HomonculusArmConfig("/dev/tty.usbmodem2101", id="left")
|
||||
cfg = HomonculusArmConfig("/dev/tty.usbmodem2101", id="right")
|
||||
arm = HomonculusArm(cfg)
|
||||
display_len = max(len(key) for key in arm.action_features)
|
||||
|
||||
arm.connect()
|
||||
# arm.calibrate()
|
||||
try:
|
||||
while True:
|
||||
start = time.perf_counter()
|
||||
raw_action = arm._read(normalize=False)
|
||||
norm_action = arm._normalize(raw_action)
|
||||
loop_s = time.perf_counter() - start
|
||||
|
||||
print("\n" + "-" * (display_len + 10))
|
||||
print(f"{'NAME':<{display_len}} | {'RAW':>7} | {'NORM':>7}")
|
||||
for joint in arm.joints:
|
||||
print(f"{joint:<{display_len}} | {raw_action[joint]:>7} | {norm_action[joint]:>7.2f}")
|
||||
print(f"\ntime: {loop_s * 1e3:.2f}ms ({1 / loop_s:.0f} Hz)")
|
||||
move_cursor_up(len(norm_action) + 5)
|
||||
|
||||
except KeyboardInterrupt:
|
||||
pass
|
||||
except Exception:
|
||||
traceback.print_exc()
|
||||
finally:
|
||||
arm.disconnect()
|
||||
32
examples/hope_jr/vis/glove.py
Normal file
32
examples/hope_jr/vis/glove.py
Normal file
@@ -0,0 +1,32 @@
|
||||
import time
|
||||
import traceback
|
||||
|
||||
from lerobot.common.teleoperators.homonculus import HomonculusGlove, HomonculusGloveConfig
|
||||
from lerobot.common.utils.utils import move_cursor_up
|
||||
|
||||
config = HomonculusGloveConfig("/dev/tty.usbmodem2101", side="right", id="right")
|
||||
glove = HomonculusGlove(config)
|
||||
glove.connect()
|
||||
|
||||
display_len = max(len(key) for key in glove.action_features)
|
||||
glove.calibrate()
|
||||
try:
|
||||
while True:
|
||||
start = time.perf_counter()
|
||||
raw_action = glove._read(normalize=False)
|
||||
norm_action = glove._normalize(raw_action)
|
||||
loop_s = time.perf_counter() - start
|
||||
|
||||
print("\n" + "-" * (display_len + 10))
|
||||
print(f"{'NAME':<{display_len}} | {'RAW':>7} | {'NORM':>7}")
|
||||
for joint in glove.joints:
|
||||
print(f"{joint:<{display_len}} | {raw_action[joint]:>7} | {norm_action[joint]:>7.2f}")
|
||||
print(f"\ntime: {loop_s * 1e3:.2f}ms ({1 / loop_s:.0f} Hz)")
|
||||
move_cursor_up(len(norm_action) + 5)
|
||||
|
||||
except KeyboardInterrupt:
|
||||
pass
|
||||
except Exception:
|
||||
traceback.print_exc()
|
||||
finally:
|
||||
glove.disconnect()
|
||||
8
examples/hope_jr/vis/hand.py
Normal file
8
examples/hope_jr/vis/hand.py
Normal file
@@ -0,0 +1,8 @@
|
||||
from lerobot.common.robots.hope_jr import HopeJrHand, HopeJrHandConfig
|
||||
|
||||
cfg = HopeJrHandConfig("/dev/tty.usbmodem58760433641", id="left", side="left")
|
||||
hand = HopeJrHand(cfg)
|
||||
|
||||
hand.connect()
|
||||
hand.calibrate()
|
||||
hand.disconnect()
|
||||
Reference in New Issue
Block a user