Skip to content

Commit 092813e

Browse files
fixed hand pose publishing
1 parent 430be9a commit 092813e

File tree

4 files changed

+376
-193
lines changed

4 files changed

+376
-193
lines changed

Assets/Components/Hands/Scripts/HandPub.cs

Lines changed: 39 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
using RosMessageTypes.VrHaptic;
1111
using TMPro;
1212
using UnityEngine.InputSystem;
13+
using UnityEngine.UI;
1314

1415

1516
public 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

Assets/Components/Haptics/Scripts/HandSubscriber.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@
66

77
public class HandSubscriber : MonoBehaviour
88
{
9-
public string topicName = "/haptics";
9+
public string topicName = "/quest/haptics";
1010

11-
ROSConnection ros;
11+
ROSConnection _ros;
1212

1313
// Start is called before the first frame update
1414
void Start()
1515
{
16-
ros = ROSConnection.GetOrCreateInstance();
17-
ros.Subscribe<HapticReadingsMsg>(topicName, ReceiveMessage);
16+
_ros = ROSConnection.GetOrCreateInstance();
17+
_ros.Subscribe<HapticReadingsMsg>(topicName, ReceiveMessage);
1818
}
1919

2020
int ForceMapper(double force)

0 commit comments

Comments
 (0)