PhantomScaffold.h
Go to the documentation of this file.
1 // This file is a part of the OpenSurgSim project.
2 // Copyright 2013, SimQuest Solutions Inc.
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 // http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 
16 #ifndef SURGSIM_DEVICES_PHANTOM_PHANTOMSCAFFOLD_H
17 #define SURGSIM_DEVICES_PHANTOM_PHANTOMSCAFFOLD_H
18 
19 #include <memory>
20 
23 
24 namespace SurgSim
25 {
26 namespace Device
27 {
28 
29 class PhantomDevice;
30 
39 {
40 public:
44  explicit PhantomScaffold(std::shared_ptr<SurgSim::Framework::Logger> logger = nullptr);
45 
48 
51  std::shared_ptr<SurgSim::Framework::Logger> getLogger() const
52  {
53  return m_logger;
54  }
55 
59  static std::shared_ptr<PhantomScaffold> getOrCreateSharedInstance();
60 
65 
66 private:
67 
69  struct StateData;
71  struct DeviceData;
73  class Callback;
75  class Handle;
76 
77  friend class PhantomDevice;
78 
84  bool registerDevice(PhantomDevice* device);
85 
91  bool unregisterDevice(const PhantomDevice* device);
92 
97 
101  bool finalizeDeviceState(DeviceData* info);
102 
106  bool updateDevice(DeviceData* info);
107 
118 
121  void setInputData(DeviceData* info);
122 
125  bool initializeSdk();
126 
129  bool finalizeSdk();
130 
134  bool runHapticFrame();
135 
138  bool createHapticLoop();
139 
143  bool destroyHapticLoop();
144 
147  bool startScheduler();
148 
151  bool stopScheduler();
152 
156  bool checkForFatalError(const char* message);
157 
160 
161 
162 
164  std::shared_ptr<SurgSim::Framework::Logger> m_logger;
166  std::unique_ptr<StateData> m_state;
167 
170 };
171 
172 }; // namespace Device
173 }; // namespace SurgSim
174 
175 #endif // SURGSIM_DEVICES_PHANTOM_PHANTOMSCAFFOLD_H
std::unique_ptr< StateData > m_state
Internal scaffold state.
Definition: PhantomScaffold.h:166
bool startScheduler()
Starts the OpenHaptics scheduler.
Definition: PhantomScaffold.cpp:669
Definition: DriveElementFromInputBehavior.cpp:27
bool runHapticFrame()
Executes the operations for a single haptic frame.
Definition: PhantomScaffold.cpp:616
PhantomScaffold(std::shared_ptr< SurgSim::Framework::Logger > logger=nullptr)
Constructor.
Definition: PhantomScaffold.cpp:299
LogLevel
Logging levels.
Definition: Logger.h:36
bool destroyHapticLoop()
Destroys the haptic loop callback.
Definition: PhantomScaffold.cpp:654
void setInputData(DeviceData *info)
Sets the input DataGroup, which will be pushed to the InputComponent.
Definition: PhantomScaffold.cpp:577
bool checkForFatalError(const char *message)
Check for OpenHaptics HDAPI errors, display them, and signal fatal errors.
Definition: PhantomScaffold.cpp:691
~PhantomScaffold()
Destructor.
Definition: PhantomScaffold.cpp:321
bool finalizeSdk()
Finalizes (de-initializes) the OpenHaptics SDK.
Definition: PhantomScaffold.cpp:605
std::shared_ptr< SurgSim::Framework::Logger > m_logger
Logger used by the scaffold and all devices.
Definition: PhantomScaffold.h:164
bool registerDevice(PhantomDevice *device)
Registers the specified device object.
Definition: PhantomScaffold.cpp:347
static SurgSim::Framework::LogLevel m_defaultLogLevel
The default logging level.
Definition: PhantomScaffold.h:169
Definition: PhantomScaffold.cpp:145
Definition: PhantomScaffold.cpp:258
static void setDefaultLogLevel(SurgSim::Framework::LogLevel logLevel)
Sets the default log level.
Definition: PhantomScaffold.cpp:735
void calculateForceAndTorque(DeviceData *info)
Calculates forces and torques and sends them to the device library.
Definition: PhantomScaffold.cpp:517
A collection of NamedData objects.
Definition: DataGroup.h:66
bool finalizeDeviceState(DeviceData *info)
Finalizes a single device, destroying the necessary HDAPI resources.
Definition: PhantomScaffold.cpp:469
bool initializeDeviceState(DeviceData *info)
Initializes a single device, creating the necessary HDAPI resources.
Definition: PhantomScaffold.cpp:451
A class implementing the communication with a SensAble/Geomagic PHANTOM device.
Definition: PhantomDevice.h:57
static std::shared_ptr< PhantomScaffold > getOrCreateSharedInstance()
Gets or creates the scaffold shared by all PhantomDevice instances.
Definition: PhantomScaffold.cpp:729
bool unregisterDevice(const PhantomDevice *device)
Unregisters the specified device object.
Definition: PhantomScaffold.cpp:408
std::shared_ptr< SurgSim::Framework::Logger > getLogger() const
Gets the logger used by this object and the devices it manages.
Definition: PhantomScaffold.h:51
bool createHapticLoop()
Creates the haptic loop callback.
Definition: PhantomScaffold.cpp:633
static SurgSim::DataStructures::DataGroup buildDeviceInputData()
Builds the data layout for the application input (i.e. device output).
Definition: PhantomScaffold.cpp:717
bool updateDevice(DeviceData *info)
Updates the device information for a single device.
Definition: PhantomScaffold.cpp:480
bool initializeSdk()
Initializes the OpenHaptics SDK.
Definition: PhantomScaffold.cpp:594
Definition: PhantomScaffold.cpp:50
bool stopScheduler()
Stops the OpenHaptics scheduler.
Definition: PhantomScaffold.cpp:680
Definition: PhantomScaffold.cpp:212
A class that manages Sensable PHANTOM devices.
Definition: PhantomScaffold.h:38