NovintScaffold.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_NOVINT_NOVINTSCAFFOLD_H
17 #define SURGSIM_DEVICES_NOVINT_NOVINTSCAFFOLD_H
18 
19 #include <memory>
20 
23 
24 namespace SurgSim
25 {
26 namespace Device
27 {
28 
29 class NovintCommonDevice;
30 class NovintDevice;
31 
32 
41 {
42 public:
46  explicit NovintScaffold(std::shared_ptr<SurgSim::Framework::Logger> logger = nullptr);
47 
50 
53  std::shared_ptr<SurgSim::Framework::Logger> getLogger() const;
54 
58  static std::shared_ptr<NovintScaffold> getOrCreateSharedInstance();
59 
64 
65 private:
66 
68  struct StateData;
70  struct DeviceData;
72  class Callback;
74  class Handle;
75 
76  friend class NovintCommonDevice;
77  friend class NovintDevice;
78 
84  bool registerDevice(NovintCommonDevice* device);
85 
91  bool unregisterDevice(const NovintCommonDevice* device);
92 
97 
101  bool finalizeDeviceState(DeviceData* info);
102 
106  bool updateDevice(DeviceData* info);
107 
112  void checkDeviceHoming(DeviceData* info);
113 
125 
128  void setInputData(DeviceData* info);
129 
132  bool initializeSdk();
133 
136  bool finalizeSdk();
137 
141  bool runHapticFrame();
142 
145  bool createHapticLoop();
146 
150  bool destroyHapticLoop();
151 
154  bool startScheduler();
155 
158  bool stopScheduler();
159 
164  bool getGravityCompensation(const DeviceData* info, bool* gravityCompensationState);
165 
177  bool enforceGravityCompensation(const DeviceData* info, bool gravityCompensationState);
178 
183  bool setGravityCompensation(const DeviceData* info, bool gravityCompensationState);
184 
189  bool checkForFatalError(const char* message);
190 
196  bool checkForFatalError(bool previousError, const char* message)
197  {
198  bool newError = checkForFatalError(message);
199  return previousError || newError;
200  }
201 
204 
208  void setPositionScale(const NovintCommonDevice* device, double scale);
209 
213  void setOrientationScale(const NovintCommonDevice* device, double scale);
214 
216  std::shared_ptr<SurgSim::Framework::Logger> m_logger;
218  std::unique_ptr<StateData> m_state;
219 
222 };
223 
224 }; // namespace Device
225 }; // namespace SurgSim
226 
227 #endif // SURGSIM_DEVICES_NOVINT_NOVINTSCAFFOLD_H
A class that manages Novint Falcon devices.
Definition: NovintScaffold.h:40
NovintScaffold(std::shared_ptr< SurgSim::Framework::Logger > logger=nullptr)
Constructor.
Definition: NovintScaffold.cpp:377
Definition: DriveElementFromInputBehavior.cpp:27
static std::shared_ptr< NovintScaffold > getOrCreateSharedInstance()
Gets or creates the scaffold shared by all NovintDevice and Novint7DofDevice instances.
Definition: NovintScaffold.cpp:1178
bool checkForFatalError(const char *message)
Check for HDAL errors, display them, and signal fatal errors.
Definition: NovintScaffold.cpp:1118
bool unregisterDevice(const NovintCommonDevice *device)
Unregisters the specified device object.
Definition: NovintScaffold.cpp:486
LogLevel
Logging levels.
Definition: Logger.h:36
bool enforceGravityCompensation(const DeviceData *info, bool gravityCompensationState)
Attempts to force the gravity compensation flag for the current device to the specified value...
Definition: NovintScaffold.cpp:1026
A class implementing the communication with a Novint Falcon device.
Definition: NovintDevice.h:57
void checkDeviceHoming(DeviceData *info)
Checks whether a device has been homed.
Definition: NovintScaffold.cpp:668
static SurgSim::DataStructures::DataGroup buildDeviceInputData()
Builds the data layout for the application input (i.e. device output).
Definition: NovintScaffold.cpp:1139
static void setDefaultLogLevel(SurgSim::Framework::LogLevel logLevel)
Sets the default log level.
Definition: NovintScaffold.cpp:1184
bool setGravityCompensation(const DeviceData *info, bool gravityCompensationState)
Sets the gravity compensation flag for the current device, unless it's already set as desired...
Definition: NovintScaffold.cpp:1071
void setInputData(DeviceData *info)
Sets the input DataGroup, which will be pushed to the InputComponent.
Definition: NovintScaffold.cpp:881
bool initializeSdk()
Initializes the HDAL SDK.
Definition: NovintScaffold.cpp:895
void calculateForceAndTorque(DeviceData *info)
Calculates forces, and torques if the device is a 7Dof, and sends them to the HDAL.
Definition: NovintScaffold.cpp:717
bool destroyHapticLoop()
Destroys the haptic loop callback.
Definition: NovintScaffold.cpp:955
bool startScheduler()
Starts the HDAL scheduler.
Definition: NovintScaffold.cpp:970
void setPositionScale(const NovintCommonDevice *device, double scale)
Sets the position scale for this device.
Definition: NovintScaffold.cpp:1153
~NovintScaffold()
Destructor.
Definition: NovintScaffold.cpp:399
bool updateDevice(DeviceData *info)
Updates the device information for a single device.
Definition: NovintScaffold.cpp:592
bool runHapticFrame()
Executes the operations for a single haptic frame.
Definition: NovintScaffold.cpp:917
bool stopScheduler()
Stops the HDAL scheduler.
Definition: NovintScaffold.cpp:981
Definition: NovintScaffold.cpp:154
bool registerDevice(NovintCommonDevice *device)
Registers the specified device object.
Definition: NovintScaffold.cpp:425
A collection of NamedData objects.
Definition: DataGroup.h:66
std::shared_ptr< SurgSim::Framework::Logger > getLogger() const
Gets the logger used by this object and the devices it manages.
Definition: NovintScaffold.cpp:1189
bool finalizeDeviceState(DeviceData *info)
Finalizes a single device, destroying the necessary HDAL resources.
Definition: NovintScaffold.cpp:581
Definition: NovintScaffold.cpp:223
std::shared_ptr< SurgSim::Framework::Logger > m_logger
Logger used by the scaffold and all devices.
Definition: NovintScaffold.h:216
bool getGravityCompensation(const DeviceData *info, bool *gravityCompensationState)
Gets the gravity compensation flag for the current device.
Definition: NovintScaffold.cpp:992
bool createHapticLoop()
Creates the haptic loop callback.
Definition: NovintScaffold.cpp:934
Definition: NovintScaffold.cpp:324
Definition: NovintScaffold.cpp:59
static SurgSim::Framework::LogLevel m_defaultLogLevel
The default logging level.
Definition: NovintScaffold.h:221
bool initializeDeviceState(DeviceData *info)
Initializes a single device, creating the necessary HDAL resources.
Definition: NovintScaffold.cpp:533
A class implementing the communication with a generic Novint Falcon device.
Definition: NovintCommonDevice.h:35
std::unique_ptr< StateData > m_state
Internal scaffold state.
Definition: NovintScaffold.h:218
bool checkForFatalError(bool previousError, const char *message)
Check for HDAL errors, display them, and signal fatal errors.
Definition: NovintScaffold.h:196
bool finalizeSdk()
Finalizes (de-initializes) the HDAL SDK.
Definition: NovintScaffold.cpp:906
void setOrientationScale(const NovintCommonDevice *device, double scale)
Sets the orientation scale for this device.
Definition: NovintScaffold.cpp:1165