Unreal SDK  v1.1
Loading...
Searching...
No Matches
WeArtMessages.h
Go to the documentation of this file.
1#pragma once
2
3#include "WeArtCommon.h"
4#include <string>
5#include <vector>
6#include <cassert>
7
8static HandSide StringToHandside(std::string &str) {
9 if (str == "LEFT") {
10 return HandSide::Left;
11 }
12 else if (str == "RIGHT") {
13 return HandSide::Right;
14 }
15 else {
16 assert(false);
17 return HandSide::Left;
18 }
19};
20
21
22static std::string HandsideToString(HandSide hs) {
23 if (hs == HandSide::Left) {
24 return "LEFT";
25 }
26 else if (hs == HandSide::Right) {
27 return "RIGHT";
28 }
29 else {
30 assert(false);
31 return "";
32 }
33};
34
35
36static ActuationPoint StringToActuationPoint(std::string& str) {
37 if (str == "THUMB") {
39 }
40 else if (str == "INDEX") {
42 }
43 else if (str == "MIDDLE") {
45 }
46 else if (str == "PALM") {
48 }
49 else {
50 assert(false);
52 }
53};
54
55
56static std::string ActuationPointToString(ActuationPoint ap) {
57 if (ap == ActuationPoint::Thumb) {
58 return "THUMB";
59 }
60 else if (ap == ActuationPoint::Index) {
61 return "INDEX";
62 }
63 else if (ap == ActuationPoint::Middle) {
64 return "MIDDLE";
65 }
66 else if (ap == ActuationPoint::Palm) {
67 return "PALM";
68 }
69 else {
70 assert(false);
71 return "";
72 }
73};
74
75static TrackingType StringToTrackingType(const std::string& str) {
76 if (str == "TrackType1")
79}
80
81static std::string TrackingTypeToString(TrackingType trackType) {
82 switch (trackType) {
84 return "";
86 return "TrackType1";
87 }
88 return "";
89}
90
95
96public:
97 virtual std::string getID() = 0;
98 virtual std::vector<std::string> getValues() = 0;
99 virtual void setValues(std::vector<std::string>& values) = 0;
100
101 virtual void setHandSide(HandSide hs) = 0;
102 virtual void setActuationPoint(ActuationPoint ap) = 0;
103};
104
109
110public:
111 virtual void setHandSide(HandSide hs) override {};
112 virtual void setActuationPoint(ActuationPoint ap) override {};
113
114 // This message carries no values.
115 virtual std::vector<std::string> getValues() override { return std::vector<std::string>(); };
116 virtual void setValues(std::vector<std::string>& values) override {};
117};
118
123
124protected:
127public:
128 virtual void setHandSide(HandSide hs) override { handSide = hs; };
129 virtual void setActuationPoint(ActuationPoint ap) override { actuationPoint = ap; };
130};
131
136
137public:
138
139 virtual std::string getID() override { return std::string("StartFromClient"); };
140
141 virtual std::vector<std::string> getValues() override {
142 std::vector<std::string> ret;
143 if (_trackType != TrackingType::DEFAULT) {
144 ret.push_back(WeArtConstants::WEART_SDK_TYPE);
147 }
148 return ret;
149 };
150
151 virtual void setValues(std::vector<std::string>& values) override {
152 if (values.empty())
153 _trackType = TrackingType::DEFAULT;
154 else
155 _trackType = StringToTrackingType(values[2]);
156 };
157
158private:
159 TrackingType _trackType;
160};
161
166
167public:
168 virtual std::string getID() override { return std::string("StopFromClient"); };
169};
170
175
176public:
177 virtual std::string getID() override { return std::string("StartCalibration"); };
178};
179
184
185public:
186 virtual std::string getID() override { return std::string("StopCalibration"); };
187};
188
193
194public:
195 virtual std::string getID() override { return std::string("exit"); };
196};
197
202
203public:
204 virtual std::string getID() override { return std::string("disconnect"); };
205};
206
211{
212public:
213 SetTemperatureMessage(const float t) : temperature(t) {};
215 virtual std::string getID() override { return std::string("temperature"); };
216
217 virtual std::vector<std::string> getValues() override {
218 std::vector<std::string> ret;
219 ret.push_back(std::to_string(temperature));
220 ret.push_back(HandsideToString(handSide));
221 ret.push_back(ActuationPointToString(actuationPoint));
222 return ret;
223 };
224
225 virtual void setValues(std::vector<std::string>& values) override {
226 assert(values.size() == 3);
227 temperature = std::stof(values[0]);
228 handSide = StringToHandside(values[1]);
229 actuationPoint = StringToActuationPoint(values[2]);
230 };
231
232protected:
233
235};
236
241{
242
243public:
244 virtual std::string getID() override { return std::string("stopTemperature"); };
245
246 virtual std::vector<std::string> getValues() override {
247 std::vector<std::string> ret;
248 ret.push_back(HandsideToString(handSide));
249 ret.push_back(ActuationPointToString(actuationPoint));
250 return ret;
251 };
252
253 virtual void setValues(std::vector<std::string>& values) override {
254 assert(values.size() == 2);
255 handSide = StringToHandside(values[0]);
256 actuationPoint = StringToActuationPoint(values[1]);
257 };
258};
259
264{
265
266public:
267 SetForceMessage(const float f[3]) : force{ f[0], f[1], f[2] } {};
269 virtual std::string getID() override { return std::string("force"); };
270
271 virtual std::vector<std::string> getValues() override {
272 std::vector<std::string> ret;
273 ret.push_back(std::to_string(force[0]));
274 ret.push_back(std::to_string(force[1]));
275 ret.push_back(std::to_string(force[2]));
276 ret.push_back(HandsideToString(handSide));
277 ret.push_back(ActuationPointToString(actuationPoint));
278 return ret;
279 };
280
281 virtual void setValues(std::vector<std::string>& values) override {
282 assert(values.size() == 5);
283 force[0] = std::stof(values[0]);
284 force[1] = std::stof(values[1]);
285 force[2] = std::stof(values[2]);
286 handSide = StringToHandside(values[3]);
287 actuationPoint = StringToActuationPoint(values[4]);
288 };
289
290protected:
291
292 float force[3];
293};
294
299{
300
301public:
302 virtual std::string getID() override { return std::string("stopForce"); };
303
304 virtual std::vector<std::string> getValues() override {
305 std::vector<std::string> ret;
306 ret.push_back(HandsideToString(handSide));
307 ret.push_back(ActuationPointToString(actuationPoint));
308 return ret;
309 };
310
311 virtual void setValues(std::vector<std::string>& values) override {
312 assert(values.size() == 2);
313 handSide = StringToHandside(values[0]);
314 actuationPoint = StringToActuationPoint(values[1]);
315 };
316};
317
322{
323
324public:
325 SetTextureMessage(const int idx, const float vel[3], const float vol) : index(idx), velocity{ vel[0], vel[1], vel[2] }, volume(vol) {};
327 virtual std::string getID() override { return std::string("texture"); };
328
329 virtual std::vector<std::string> getValues() override {
330 std::vector<std::string> ret;
331
332 // avoinding texture id out of bounds
333 if (index < WeArtConstants::minTextureIndex || index > WeArtConstants::maxTextureIndex) {
335 }
336
337 ret.push_back(std::to_string(index));
338 ret.push_back(std::to_string(velocity[0]));
339 ret.push_back(std::to_string(velocity[1]));
340 ret.push_back(std::to_string(velocity[2]));
341 ret.push_back(std::to_string(volume));
342 ret.push_back(HandsideToString(handSide));
343 ret.push_back(ActuationPointToString(actuationPoint));
344 return ret;
345 };
346
347 virtual void setValues(std::vector<std::string>& values) override {
348 assert(values.size() == 6);
349 index = std::stoi(values[0]);
350 velocity[0] = std::stof(values[1]);
351 velocity[1] = std::stof(values[2]);
352 velocity[2] = std::stof(values[3]);
353 volume = std::stof(values[4]);
354 handSide = StringToHandside(values[5]);
355 actuationPoint = StringToActuationPoint(values[6]);
356 };
357
358protected:
359
360 int index;
361 float velocity[3];
362 float volume;
363};
364
369{
370
371public:
372 virtual std::string getID() override { return std::string("stopTexture"); };
373
374 virtual std::vector<std::string> getValues() override {
375 std::vector<std::string> ret;
376 ret.push_back(HandsideToString(handSide));
377 ret.push_back(ActuationPointToString(actuationPoint));
378 return ret;
379 };
380
381 virtual void setValues(std::vector<std::string>& values) override {
382 assert(values.size() == 2);
383 handSide = StringToHandside(values[0]);
384 actuationPoint = StringToActuationPoint(values[1]);
385 };
386};
387
392{
393 // Closures
394 uint8 RightThumbClosure;
395 uint8 RightIndexClosure;
396 uint8 RightMiddleClosure;
397 uint8 RightPalmClosure;
398 uint8 LeftThumbClosure;
399 uint8 LeftIndexClosure;
400 uint8 LeftMiddleClosure;
401 uint8 LeftPalmClosure;
402
403 // Abductions
404 uint8 RightThumbAbduction;
405 uint8 LeftThumbAbduction;
406
407 TrackingType _trackingType;
408
409public:
410
411 virtual std::string getID() override { return std::string("Tracking"); };
412
413 struct Angles {
414 float X;
415 float Y;
416 float Z;
417 };
418
419 virtual std::vector<std::string> getValues() override {
420 std::vector<std::string> ret;
421 ret.push_back(std::to_string(RightThumbClosure));
422 ret.push_back(std::to_string(RightIndexClosure));
423 ret.push_back(std::to_string(RightMiddleClosure));
424 ret.push_back(std::to_string(RightPalmClosure));
425 ret.push_back(std::to_string(LeftThumbClosure));
426 ret.push_back(std::to_string(LeftIndexClosure));
427 ret.push_back(std::to_string(LeftMiddleClosure));
428 ret.push_back(std::to_string(LeftPalmClosure));
429 return ret;
430 };
431
432 virtual void setValues(std::vector<std::string>& values) override {
433 _trackingType = StringToTrackingType(values[0]);
434 switch (_trackingType) {
435 case TrackingType::DEFAULT:
436 {
437 assert(values.size() == 8);
438 RightThumbClosure = std::stoi(values[0]);
439 RightIndexClosure = std::stoi(values[1]);
440 RightMiddleClosure = std::stoi(values[2]);
441 RightPalmClosure = std::stoi(values[3]);
442 LeftThumbClosure = std::stoi(values[4]);
443 LeftIndexClosure = std::stoi(values[5]);
444 LeftMiddleClosure = std::stoi(values[6]);
445 LeftPalmClosure = std::stoi(values[7]);
446 break;
447 }
448 case TrackingType::WEART_HAND:
449 {
450 assert(values.size() == 9);
451 // Right
452 RightIndexClosure = std::stoi(values[1]);
453 RightThumbClosure = std::stoi(values[2]);
454 RightThumbAbduction = std::stoi(values[3]);
455 RightMiddleClosure = std::stoi(values[4]);
456
457 // Left
458 LeftIndexClosure = std::stoi(values[5]);
459 LeftThumbClosure = std::stoi(values[6]);
460 LeftThumbAbduction = std::stoi(values[7]);
461 LeftMiddleClosure = std::stoi(values[8]);
462 }
463 }
464 };
465
466 float GetClosure(HandSide handSide, ActuationPoint actuationPoint) {
467 uint8 byteValue = 0x00;
468 switch (handSide)
469 {
470 case HandSide::Left:
471 switch (actuationPoint)
472 {
473 case ActuationPoint::Thumb: byteValue = LeftThumbClosure; break;
474 case ActuationPoint::Index: byteValue = LeftIndexClosure; break;
475 case ActuationPoint::Middle: byteValue = LeftMiddleClosure; break;
476 case ActuationPoint::Palm: byteValue = LeftPalmClosure; break;
477 }
478 break;
479 case HandSide::Right:
480 switch (actuationPoint)
481 {
482 case ActuationPoint::Thumb: byteValue = RightThumbClosure; break;
483 case ActuationPoint::Index: byteValue = RightIndexClosure; break;
484 case ActuationPoint::Middle: byteValue = RightMiddleClosure; break;
485 case ActuationPoint::Palm: byteValue = RightPalmClosure; break;
486 }
487 break;
488 }
489
490 float num(byteValue);
491 float denom(255);
492 return num / denom;
493 }
494
495 float GetAbduction(HandSide handSide, ActuationPoint actuationPoint) {
496 float maxAbductionValue = 255;
497 switch (handSide) {
498 case HandSide::Left:
499 if (actuationPoint == ActuationPoint::Thumb) return ((float)LeftThumbAbduction) / maxAbductionValue;
500 break;
501 case HandSide::Right:
502 if (actuationPoint == ActuationPoint::Thumb) return ((float)RightThumbAbduction) / maxAbductionValue;
503 break;
504 }
505 return 0.0f;
506 }
507};
HandSide
Definition: WeArtCommon.h:7
@ Left
Definition: WeArtCommon.h:9
@ Right
Definition: WeArtCommon.h:10
TrackingType
Definition: WeArtCommon.h:26
@ DEFAULT
Deprecated, contains only closure values.
@ WEART_HAND
Tracking with closures, and abduction value for thumb.
ActuationPoint
Definition: WeArtCommon.h:17
@ Index
Definition: WeArtCommon.h:20
@ Thumb
Definition: WeArtCommon.h:19
@ Middle
Definition: WeArtCommon.h:21
@ Palm
Definition: WeArtCommon.h:22
Message to the middleware to disconnect.
Definition: WeArtMessages.h:201
virtual std::string getID() override
Definition: WeArtMessages.h:204
Message to the middleware to exit the connection.
Definition: WeArtMessages.h:192
virtual std::string getID() override
Definition: WeArtMessages.h:195
Message to the middleware to set the force of the effect.
Definition: WeArtMessages.h:264
float force[3]
Definition: WeArtMessages.h:292
virtual std::vector< std::string > getValues() override
Definition: WeArtMessages.h:271
SetForceMessage()
Definition: WeArtMessages.h:268
SetForceMessage(const float f[3])
Definition: WeArtMessages.h:267
virtual void setValues(std::vector< std::string > &values) override
Definition: WeArtMessages.h:281
virtual std::string getID() override
Definition: WeArtMessages.h:269
Message to the middleware to set the temperature of the effect.
Definition: WeArtMessages.h:211
float temperature
Definition: WeArtMessages.h:234
virtual std::vector< std::string > getValues() override
Definition: WeArtMessages.h:217
SetTemperatureMessage()
Definition: WeArtMessages.h:214
virtual void setValues(std::vector< std::string > &values) override
Definition: WeArtMessages.h:225
SetTemperatureMessage(const float t)
Definition: WeArtMessages.h:213
virtual std::string getID() override
Definition: WeArtMessages.h:215
Message to the middleware to set the texture of the effect.
Definition: WeArtMessages.h:322
float velocity[3]
Definition: WeArtMessages.h:361
float volume
Definition: WeArtMessages.h:362
virtual void setValues(std::vector< std::string > &values) override
Definition: WeArtMessages.h:347
SetTextureMessage()
Definition: WeArtMessages.h:326
virtual std::string getID() override
Definition: WeArtMessages.h:327
SetTextureMessage(const int idx, const float vel[3], const float vol)
Definition: WeArtMessages.h:325
int index
Definition: WeArtMessages.h:360
virtual std::vector< std::string > getValues() override
Definition: WeArtMessages.h:329
Message to the middleware to start the calibration.
Definition: WeArtMessages.h:174
virtual std::string getID() override
Definition: WeArtMessages.h:177
Message to middleware to start the connection.
Definition: WeArtMessages.h:135
virtual std::vector< std::string > getValues() override
Definition: WeArtMessages.h:141
virtual void setValues(std::vector< std::string > &values) override
Definition: WeArtMessages.h:151
virtual std::string getID() override
Definition: WeArtMessages.h:139
Message to the middleware to stop the calibration.
Definition: WeArtMessages.h:183
virtual std::string getID() override
Definition: WeArtMessages.h:186
Message to the middleware to stop the temperature of the effect.
Definition: WeArtMessages.h:299
virtual std::string getID() override
Definition: WeArtMessages.h:302
virtual std::vector< std::string > getValues() override
Definition: WeArtMessages.h:304
virtual void setValues(std::vector< std::string > &values) override
Definition: WeArtMessages.h:311
Message to middleware to stop the connection.
Definition: WeArtMessages.h:165
virtual std::string getID() override
Definition: WeArtMessages.h:168
Message to the middleware to stop the temperature of the effect.
Definition: WeArtMessages.h:241
virtual void setValues(std::vector< std::string > &values) override
Definition: WeArtMessages.h:253
virtual std::string getID() override
Definition: WeArtMessages.h:244
virtual std::vector< std::string > getValues() override
Definition: WeArtMessages.h:246
Message to the middleware to stop the texture of the effect.
Definition: WeArtMessages.h:369
virtual std::vector< std::string > getValues() override
Definition: WeArtMessages.h:374
virtual std::string getID() override
Definition: WeArtMessages.h:372
virtual void setValues(std::vector< std::string > &values) override
Definition: WeArtMessages.h:381
Generic Tracking message, contains information on closure and abduction (based on tracking type)
Definition: WeArtMessages.h:392
virtual std::vector< std::string > getValues() override
Definition: WeArtMessages.h:419
float GetClosure(HandSide handSide, ActuationPoint actuationPoint)
Definition: WeArtMessages.h:466
virtual std::string getID() override
Definition: WeArtMessages.h:411
float GetAbduction(HandSide handSide, ActuationPoint actuationPoint)
Definition: WeArtMessages.h:495
virtual void setValues(std::vector< std::string > &values) override
Definition: WeArtMessages.h:432
Generic Weart message.
Definition: WeArtMessages.h:94
virtual void setValues(std::vector< std::string > &values)=0
virtual std::string getID()=0
virtual std::vector< std::string > getValues()=0
virtual void setActuationPoint(ActuationPoint ap)=0
virtual void setHandSide(HandSide hs)=0
Message without handside or actuation point parameters.
Definition: WeArtMessages.h:108
virtual std::vector< std::string > getValues() override
Definition: WeArtMessages.h:115
virtual void setValues(std::vector< std::string > &values) override
Definition: WeArtMessages.h:116
virtual void setActuationPoint(ActuationPoint ap) override
Definition: WeArtMessages.h:112
virtual void setHandSide(HandSide hs) override
Definition: WeArtMessages.h:111
Message without handside or actuation point parameters.
Definition: WeArtMessages.h:122
ActuationPoint actuationPoint
Definition: WeArtMessages.h:126
virtual void setActuationPoint(ActuationPoint ap) override
Definition: WeArtMessages.h:129
virtual void setHandSide(HandSide hs) override
Definition: WeArtMessages.h:128
HandSide handSide
Definition: WeArtMessages.h:125
const int nullTextureIndex
Definition: WeArtCommon.h:93
const int maxTextureIndex
Definition: WeArtCommon.h:92
const std::string WEART_SDK_TRACK_TYPE
Definition: WeArtCommon.h:74
const std::string WEART_SDK_VERSION
Definition: WeArtCommon.h:73
const std::string WEART_SDK_TYPE
Definition: WeArtCommon.h:72
Definition: WeArtMessages.h:413
float Y
Definition: WeArtMessages.h:415
float Z
Definition: WeArtMessages.h:416
float X
Definition: WeArtMessages.h:414