Skip to content

Commit 851c5c8

Browse files
committed
[src] Fix several bugs in the integration of the wireless stylus
1 parent d2f11d9 commit 851c5c8

1 file changed

Lines changed: 13 additions & 10 deletions

File tree

src/SofaHaplyRobotics/Haply_Inverse3Controller.cpp

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ namespace sofa::HaplyRobotics
4242
// Static constants
4343
const std::string Haply_Inverse3Controller::inverseKey_ = "inverse3";
4444
const std::string Haply_Inverse3Controller::deviceIdKey_ = "device_id";
45-
const std::string Haply_Inverse3Controller::gripIdKey_ = "verse_grip";
46-
const std::string Haply_Inverse3Controller::wirelessGripIdKey_ = "wireless_verse_grip";
45+
const std::string Haply_Inverse3Controller::gripIdKey_ = "verse_grip"; // Refered as "VerseGrip Quill" on Haply developer doc.
46+
const std::string Haply_Inverse3Controller::wirelessGripIdKey_ = "wireless_verse_grip"; // Refered as "VerseGrip Stylus" on Haply developer doc.
4747

4848

4949
using namespace sofa::helper::system::thread;
@@ -60,9 +60,9 @@ Haply_Inverse3Controller::Haply_Inverse3Controller()
6060
, d_orientationBase(initData(&d_orientationBase, Quat(0, 0, 0, 1), "orientationBase", "Orientation of the device base in the SOFA scene world coordinates"))
6161
, d_scale(initData(&d_scale, 1.0, "scale", "Default scale applied to the Device coordinates"))
6262

63-
, d_handleButtonA(initData(&d_handleButtonA, false, "handleButtonA", "Bool value showing if first button is pressed"))
64-
, d_handleButtonB(initData(&d_handleButtonB, false, "handleButtonA", "Bool value showing if second button is pressed"))
65-
, d_handleButtonC(initData(&d_handleButtonC, false, "handleButtonA", "Bool value showing if third button is pressed"))
63+
, d_handleButtonA(initData(&d_handleButtonA, false, "handleButtonA", "Bool value returning if VerseGrip Stylus first button (resp. VerseGrip Quill single button) is pressed."))
64+
, d_handleButtonB(initData(&d_handleButtonB, false, "handleButtonB", "Bool value returning if VerseGrip Stylus second button is pressed"))
65+
, d_handleButtonC(initData(&d_handleButtonC, false, "handleButtonC", "Bool value returning if VerseGrip Stylus calibrate button is pressed"))
6666
, d_posDevice(initData(&d_posDevice, "positionDevice", "position of the device end-effector in SOFA frame"))
6767
, d_rawForceDevice(initData(&d_rawForceDevice, "rawForceDevice", "For debug: raw values sent to the device in the device frame"))
6868
, d_dampingForce(initData(&d_dampingForce, 0.0001, "damping", "Default damping applied to the force feedback"))
@@ -327,7 +327,7 @@ void Haply_Inverse3Controller::HapticsHandling(const std::string& msg)
327327
}
328328
}
329329

330-
if (data.contains(gripIdKey_))
330+
if (data.contains(gripIdKey_) && !data[gripIdKey_].empty())
331331
{
332332
// example of grip data
333333
// grip_id: 61576 -> {"button":false, "hall" : 1, "orientation" : {"w":0.71655273, "x" : 0.19647217, "y" : 0.6290283, "z" : -0.22833252},
@@ -351,8 +351,11 @@ void Haply_Inverse3Controller::HapticsHandling(const std::string& msg)
351351
m_hapticData.buttonC = false;
352352
}
353353
}
354-
else if (data.contains(wirelessGripIdKey_))
354+
else if (data.contains(wirelessGripIdKey_) && !data[wirelessGripIdKey_].empty())
355355
{
356+
// example of wireless grip data
357+
// {"device_id":"1534","state":{"battery_level":0.55833346,"battery_voltage":3.935,"buttons":{"a":false,"b":false,"c":false},"hall":18,"orientation":{"w":-0.02947998, "x":-0.22390747, "y" : 0.65689087, "z" : 0.71691895},
358+
// "transform":{"position":{"x":0, "y" : 0, "z" : 0}, "rotation" : {"w":1, "x" : 0, "y" : 0, "z" : 0}, "scale" : {"x":1, "y" : 1, "z":1}}},"status":{"awake":true,"connected":true,"ready":true}}
356359
for (auto& el : data[wirelessGripIdKey_])
357360
{
358361
const json& state = el["state"];
@@ -366,9 +369,9 @@ void Haply_Inverse3Controller::HapticsHandling(const std::string& msg)
366369
m_hapticData.orientation[1] = qy;
367370
m_hapticData.orientation[2] = qz;
368371
m_hapticData.orientation[3] = qw;
369-
m_hapticData.buttonA = state["button"]["a"].get<bool>();
370-
m_hapticData.buttonB = state["button"]["b"].get<bool>();
371-
m_hapticData.buttonC = state["button"]["c"].get<bool>();
372+
m_hapticData.buttonA = state["buttons"]["a"].get<bool>();
373+
m_hapticData.buttonB = state["buttons"]["b"].get<bool>();
374+
m_hapticData.buttonC = state["buttons"]["c"].get<bool>();
372375
}
373376
}
374377

0 commit comments

Comments
 (0)