@@ -15,6 +15,11 @@ std::array<double, 7> LeftControllerPose;
1515std::array<double , 7 > RightControllerPose;
1616std::array<double , 7 > HeadsetPose;
1717
18+ std::array<std::array<double , 7 >, 26 > LeftHandTrackingState;
19+ double LeftHandScale = 1.0 ;
20+ std::array<std::array<double , 7 >, 26 > RightHandTrackingState;
21+ double RightHandScale = 1.0 ;
22+
1823bool LeftMenuButton;
1924double LeftTrigger;
2025double LeftGrip;
@@ -37,6 +42,8 @@ std::mutex leftMutex;
3742std::mutex rightMutex;
3843std::mutex headsetPoseMutex;
3944std::mutex timestampMutex;
45+ std::mutex leftHandMutex;
46+ std::mutex rightHandMutex;
4047
4148std::array<double , 7 > stringToPoseArray (const std::string& poseStr) {
4249 std::array<double , 7 > result{0 };
@@ -60,13 +67,13 @@ void OnPXREAClientCallback(void* context, PXREAClientCallbackType type, int stat
6067 std::cout << " server disconnect\n " << std::endl;
6168 break ;
6269 case PXREADeviceFind:
63- std::cout << " device find " << (const char *)userData << std::endl;
70+ std::cout << " device found \n " << (const char *)userData << std::endl;
6471 break ;
6572 case PXREADeviceMissing:
66- std::cout << " device missing " << (const char *)userData << std::endl;
73+ std::cout << " device missing\n " << (const char *)userData << std::endl;
6774 break ;
6875 case PXREADeviceConnect:
69- std::cout << " device connect " << (const char *)userData << status << std::endl;
76+ std::cout << " device connect\n " << (const char *)userData << status << std::endl;
7077 break ;
7178 case PXREADeviceStateJson:
7279 auto & dsj = *((PXREADevStateJson*)userData);
@@ -115,6 +122,27 @@ void OnPXREAClientCallback(void* context, PXREAClientCallbackType type, int stat
115122 std::lock_guard<std::mutex> lock (timestampMutex);
116123 TimeStampNs = value[" timeStampNs" ].get <int64_t >();
117124 }
125+ if (value[" Hand" ].contains (" leftHand" )) {
126+ auto & leftHand = value[" Hand" ][" leftHand" ];
127+ {
128+ std::lock_guard<std::mutex> lock (leftHandMutex);
129+
130+ LeftHandScale = leftHand[" scale" ].get <double >();
131+ for (int i = 0 ; i < 26 ; i++) {
132+ LeftHandTrackingState[i] = stringToPoseArray (leftHand[" HandJointLocations" ][i][" p" ].get <std::string>());
133+ }
134+ }
135+ }
136+ if (value[" Hand" ].contains (" rightHand" )) {
137+ auto & rightHand = value[" Hand" ][" rightHand" ];
138+ {
139+ std::lock_guard<std::mutex> lock (rightHandMutex);
140+ RightHandScale = rightHand[" scale" ].get <double >();
141+ for (int i = 0 ; i < 26 ; i++) {
142+ RightHandTrackingState[i] = stringToPoseArray (rightHand[" HandJointLocations" ][i][" p" ].get <std::string>());
143+ }
144+ }
145+ }
118146 }
119147 } catch (const json::exception& e) {
120148 std::cerr << " JSON parsing error: " << e.what () << std::endl;
@@ -224,6 +252,26 @@ int64_t getTimeStampNs() {
224252 return TimeStampNs;
225253}
226254
255+ std::array<std::array<double , 7 >, 26 > getLeftHandTrackingState () {
256+ std::lock_guard<std::mutex> lock (leftHandMutex);
257+ return LeftHandTrackingState;
258+ }
259+
260+ int getLeftHandScale () {
261+ std::lock_guard<std::mutex> lock (leftHandMutex);
262+ return LeftHandScale;
263+ }
264+
265+ std::array<std::array<double , 7 >, 26 > getRightHandTrackingState () {
266+ std::lock_guard<std::mutex> lock (rightHandMutex);
267+ return RightHandTrackingState;
268+ }
269+
270+ int getRightHandScale () {
271+ std::lock_guard<std::mutex> lock (rightHandMutex);
272+ return RightHandScale;
273+ }
274+
227275PYBIND11_MODULE (xrobotoolkit_sdk, m) {
228276 m.def (" init" , &init, " Initialize the PXREARobot SDK." );
229277 m.def (" close" , &deinit, " Deinitialize the PXREARobot SDK." );
@@ -245,5 +293,7 @@ PYBIND11_MODULE(xrobotoolkit_sdk, m) {
245293 m.def (" get_Y_button" , &getLeftSecondaryButton, " Get the left secondary button state." );
246294 m.def (" get_B_button" , &getRightSecondaryButton, " Get the right secondary button state." );
247295 m.def (" get_time_stamp_ns" , &getTimeStampNs, " Get the timestamp in nanoseconds." );
296+ m.def (" get_left_hand_tracking_state" , &getLeftHandTrackingState, " Get the left hand state." );
297+ m.def (" get_right_hand_tracking_state" , &getRightHandTrackingState, " Get the right hand state." );
248298 m.doc () = " Python bindings for PXREARobot SDK using pybind11." ;
249299}
0 commit comments