opensurgsim
LabJackDevice.h
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_LABJACK_LABJACKDEVICE_H
17 #define SURGSIM_DEVICES_LABJACK_LABJACKDEVICE_H
18 
19 #include <memory>
20 #include <string>
21 #include <unordered_map>
22 #include <unordered_set>
23 
24 #include "SurgSim/DataStructures/OptionalValue.h"
25 #include "SurgSim/Input/CommonDevice.h"
26 
27 namespace SurgSim
28 {
29 namespace Devices
30 {
31 class LabJackScaffold;
32 
33 SURGSIM_STATIC_REGISTRATION(LabJackDevice);
34 
35 namespace LabJack
36 {
40 enum TIMER
41 {
42  TIMER0,
43  TIMER1,
44  TIMER2,
45  TIMER3,
46  TIMER4,
47  TIMER5
48 };
49 
50 enum FIO_LINE
51 {
52  FIO0,
53  FIO1,
54  FIO2,
55  FIO3,
56  FIO4,
57  FIO5,
58  FIO6,
59  FIO7
60 };
61 
62 enum EIO_LINE
63 {
64  EIO0 = 8,
65  EIO1,
66  EIO2,
67  EIO3,
68  EIO4,
69  EIO5,
70  EIO6,
71  EIO7
72 };
73 
74 enum CIO_LINE
75 {
76  CIO0 = 16,
77  CIO1,
78  CIO2,
79  CIO3
80 };
81 
82 enum MIO_LINE
83 {
84  MIO0 = 20,
85  MIO1,
86  MIO2
87 };
88 
89 enum AIN
90 {
91  AIN0,
92  AIN1,
93  AIN2,
94  AIN3,
95  AIN4,
96  AIN5,
97  AIN6,
98  AIN7,
99  AIN8,
100  AIN9,
101  AIN10,
102  AIN11,
103  AIN12,
104  AIN13,
105  AIN14,
106  AIN15
107 };
108 
109 enum DAC
110 {
111  DAC0,
112  DAC1
113 };
115 
117 enum Model
118 {
119  MODEL_SEARCH = -1,
120  MODEL_UE9 = 9,
121  MODEL_U3 = 3,
122  MODEL_U6 = 6
123 };
124 
127 {
128  CONNECTION_SEARCH = -1,
129  CONNECTION_USB = 1,
130  CONNECTION_ETHERNET = 2,
131  CONNECTION_ETHERNET_MB = 3,
132  CONNECTION_ETHERNET_DATA_ONLY = 4
133 };
134 
139 {
140  TIMERBASE_DEFAULT = -1,
141  TIMERBASE_0 = 0,
142  TIMERBASE_1 = 1,
143  TIMERBASE_2 = 2,
144  TIMERBASE_3 = 3,
145  TIMERBASE_4 = 4,
146  TIMERBASE_5 = 5,
147  TIMERBASE_6 = 6,
148  TIMERBASE_20 = 20,
149  TIMERBASE_21 = 21,
150  TIMERBASE_22 = 22,
151  TIMERBASE_23 = 23,
152  TIMERBASE_24 = 24,
153  TIMERBASE_25 = 25,
154  TIMERBASE_26 = 26
155 };
156 
161 {
162  TIMERMODE_PWM_16BIT = 0, // 16 bit PWM
163  TIMERMODE_PWM_8BIT = 1, // 8 bit PWM
164  TIMERMODE_RISING_EDGES_32BIT = 2, // 32-bit rising to rising edge measurement
165  TIMERMODE_FALLING_EDGES_32BIT = 3, // 32-bit falling to falling edge measurement
166  TIMERMODE_DUTY_CYCLE = 4, // duty cycle measurement
167  TIMERMODE_FIRMWARE_COUNTER = 5, // firmware based rising edge counter
168  TIMERMODE_FIRMWARE_COUNTER_DEBOUNCED = 6, // firmware counter with debounce
169  TIMERMODE_FREQUENCY_OUTPUT = 7, // frequency output
170  TIMERMODE_QUADRATURE = 8, // Quadrature
171  TIMERMODE_TIMER_STOP = 9, // stops another timer after n pulses
172  TIMERMODE_SYSTEM_TIMER_LOWER_32BITS = 10, // read lower 32-bits of system timer
173  TIMERMODE_SYSTEM_TIMER_UPPR_32BITS = 11, // read upper 32-bits of system timer
174  TIMERMODE_RISING_EDGES_16BIT = 12, // 16-bit rising to rising edge measurement
175  TIMERMODE_FALLING_EDGES_16BIT = 13, // 16-bit falling to falling edge measurement
176  TIMERMODE_LINE_TO_LINE = 14 // Line to Line measurement
177 };
178 
181 {
185  bool operator==(const TimerSettings& other) const
186  {
187  return (mode == other.mode) && (initialValue == other.initialValue);
188  }
189 
192 
195 };
196 
199 enum Range : SURGSIM_ENUM_TYPE;
200 
203 {
207  bool operator==(const AnalogInputSettings& other) const
208  {
209  return (negativeChannel == other.negativeChannel) && (range == other.range);
210  }
211 
213  Range range;
214 
217 };
218 };
219 
263 {
264 public:
267  explicit LabJackDevice(const std::string& uniqueName);
268 
269  SURGSIM_CLASSNAME(SurgSim::Devices::LabJackDevice);
270 
272  virtual ~LabJackDevice();
273 
274  bool initialize() override;
275 
276  bool isInitialized() const override;
277 
281  void setModel(LabJack::Model model);
282 
284  LabJack::Model getModel() const;
285 
289  void setConnection(LabJack::Connection connection);
290 
292  LabJack::Connection getConnection() const;
293 
298  void setAddress(std::string address);
299 
301  const std::string& getAddress() const;
302 
312  void setResetOnDestruct(bool reset);
313 
316  bool getResetOnDestruct() const;
317 
321  void enableDigitalInput(int channel);
322 
326  void setDigitalInputs(const std::unordered_set<int>& digitalInputChannels);
327 
329  const std::unordered_set<int>& getDigitalInputs() const;
330 
334  void enableDigitalOutput(int channel);
335 
339  void setDigitalOutputs(const std::unordered_set<int>& digitalOutputChannels);
340 
342  const std::unordered_set<int>& getDigitalOutputs() const;
343 
348  void setTimerBase(LabJack::TimerBase base);
349 
351  LabJack::TimerBase getTimerBase() const;
352 
357  void setTimerClockDivisor(int divisor);
358 
360  int getTimerClockDivisor() const;
361 
365  void setTimerCounterPinOffset(int offset);
366 
368  int getTimerCounterPinOffset() const;
369 
377  void enableTimer(int index, LabJack::TimerMode mode);
378 
388  void enableTimer(int index, LabJack::TimerMode mode, int initialValue);
389 
394  void setTimers(const std::unordered_map<int, LabJack::TimerSettings>& timers);
395 
397  const std::unordered_map<int, LabJack::TimerSettings>& getTimers() const;
398 
402  void setMaximumUpdateRate(double rate);
403 
405  double getMaximumUpdateRate() const;
406 
413  void enableAnalogInput(int positiveChannel, LabJack::Range range, int negativeChannel);
414 
419  void enableAnalogInput(int channel, LabJack::Range range);
420 
426  void setAnalogInputs(const std::unordered_map<int, LabJack::AnalogInputSettings>& analogInputs);
427 
429  const std::unordered_map<int, LabJack::AnalogInputSettings>& getAnalogInputs() const;
430 
434  void enableAnalogOutput(int channel);
435 
440  void setAnalogOutputs(const std::unordered_set<int>& analogOutputChannels);
441 
443  const std::unordered_set<int>& getAnalogOutputs() const;
444 
450  void setAnalogInputResolution(int resolution);
451 
453  int getAnalogInputResolution() const;
454 
460  void setAnalogInputSettling(int settling);
461 
463  int getAnalogInputSettling() const;
464 
465 private:
466  friend class LabJackScaffold;
467 
468  bool finalize() override;
469 
471  std::shared_ptr<LabJackScaffold> m_scaffold;
472 
474  LabJack::Model m_model;
475 
477  LabJack::Connection m_connection;
478 
480  std::string m_address;
481 
483  bool m_reset;
484 
486  std::unordered_set<int> m_digitalInputChannels;
487 
489  std::unordered_map<int, LabJack::AnalogInputSettings> m_analogInputs;
490 
492  std::unordered_set<int> m_digitalOutputChannels;
493 
495  std::unordered_set<int> m_analogOutputChannels;
496 
500  LabJack::TimerBase m_timerBase;
501 
503  int m_timerClockDivisor;
504 
506  int m_timerCounterPinOffset;
507 
509  std::unordered_map<int, LabJack::TimerSettings> m_timers;
510 
512  double m_threadRate;
513 
515  int m_analogInputResolution;
516 
518  int m_analogInputSettling;
519 };
520 
521 }; // namespace Devices
522 }; // namespace SurgSim
523 
524 SURGSIM_SERIALIZABLE_ENUM(SurgSim::Devices::LabJack::Range, (RANGE_NONE)(RANGE_20)(RANGE_10)(RANGE_5)(RANGE_4)(RANGE_2_POINT_5)(RANGE_2)(RANGE_1_POINT_25)(RANGE_1)(RANGE_0_POINT_625)(RANGE_0_POINT_1)(RANGE_0_POINT_01));
525 
526 #endif // SURGSIM_DEVICES_LABJACK_LABJACKDEVICE_H
Wraps glewInit() to separate the glew opengl definitions from the osg opengl definitions only imgui n...
Definition: AddRandomSphereBehavior.cpp:36
SurgSim::DataStructures::OptionalValue< int > negativeChannel
The negative channel.
Definition: LabJackDevice.h:216
The analog input ranges.
Definition: LabJackDevice.h:202
Connection
The connection (i.e., communication media) for LabJacks. Numbers come from LabJackUD.h.
Definition: LabJackDevice.h:126
TimerMode
The timer modes.
Definition: LabJackDevice.h:160
Model
The models of LabJack devices. Numbers come from LabJackUD.h.
Definition: LabJackDevice.h:117
A class implementing the communication with a LabJack data acquisition (DAQ) device.
Definition: LabJackDevice.h:262
TimerBase
The timer base frequencies for LabJacks.
Definition: LabJackDevice.h:138
A class that implements the behavior of LabJackDevice objects.
Definition: LabJackScaffold.h:41
bool operator==(const AnalogInputSettings &other) const
Equality comparison.
Definition: LabJackDevice.h:207
Range range
The range.
Definition: LabJackDevice.h:213
A class that implements some common management code on top of the DeviceInterface.
Definition: CommonDevice.h:35
TIMER
Definition: LabJackDevice.h:40
A struct holding the data to be associated with a Timer.
Definition: LabJackDevice.h:180
TimerMode mode
The mode.
Definition: LabJackDevice.h:191
SurgSim::DataStructures::OptionalValue< int > initialValue
The initial value.
Definition: LabJackDevice.h:194
bool operator==(const TimerSettings &other) const
Equality comparison.
Definition: LabJackDevice.h:185