Skip to content

Commit 1ba0936

Browse files
committed
Create tracked types to handle inactive input sources
1 parent 6a6eb42 commit 1ba0936

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+674
-508
lines changed

examples/lerobot/record.py

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
from pathlib import Path
1616
import isaacteleop.deviceio as deviceio
1717
import isaacteleop.oxr as oxr
18-
import isaacteleop.schema as schema
1918
from lerobot.datasets.lerobot_dataset import LeRobotDataset
2019

2120

@@ -115,31 +114,31 @@ def main():
115114
break
116115

117116
# Get hand data
118-
left: schema.HandPoseT = hand_tracker.get_left_hand(session)
119-
right: schema.HandPoseT = hand_tracker.get_right_hand(session)
120-
head: schema.HeadPoseT = head_tracker.get_head(session)
117+
tracked_left = hand_tracker.get_left_hand(session)
118+
tracked_right = hand_tracker.get_right_hand(session)
119+
tracked_head = head_tracker.get_head(session)
121120

122121
# Extract positions and orientations (with defaults for invalid data)
123122
left_pos = np.zeros(3, dtype=np.float32)
124123
right_pos = np.zeros(3, dtype=np.float32)
125124

126-
if left.is_active and left.joints:
127-
wrist = left.joints[deviceio.JOINT_WRIST]
125+
if tracked_left.data is not None and tracked_left.data.joints:
126+
wrist = tracked_left.data.joints[deviceio.JOINT_WRIST]
128127
if wrist.is_valid:
129128
pos = wrist.pose.position
130129
left_pos = np.array([pos.x, pos.y, pos.z], dtype=np.float32)
131130

132-
if right.is_active and right.joints:
133-
wrist = right.joints[deviceio.JOINT_WRIST]
131+
if tracked_right.data is not None and tracked_right.data.joints:
132+
wrist = tracked_right.data.joints[deviceio.JOINT_WRIST]
134133
if wrist.is_valid:
135134
pos = wrist.pose.position
136135
right_pos = np.array(
137136
[pos.x, pos.y, pos.z], dtype=np.float32
138137
)
139138

140139
head_pos = np.zeros(3, dtype=np.float32)
141-
if head.is_valid and head.pose:
142-
pos = head.pose.position
140+
if tracked_head.data.is_valid and tracked_head.data.pose:
141+
pos = tracked_head.data.pose.position
143142
head_pos = np.array([pos.x, pos.y, pos.z], dtype=np.float32)
144143

145144
# STEP 3: Record frame to dataset

examples/oxr/cpp/oxr_session_sharing.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -89,17 +89,17 @@ try
8989
}
9090

9191
// Get data from both trackers
92-
const auto& left = hand_tracker->get_left_hand(*session1);
93-
const auto& head = head_tracker->get_head(*session2);
92+
const auto& left_tracked = hand_tracker->get_left_hand(*session1);
93+
const auto& head_tracked = head_tracker->get_head(*session2);
9494

9595
if (i % 3 == 0)
9696
{
9797
std::cout << "Frame " << i << ": "
98-
<< "Hands=" << (left.is_active ? "ACTIVE" : "INACTIVE") << " | "
99-
<< "Head=" << (head.is_valid ? "VALID" : "INVALID");
100-
if (head.is_valid && head.pose)
98+
<< "Hands=" << (left_tracked.data ? "ACTIVE" : "INACTIVE") << " | "
99+
<< "Head=" << ((head_tracked.data && head_tracked.data->is_valid) ? "VALID" : "INVALID");
100+
if (head_tracked.data && head_tracked.data->is_valid && head_tracked.data->pose)
101101
{
102-
const auto& pos = head.pose->position();
102+
const auto& pos = head_tracked.data->pose->position();
103103
std::cout << " [" << pos.x() << ", " << pos.y() << ", " << pos.z() << "]";
104104
}
105105
std::cout << std::endl;

examples/oxr/cpp/oxr_simple_api_demo.cpp

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -82,18 +82,19 @@ try
8282
}
8383

8484
// External user only uses public query methods
85-
const auto& left = hand_tracker->get_left_hand(*session);
86-
const auto& right = hand_tracker->get_right_hand(*session);
87-
const auto& head = head_tracker->get_head(*session);
85+
const auto& left_tracked = hand_tracker->get_left_hand(*session);
86+
const auto& right_tracked = hand_tracker->get_right_hand(*session);
87+
const auto& head_tracked = head_tracker->get_head(*session);
8888

