1010using RosMessageTypes . VrHaptic ;
1111using TMPro ;
1212using UnityEngine . InputSystem ;
13+ using UnityEngine . UI ;
1314
1415
1516public class HandPub : MonoBehaviour
@@ -43,24 +44,37 @@ public class HandPub : MonoBehaviour
4344 public InputActionReference twistController ;
4445 public InputActionReference poseController ;
4546
46-
47+ public Sprite enableIcon ;
48+ public Sprite disableIcon ;
49+ public Button enableButton ;
50+ private Image _img ;
4751 public TextMeshProUGUI infoText ;
48- private Transform _root ;
4952
50- ROSConnection ros ;
53+ ROSConnection _ros ;
5154 XRHandSubsystem m_handSubsystem ;
5255
56+ private Transform _root ;
57+ private bool _publishing = false ;
58+
5359 private bool _highConfidence = false ;
54- private const string _landmarksTopic = "/hand_pose" ;
55- private const string _pointCloudTopic = "/hand_points" ;
56- private const string _gestureTopic = "/hand_gesture" ;
60+ private const string _landmarksTopic = "/quest/ hand_pose" ;
61+ private const string _pointCloudTopic = "/quest/ hand_points" ;
62+ private const string _gestureTopic = "/quest/ hand_gesture" ;
5763
5864 public string worldFrame = "quest_origin" ;
5965
6066 void Start ( )
6167 {
6268 _root = GameObject . FindWithTag ( "root" ) . transform ;
6369
70+ _img = enableButton . transform . Find ( "Image/Image" ) . GetComponent < Image > ( ) ;
71+
72+ if ( PlayerPrefs . HasKey ( "handPublishing" ) )
73+ {
74+ _publishing = PlayerPrefs . GetInt ( "handPublishing" ) == 1 ;
75+ _img . sprite = _publishing ? enableIcon : disableIcon ;
76+ }
77+
6478 var _handSubsystem = new List < XRHandSubsystem > ( ) ;
6579 SubsystemManager . GetSubsystems ( _handSubsystem ) ;
6680 Debug . Log ( "Found " + _handSubsystem . Count + " hand subsystems" ) ;
@@ -92,10 +106,10 @@ void Start()
92106 }
93107
94108 }
95- ros = ROSConnection . GetOrCreateInstance ( ) ;
96- ros . RegisterPublisher < ManoLandmarksMsg > ( _landmarksTopic ) ;
97- ros . RegisterPublisher < PointCloudMsg > ( _pointCloudTopic ) ;
98- ros . RegisterPublisher < HandGestureMsg > ( _gestureTopic ) ;
109+ _ros = ROSConnection . GetOrCreateInstance ( ) ;
110+ _ros . RegisterPublisher < ManoLandmarksMsg > ( _landmarksTopic ) ;
111+ _ros . RegisterPublisher < PointCloudMsg > ( _pointCloudTopic ) ;
112+ _ros . RegisterPublisher < HandGestureMsg > ( _gestureTopic ) ;
99113
100114 // setup action map listeners
101115 twistController . action . performed += _ => PubTwistController ( ) ;
@@ -117,7 +131,7 @@ public void PubActiveController()
117131 {
118132 HandGestureMsg msg = new HandGestureMsg ( ) ;
119133 msg . name = "Closed_Fist" ;
120- ros . Publish ( _gestureTopic , msg ) ;
134+ _ros . Publish ( _gestureTopic , msg ) ;
121135 if ( infoText != null )
122136 infoText . color = Color . green ;
123137
@@ -127,7 +141,7 @@ public void PubTwistController()
127141 {
128142 HandGestureMsg msg = new HandGestureMsg ( ) ;
129143 msg . name = "Thumb_Up" ;
130- ros . Publish ( _gestureTopic , msg ) ;
144+ _ros . Publish ( _gestureTopic , msg ) ;
131145
132146 infoText ? . SetText ( "Twist activated" ) ;
133147 }
@@ -136,7 +150,7 @@ public void PubPoseController()
136150 {
137151 HandGestureMsg msg = new HandGestureMsg ( ) ;
138152 msg . name = "Thump_Down" ;
139- ros . Publish ( _gestureTopic , msg ) ;
153+ _ros . Publish ( _gestureTopic , msg ) ;
140154 infoText ? . SetText ( "Pose activated" ) ;
141155 }
142156
@@ -146,11 +160,20 @@ public void ToggleConfidence()
146160 infoText ? . SetText ( _highConfidence ? "High Confidence" : "Low Confidence" ) ;
147161 }
148162
163+ public void TogglePublishing ( )
164+ {
165+ _publishing = ! _publishing ;
166+ PlayerPrefs . SetInt ( "handPublishing" , _publishing ? 1 : 0 ) ;
167+ PlayerPrefs . Save ( ) ;
168+ _img . sprite = _publishing ? enableIcon : disableIcon ;
169+ }
170+
149171 void OnHandUpdate ( XRHandSubsystem subsystem ,
150172 XRHandSubsystem . UpdateSuccessFlags updateSuccessFlags ,
151173 XRHandSubsystem . UpdateType updateType )
152174 {
153- if ( updateSuccessFlags == 0 && _highConfidence ) return ;
175+ if ( ! _publishing ) return ;
176+ if ( updateSuccessFlags == 0 && _highConfidence ) return ;
154177
155178
156179 // bypass render update to slightly throttle
@@ -221,8 +244,8 @@ void OnHandUpdate(XRHandSubsystem subsystem,
221244
222245 pointCloudMsg . points = points ;
223246 msg . landmarks = CastPoints ( points ) ;
224- ros . Publish ( _landmarksTopic , msg ) ;
225- ros . Publish ( _pointCloudTopic , pointCloudMsg ) ;
247+ _ros . Publish ( _landmarksTopic , msg ) ;
248+ _ros . Publish ( _pointCloudTopic , pointCloudMsg ) ;
226249 }
227250 }
228251
0 commit comments