vrpn  07.33
Virtual Reality Peripheral Network
vrpn_inertiamouse.h
Go to the documentation of this file.
1 //-----------------------------------------------------------------------------------------
2 // Driver for the Bauhaus University Weimar "inertiamouse" device. The class for this
3 // device is found at the end of the file, after two helper classes.
4 
5 #ifndef VRPN_INERTIAMOUSE_H
6 #define VRPN_INERTIAMOUSE_H
7 
8 #include "vrpn_Analog.h" // for vrpn_Serial_Analog
9 #include "vrpn_Button.h" // for vrpn_Button_Filter
10 #include "vrpn_Configure.h" // for VRPN_API
11 #include "vrpn_Connection.h" // for vrpn_CONNECTION_LOW_LATENCY, etc
12 #include "vrpn_Shared.h" // for timeval
13 #include "vrpn_Types.h" // for vrpn_uint32
14 
15 // Helper classes
17 public: // ctors, dtor
19  : in_ (0.0),
20  out_ (0.0)
21  {}
22  dcblocker (dcblocker const& o)
23  : in_ (o.in_),
24  out_ (o.out_)
25  {}
26  ~dcblocker () throw () {}
27 public: // methods
28  void swap (dcblocker& o) throw ()
29  {
30  double t;
31  t = in_; in_ = o.in_; o.in_ = t;
32  t = out_; out_ = o.out_; o.out_ = t;
33  }
34  dcblocker& operator= (dcblocker const& o)
35  {
36  dcblocker tmp (o);
37  swap (tmp);
38  return *this;
39  }
40  double filter (double s)
41  {
42  out_ = s - in_ + (0.95 * out_);
43  in_ = s;
44  return out_;
45  }
46  void reset ()
47  {
48  in_ = out_ = 0.0;
49  }
50 private: // variables
51  double in_;
52  double out_;
53 };
54 
55 // Helper classes
56 /*
57  * butterworth lowpass
58  */
60 public: // ctors, dtor
62  {
63  in_[0] = 0.0;
64  in_[1] = 0.0;
65  out_[0] = 0.0;
66  out_[1] = 0.0;
67  }
68  lowpass (lowpass const& o)
69  {
70  in_[0] = o.in_[0];
71  in_[1] = o.in_[1];
72  out_[0] = o.out_[0];
73  out_[1] = o.out_[1];
74  }
75  ~lowpass () throw () {}
76 public: // methods
77  double filter (double s)
78  {
79  in_[0] = in_[1];
80  in_[1] = s / 6.242183581;
81  out_[0] = out_[1];
82  out_[1] = in_[0] + in_[1] + (0.6795992982 * out_[0]);
83  return out_[1];
84  }
85  void reset ()
86  {
87  in_[0] = in_[1] = out_[0] = out_[1] = 0.0;
88  }
89 private: // variables
90  double in_[2];
91  double out_[2];
92 };
93 
95 public: // constants
96 
97  enum {
98  Channels = 6,
99  Buttons = 2,
100  Update_Interval_Hz = 7372800 / 64 / 13 / Channels,
101  };
102  static const double Vel_Decay;
103 
104 public: // construction/destruction
105  // ctor
106  vrpn_inertiamouse (const char* name,
107  vrpn_Connection* c,
108  const char* port,
109  int baud_rate);
110 
111  // factory method
112  static vrpn_inertiamouse* create (const char* name,
113  vrpn_Connection* c,
114  const char* port,
115  int baud_rate);
116  // dtor
117  ~vrpn_inertiamouse () { if (vel_) { delete [] vel_;} };
118 
119 public: // virtual methods
120 
122  virtual void mainloop ();
123 
124  virtual int reset(void); //< Set device back to starting config
125 
126 protected:
127  int status_; //< Used by mainloop() and get_report()
128  int numbuttons_; //< How many buttons to open
129  int numchannels_; //< How many analog channels to open
130 
131  int expected_chars_; //< How many characters to expect in the report
132  unsigned char buffer_[512]; //< Buffer of characters in report
133  int bufcount_; //< How many characters we have so far
134 
135  int null_radius_; //< The range over which no motion should be
136  // reported
137 
138  struct timeval timestamp; //< Time of the last report from the device
139 
140  double *vel_; // velocity update
141 
142  dcblocker dcb_[Channels]; // dc blockers for all Channels
143  lowpass lp_[Channels]; // lowpass filters for all Channels
144 
145  // Set all buttons, analogs and encoders back to 0
146  virtual void clear_values(void);
147 
150  virtual int get_report(void);
151 
153  virtual void report_changes (vrpn_uint32 class_of_service
156  virtual void report (vrpn_uint32 class_of_service
158 
159  // NOTE: class_of_service is only applied to vrpn_Analog
160  // values, not vrpn_Button, which are always vrpn_RELIABLE
161 };
162 
163 #endif
vrpn_Serial_Analog
Definition: vrpn_Analog.h:63
dcblocker::~dcblocker
~dcblocker()
Definition: vrpn_inertiamouse.h:26
vrpn_Button_Filter::report_changes
virtual void report_changes(void)
Definition: vrpn_Button.C:382
vrpn_Types.h
vrpn_inertiamouse::bufcount_
int bufcount_
Definition: vrpn_inertiamouse.h:133
vrpn_inertiamouse::~vrpn_inertiamouse
~vrpn_inertiamouse()
Definition: vrpn_inertiamouse.h:117
vrpn_Analog::report
virtual void report(vrpn_uint32 class_of_service=vrpn_CONNECTION_LOW_LATENCY, const struct timeval time=vrpn_ANALOG_NOW)
Send a report whether something has changed or not (for servers) Optionally, tell what time to stamp ...
Definition: vrpn_Analog.C:94
dcblocker::reset
void reset()
Definition: vrpn_inertiamouse.h:46
vrpn_inertiamouse::vel_
double * vel_
Definition: vrpn_inertiamouse.h:140
dcblocker::dcblocker
dcblocker(dcblocker const &o)
Definition: vrpn_inertiamouse.h:22
vrpn_CONNECTION_LOW_LATENCY
const vrpn_uint32 vrpn_CONNECTION_LOW_LATENCY
Definition: vrpn_Connection.h:122
vrpn_inertiamouse::status_
int status_
Definition: vrpn_inertiamouse.h:127
vrpn_inertiamouse::Vel_Decay
static const double Vel_Decay
Definition: vrpn_inertiamouse.h:102
dcblocker::filter
double filter(double s)
Definition: vrpn_inertiamouse.h:40
lowpass::lowpass
lowpass(lowpass const &o)
Definition: vrpn_inertiamouse.h:68
vrpn_Shared.h
vrpn_Button.h
dcblocker
Definition: vrpn_inertiamouse.h:16
vrpn_BaseClass::mainloop
virtual void mainloop()=0
Called once through each main loop iteration to handle updates. Remote object mainloop() should call ...
lowpass
Definition: vrpn_inertiamouse.h:59
vrpn_Connection
Generic connection class not specific to the transport mechanism.
Definition: vrpn_Connection.h:510
vrpn_Connection.h
vrpn_inertiamouse::numchannels_
int numchannels_
Definition: vrpn_inertiamouse.h:129
lowpass::filter
double filter(double s)
Definition: vrpn_inertiamouse.h:77
dcblocker::dcblocker
dcblocker()
Definition: vrpn_inertiamouse.h:18
lowpass::~lowpass
~lowpass()
Definition: vrpn_inertiamouse.h:75
dcblocker::swap
void swap(dcblocker &o)
Definition: vrpn_inertiamouse.h:28
vrpn_inertiamouse::null_radius_
int null_radius_
Definition: vrpn_inertiamouse.h:135
vrpn_Analog.h
lowpass::lowpass
lowpass()
Definition: vrpn_inertiamouse.h:61
lowpass::reset
void reset()
Definition: vrpn_inertiamouse.h:85
vrpn_Configure.h
vrpn_inertiamouse
Definition: vrpn_inertiamouse.h:94
vrpn_inertiamouse::numbuttons_
int numbuttons_
Definition: vrpn_inertiamouse.h:128
vrpn_inertiamouse::expected_chars_
int expected_chars_
Definition: vrpn_inertiamouse.h:131
VRPN_API
#define VRPN_API
Definition: vrpn_Configure.h:646
vrpn_Button_Filter
All button servers should derive from this class, which provides the ability to turn any of the butto...
Definition: vrpn_Button.h:65