8989
std::cout << "Frame " << i << ":" << std::endl;
90-
std::cout << " Left hand: " << (left.is_active ? "ACTIVE" : "INACTIVE") << std::endl;
91-
std::cout << " Right hand: " << (right.is_active ? "ACTIVE" : "INACTIVE") << std::endl;
92-
std::cout << " Head pose: " << (head.is_valid ? "VALID" : "INVALID") << std::endl;
90+
std::cout << " Left hand: " << (left_tracked.data ? "ACTIVE" : "INACTIVE") << std::endl;
91+
std::cout << " Right hand: " << (right_tracked.data ? "ACTIVE" : "INACTIVE") << std::endl;
92+
std::cout << " Head pose: " << ((head_tracked.data && head_tracked.data->is_valid) ? "VALID" : "INVALID")
93+
<< std::endl;
9394

94-
if (head.is_valid && head.pose)
95+
if (head_tracked.data && head_tracked.data->is_valid && head_tracked.data->pose)
9596
{
96-
const auto& pos = head.pose->position();
97+
const auto& pos = head_tracked.data->pose->position();
9798
std::cout << " Position: [" << pos.x() << ", " << pos.y() << ", " << pos.z() << "]" << std::endl;
9899
}
99100
std::cout << std::endl;

examples/oxr/python/modular_example.py

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -70,28 +70,30 @@ def main():
7070
print(f"[{elapsed:4.1f}s] Frame {frame_count}")
7171

7272
# Get hand data
73-
left = hand_tracker.get_left_hand(session)
74-
right = hand_tracker.get_right_hand(session)
73+
tracked_left = hand_tracker.get_left_hand(session)
74+
tracked_right = hand_tracker.get_right_hand(session)
7575

7676
print(
77-
f" Hands: Left={'ACTIVE' if left.is_active else 'INACTIVE':8s} | "
78-
f"Right={'ACTIVE' if right.is_active else 'INACTIVE':8s}"
77+
f" Hands: Left={'ACTIVE' if tracked_left.data is not None else 'INACTIVE':8s} | "
78+
f"Right={'ACTIVE' if tracked_right.data is not None else 'INACTIVE':8s}"
7979
)
8080

81-
if left.is_active:
82-
wrist = left.joints[deviceio.JOINT_WRIST]
81+
if tracked_left.data is not None:
82+
wrist = tracked_left.data.joints[deviceio.JOINT_WRIST]
8383
if wrist.is_valid:
8484
pos = wrist.pose.position
8585
print(
8686
f" Left wrist: [{pos.x:6.3f}, {pos.y:6.3f}, {pos.z:6.3f}]"
8787
)
8888

89-
# Get head data (returns HeadPoseT from schema)
90-
head = head_tracker.get_head(session)
91-
print(f" Head: {'VALID' if head.is_valid else 'INVALID':8s}")
89+
# Get head data (returns TrackedT<HeadPoseT> from schema)
90+
tracked_head = head_tracker.get_head(session)
91+
print(
92+
f" Head: {'VALID' if tracked_head.data.is_valid else 'INVALID':8s}"
93+
)
9294

93-
if head.is_valid and head.pose:
94-
pos = head.pose.position
95+
if tracked_head.data.is_valid and tracked_head.data.pose:
96+
pos = tracked_head.data.pose.position
9597
print(
9698
f" Head position: [{pos.x:6.3f}, {pos.y:6.3f}, {pos.z:6.3f}]"
9799
)

examples/oxr/python/test_controller_tracker.py

Lines changed: 85 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -57,17 +57,21 @@
5757

5858
# Test 5: Check initial controller state
5959
print("[Test 5] Checking controller state...")
60-
left_snap = controller_tracker.get_left_controller(session)
61-
right_snap = controller_tracker.get_right_controller(session)
62-
print(f" Left controller: {'ACTIVE' if left_snap.is_active else 'INACTIVE'}")
63-
print(f" Right controller: {'ACTIVE' if right_snap.is_active else 'INACTIVE'}")
64-
65-
if left_snap.is_active and left_snap.grip_pose.is_valid:
66-
pos = left_snap.grip_pose.pose.position
60+
tracked_left = controller_tracker.get_left_controller(session)
61+
tracked_right = controller_tracker.get_right_controller(session)
62+
print(
63+
f" Left controller: {'ACTIVE' if tracked_left.data is not None else 'INACTIVE'}"
64+
)
65+
print(
66+
f" Right controller: {'ACTIVE' if tracked_right.data is not None else 'INACTIVE'}"
67+
)
68+
69+
if tracked_left.data is not None and tracked_left.data.grip_pose.is_valid:
70+
pos = tracked_left.data.grip_pose.pose.position
6771
print(f" Left grip position: [{pos.x:.3f}, {pos.y:.3f}, {pos.z:.3f}]")
6872

