7 #include "imstkHaplyDeviceClient.h" 8 #include "imstkLogger.h" 10 #include <SerialStream.h> 17 operator<<(std::ostream& os,
const HaplyDeviceClient::DeviceInfo& info)
19 os <<
"Device id: " << info.deviceId << std::endl;
20 os <<
"Device Model #: " <<
static_cast<int>(info.modelNumber) << std::endl;
21 os <<
"Hardware Version: " <<
static_cast<int>(info.hardwareVersion) << std::endl;
22 os <<
"Firmware Version: " <<
static_cast<int>(info.firmwareVersion) << std::endl;
27 HaplyDeviceClient::initialize()
29 m_deviceStream = std::make_shared<IO::SerialStream>(m_deviceName.c_str(),
true);
30 m_device = std::make_shared<Devices::Inverse3>(m_deviceStream.get());
32 if (m_handleName !=
"")
34 m_handleEnabled =
true;
35 m_handleDeviceStream = std::make_shared<IO::SerialStream>(m_handleName.c_str(),
true);
36 m_handleDevice = std::make_shared<HaplyHandle>(m_handleDeviceStream.get());
39 m_device->SendDeviceWakeup();
41 m_device->ReceiveDeviceInfo(&m_deviceInfo.deviceId,
42 &m_deviceInfo.modelNumber,
43 &m_deviceInfo.hardwareVersion, &m_deviceInfo.firmwareVersion,
49 m_handleDevice->SendDeviceWakeup();
50 while (m_lastReturnType != 0xD0)
52 m_handleDevice->Receive(&m_lastReturnType);
59 LOG(INFO) << m_deviceInfo;
63 HaplyDeviceClient::update()
66 m_deviceForce = m_force.cast<
float>();
67 m_deviceForce = Vec3f(
68 static_cast<float>(m_force[2]),
69 static_cast<float>(m_force[0]),
70 static_cast<float>(m_force[1]));
73 m_device->SendEndEffectorForce(m_deviceForce.data());
74 m_device->ReceiveEndEffectorState(m_devicePos.data(), m_deviceVelocity.data());
81 m_handleDevice->Receive(&m_lastReturnType);
85 m_transformLock.lock();
87 static_cast<double>(m_devicePos[1]),
88 static_cast<double>(m_devicePos[2]),
89 static_cast<double>(m_devicePos[0]));
92 m_orientation = Quatd(
93 static_cast<double>(m_handleDevice->m_statusResponse.quaternion[0]),
94 static_cast<double>(m_handleDevice->m_statusResponse.quaternion[1]),
95 static_cast<double>(m_handleDevice->m_statusResponse.quaternion[2]),
96 static_cast<double>(m_handleDevice->m_statusResponse.quaternion[3]));
98 m_transformLock.unlock();
102 HaplyDeviceClient::disable()
104 LOG(INFO) <<
"Closing Haply device streams";
105 m_deviceStream->CloseDevice();
108 m_handleDeviceStream->CloseDevice();