iMSTK
Interactive Medical Simulation Toolkit
imstkHaplyDeviceClient.h
1 /*
2 ** This file is part of the Interactive Medical Simulation Toolkit (iMSTK)
3 ** iMSTK is distributed under the Apache License, Version 2.0.
4 ** See accompanying NOTICE for details.
5 */
6 
7 #pragma once
8 
9 #include "imstkDeviceClient.h"
10 
11 #include <Handle.h>
12 #include <Inverse3.h>
13 #include <UUID.h>
14 
15 namespace Haply
16 {
17 namespace HardwareAPI
18 {
19 namespace Devices
20 {
21 class Handle;
22 class Inverse3;
23 } // namespace Devices
24 namespace IO { class SerialStream; }
25 } // namespace HardwareAPI
26 } // namespace Haply
27 
28 namespace imstk
29 {
37 {
38 struct DeviceInfo
39 {
40  uint16_t deviceId = -1;
41  unsigned char modelNumber = -1;
42  unsigned char hardwareVersion = -1;
43  unsigned char firmwareVersion = -1;
44  Haply::HardwareAPI::UUID quat;
45 };
46 
47 friend std::ostream& operator<<(std::ostream& os, const DeviceInfo& info);
48 
49 friend class HaplyDeviceManager;
50 
51 public:
52  ~HaplyDeviceClient() override = default;
53 
57  void update() override;
58 
59 protected:
64  HaplyDeviceClient(const std::string& name = "", const std::string& handleName = "") :
65  DeviceClient(name, "localhost"), m_handleName(handleName) { }
66 
70  void initialize();
71 
75  void disable();
76 
77 private:
81  class HaplyHandle : public Haply::HardwareAPI::Devices::Handle
82  {
83  public:
84  HaplyHandle(std::iostream* stream) : Handle(stream) { }
85 
86  protected:
87  void OnReceiveHandleInfo(HandleInfoResponse& response) override { m_infoResponse = response; }
88  void OnReceiveHandleStatusMessage(HandleStatusResponse& response) override { m_statusResponse = response; }
89  void OnReceiveHandleErrorResponse(HandleErrorResponse& response) override { m_errorResponse = response; }
90 
91  public:
92  Haply::HardwareAPI::Devices::Handle::HandleInfoResponse m_infoResponse;
93  Haply::HardwareAPI::Devices::Handle::HandleStatusResponse m_statusResponse;
94  //Haply::HardwareAPI::Devices::Handle::HandleStatusResponse statusResponseCalibrated;
95  Haply::HardwareAPI::Devices::Handle::HandleErrorResponse m_errorResponse;
96  };
97 
98 private:
99  std::shared_ptr<Haply::HardwareAPI::Devices::Inverse3> m_device;
100  std::shared_ptr<Haply::HardwareAPI::IO::SerialStream> m_deviceStream;
101 
102  std::string m_handleName = "";
103  bool m_handleEnabled = false;
104  unsigned char m_lastReturnType;
105  std::shared_ptr<HaplyHandle> m_handleDevice;
106  std::shared_ptr<Haply::HardwareAPI::IO::SerialStream> m_handleDeviceStream;
107  Haply::HardwareAPI::Devices::Inverse3::EndEffectorStateResponse m_deviceResponse;
108 
109  Vec3f m_devicePos = Vec3f::Zero();
110  Vec3f m_deviceVelocity = Vec3f::Zero();
111  Vec3f m_deviceForce = Vec3f::Zero();
112  DeviceInfo m_deviceInfo;
113 };
114 } // namespace imstk
The device client&#39;s represents the device and provides an interface to acquire data from a device...
HaplyDeviceClient(const std::string &name="", const std::string &handleName="")
Constructor/Destructor, only the DeviceManager can construct.
Subclass of DeviceClient for haply, currently implemented only for the Inverse3. Warning: This code i...
Compound Geometry.
Devices manager using Haply, only supports Inverse3 right now Warning: This code is based off an earl...