69-
if right_snap.is_active and right_snap.grip_pose.is_valid:
70-
pos = right_snap.grip_pose.pose.position
73+
if tracked_right.data is not None and tracked_right.data.grip_pose.is_valid:
74+
pos = tracked_right.data.grip_pose.pose.position
7175
print(f" Right grip position: [{pos.x:.3f}, {pos.y:.3f}, {pos.z:.3f}]")
7276
print()
7377

@@ -96,23 +100,71 @@
96100
current_time = time.time()
97101
if current_time - last_status_print >= 0.5: # Print every 0.5 seconds
98102
elapsed = current_time - start_time
99-
left_snap = controller_tracker.get_left_controller(session)
100-
right_snap = controller_tracker.get_right_controller(session)
103+
tracked_left = controller_tracker.get_left_controller(session)
104+
tracked_right = controller_tracker.get_right_controller(session)
101105

102106
# Show current state
103-
left_trigger = left_snap.inputs.trigger_value
104-
left_squeeze = left_snap.inputs.squeeze_value
105-
left_stick_x = left_snap.inputs.thumbstick_x
106-
left_stick_y = left_snap.inputs.thumbstick_y
107-
left_primary = left_snap.inputs.primary_click
108-
left_secondary = left_snap.inputs.secondary_click
109-
110-
right_trigger = right_snap.inputs.trigger_value
111-
right_squeeze = right_snap.inputs.squeeze_value
112-
right_stick_x = right_snap.inputs.thumbstick_x
113-
right_stick_y = right_snap.inputs.thumbstick_y
114-
right_primary = right_snap.inputs.primary_click
115-
right_secondary = right_snap.inputs.secondary_click
107+
left_trigger = (
108+
tracked_left.data.inputs.trigger_value
109+
if tracked_left.data is not None
110+
else 0.0
111+
)
112+
left_squeeze = (
113+
tracked_left.data.inputs.squeeze_value
114+
if tracked_left.data is not None
115+
else 0.0
116+
)
117+
left_stick_x = (
118+
tracked_left.data.inputs.thumbstick_x
119+
if tracked_left.data is not None
120+
else 0.0
121+
)
122+
left_stick_y = (
123+
tracked_left.data.inputs.thumbstick_y
124+
if tracked_left.data is not None
125+
else 0.0
126+
)
127+
left_primary = (
128+
tracked_left.data.inputs.primary_click
129+
if tracked_left.data is not None
130+
else False
131+
)
132+
left_secondary = (
133+
tracked_left.data.inputs.secondary_click
134+
if tracked_left.data is not None
135+
else False
136+
)
137+
138+
right_trigger = (
139+
tracked_right.data.inputs.trigger_value
140+
if tracked_right.data is not None
141+
else 0.0
142+
)
143+
right_squeeze = (
144+
tracked_right.data.inputs.squeeze_value
145+
if tracked_right.data is not None
146+
else 0.0
147+
)
148+
right_stick_x = (
149+
tracked_right.data.inputs.thumbstick_x
150+
if tracked_right.data is not None
151+
else 0.0
152+
)
153+
right_stick_y = (
154+
tracked_right.data.inputs.thumbstick_y
155+
if tracked_right.data is not None
156+
else 0.0
157+
)
158+
right_primary = (
159+
tracked_right.data.inputs.primary_click
160+
if tracked_right.data is not None
161+
else False
162+
)
163+
right_secondary = (
164+
tracked_right.data.inputs.secondary_click
165+
if tracked_right.data is not None
166+
else False
167+
)
116168

117169
# Build status strings
118170
left_status = f"Trig={left_trigger:.2f} Sq={left_squeeze:.2f}"
@@ -153,14 +205,14 @@
153205
# Test 8: Show final statistics
154206
print("[Test 8] Final controller state...")
155207

156-
def print_controller_summary(hand_name, snapshot):
208+
def print_controller_summary(hand_name, tracked):
157209
print(f" {hand_name} Controller:")
158-
if snapshot.is_active:
210+
if tracked.data is not None:
159211
print(" Status: ACTIVE")
160212

161213
# Poses from snapshot
162-
grip = snapshot.grip_pose
163-
aim = snapshot.aim_pose
214+
grip = tracked.data.grip_pose
215+
aim = tracked.data.aim_pose
164216

165217
if grip.is_valid:
166218
pos = grip.pose.position
@@ -175,7 +227,7 @@ def print_controller_summary(hand_name, snapshot):
175227
)
176228

