Fix hand & glove readings

This commit is contained in:
Simon Alibert 2025-04-16 09:54:53 +02:00
parent c4b1cee615
commit 98643b000e
2 changed files with 9 additions and 8 deletions

View File

@ -164,7 +164,8 @@ class HopeJrHand(Robot):
# Read hand position # Read hand position
start = time.perf_counter() start = time.perf_counter()
obs_dict[OBS_STATE] = self.hand.sync_read("Present_Position") for motor in self.hand.motors:
obs_dict[f"{OBS_STATE}.{motor}"] = self.hand.read("Present_Position", motor, normalize=False)
dt_ms = (time.perf_counter() - start) * 1e3 dt_ms = (time.perf_counter() - start) * 1e3
logger.debug(f"{self} read state: {dt_ms:.1f}ms") logger.debug(f"{self} read state: {dt_ms:.1f}ms")

View File

@ -48,6 +48,7 @@ class HomonculusGlove(Teleoperator):
name = "homonculus_glove" name = "homonculus_glove"
def __init__(self, config: HomonculusGloveConfig): def __init__(self, config: HomonculusGloveConfig):
super().__init__(config)
self.config = config self.config = config
self.serial = serial.Serial(config.port, config.baud_rate, timeout=1) self.serial = serial.Serial(config.port, config.baud_rate, timeout=1)
self.buffer_size = config.buffer_size self.buffer_size = config.buffer_size
@ -99,7 +100,8 @@ class HomonculusGlove(Teleoperator):
if self.is_connected: if self.is_connected:
raise DeviceAlreadyConnectedError(f"{self} already connected") raise DeviceAlreadyConnectedError(f"{self} already connected")
self.serial.open() if not self.serial.is_open:
self.serial.open()
self.thread.start() self.thread.start()
self.configure() self.configure()
logger.info(f"{self} connected.") logger.info(f"{self} connected.")
@ -145,8 +147,6 @@ class HomonculusGlove(Teleoperator):
# Get raw (last) values # Get raw (last) values
values = np.array([self.last_d[k] for k in motor_names]) values = np.array([self.last_d[k] for k in motor_names])
print(values)
# Apply calibration if available # Apply calibration if available
if self.calibration is not None: if self.calibration is not None:
values = self.apply_calibration(values, motor_names) values = self.apply_calibration(values, motor_names)
@ -164,7 +164,7 @@ class HomonculusGlove(Teleoperator):
# Gather averaged readings from buffers # Gather averaged readings from buffers
smoothed_vals = [] smoothed_vals = []
for name in motor_names: for name in motor_names:
buf = self.joint_buffer[name] buf = self.joints_buffer[name]
if len(buf) == 0: if len(buf) == 0:
# If no data has been read yet, fall back to last_d # If no data has been read yet, fall back to last_d
smoothed_vals.append(self.last_d[name]) smoothed_vals.append(self.last_d[name])
@ -219,10 +219,10 @@ class HomonculusGlove(Teleoperator):
# Also push these new values into the rolling buffers # Also push these new values into the rolling buffers
for joint_name, joint_val in d.items(): for joint_name, joint_val in d.items():
self.joint_buffer[joint_name].append(joint_val) self.joints_buffer[joint_name].append(joint_val)
def run_calibration(self): def run_calibration(self):
print("\nMove arm to open position") print("\nMove hand to open position")
input("Press Enter to continue...") input("Press Enter to continue...")
open_pos_list = [] open_pos_list = []
for _ in range(100): for _ in range(100):
@ -236,7 +236,7 @@ class HomonculusGlove(Teleoperator):
print(f"{max_open_pos=}") print(f"{max_open_pos=}")
print(f"{min_open_pos=}") print(f"{min_open_pos=}")
print("\nMove arm to closed position") print("\nMove hand to closed position")
input("Press Enter to continue...") input("Press Enter to continue...")
closed_pos_list = [] closed_pos_list = []
for _ in range(100): for _ in range(100):