177229
# Input values
178-
inputs = snapshot.inputs
230+
inputs = tracked.data.inputs
179231
print(f" Trigger: {inputs.trigger_value:.2f}")
180232
print(f" Squeeze: {inputs.squeeze_value:.2f}")
181233
print(
@@ -190,11 +242,11 @@ def print_controller_summary(hand_name, snapshot):
190242
else:
191243
print(" Status: INACTIVE")
192244

193-
left_snap = controller_tracker.get_left_controller(session)
194-
right_snap = controller_tracker.get_right_controller(session)
195-
print_controller_summary("Left", left_snap)
245+
tracked_left = controller_tracker.get_left_controller(session)
246+
tracked_right = controller_tracker.get_right_controller(session)
247+
print_controller_summary("Left", tracked_left)
196248
print()
197-
print_controller_summary("Right", right_snap)
249+
print_controller_summary("Right", tracked_right)
198250
print()
199251

200252
# Cleanup

examples/oxr/python/test_extensions.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,11 +88,13 @@
8888

8989
# Quick update test
9090
if session.update():
91-
left = hand.get_left_hand(session)
92-
head_pose = head.get_head(session)
91+
tracked_left = hand.get_left_hand(session)
92+
tracked_head = head.get_head(session)
9393
print(" ✅ Update successful")
94-
print(f" Hands: {'ACTIVE' if left.is_active else 'INACTIVE'}")
95-
print(f" Head: {'VALID' if head_pose.is_valid else 'INVALID'}")
94+
print(
95+
f" Hands: {'ACTIVE' if tracked_left.data is not None else 'INACTIVE'}"
96+
)
97+
print(f" Head: {'VALID' if tracked_head.data.is_valid else 'INVALID'}")
9698

9799
# Session will be cleaned up when exiting 'with' block (RAII)
98100

examples/oxr/python/test_full_body_tracker.py

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -66,15 +66,17 @@
6666

6767
# Test 6: Check initial body tracking state
6868
print("[Test 6] Checking body tracking state...")
69-
body_pose = body_tracker.get_body_pose(session)
70-
print(f" Body tracking active: {'YES' if body_pose.is_active else 'NO'}")
69+
tracked_body = body_tracker.get_body_pose(session)
70+
print(
71+
f" Body tracking active: {'YES' if tracked_body.data is not None else 'NO'}"
72+
)
7173

72-
if body_pose.joints:
74+
if tracked_body.data is not None and tracked_body.data.joints:
7375
# Count valid joints
7476
valid_count = sum(
7577
1
7678
for i in range(schema.BodyJointPico.NUM_JOINTS)
77-
if body_pose.joints[i].is_valid
79+
if tracked_body.data.joints[i].is_valid
7880
)
7981
print(
8082
f" Valid joints: {valid_count}/{schema.BodyJointPico.NUM_JOINTS}"
@@ -99,22 +101,22 @@
99101
current_time = time.time()
100102
if current_time - last_status_print >= 0.5: # Print every 0.5 seconds
101103
elapsed = current_time - start_time
102-
body_pose = body_tracker.get_body_pose(session)
104+
tracked_body = body_tracker.get_body_pose(session)
103105

104106
# Show key joint positions
105-
status = f"Active: {'Y' if body_pose.is_active else 'N'}"
107+
status = f"Active: {'Y' if tracked_body.data is not None else 'N'}"
106108

107-
if body_pose.joints:
109+
if tracked_body.data is not None and tracked_body.data.joints:
108110
# Get pelvis position (root joint)
109-
pelvis = body_pose.joints[schema.BodyJointPico.PELVIS]
111+
pelvis = tracked_body.data.joints[schema.BodyJointPico.PELVIS]
110112
if pelvis.is_valid:
111113
pos = pelvis.pose.position
112114
status += (
113115
f" | Pelvis: [{pos.x:+.2f}, {pos.y:+.2f}, {pos.z:+.2f}]"
114116
)
115117

116118
# Get head position
117-
head = body_pose.joints[schema.BodyJointPico.HEAD]
119+
head = tracked_body.data.joints[schema.BodyJointPico.HEAD]
118120
if head.is_valid:
119121
pos = head.pose.position
120122
status += (
@@ -133,15 +135,17 @@
133135

134136
# Test 8: Show final body pose
135137
print("[Test 8] Final body pose state...")
136-
body_pose = body_tracker.get_body_pose(session)
138+
tracked_body = body_tracker.get_body_pose(session)
137139

138-
print(f" Body tracking active: {'YES' if body_pose.is_active else 'NO'}")
140+
print(
141+
f" Body tracking active: {'YES' if tracked_body.data is not None else 'NO'}"
142+
)
139143

140-
if body_pose.joints:
144+
if tracked_body.data is not None and tracked_body.data.joints:
141145
print()
142146
print(" Joint positions (valid joints only):")
143147
for i in range(schema.BodyJointPico.NUM_JOINTS):
144-
joint = body_pose.joints[i]
148+
joint = tracked_body.data.joints[i]
145149
name = schema.BodyJointPico(i).name
146150
if joint.is_valid:
147151
pos = joint.pose.position

0 commit comments

Comments
 (0)