vrpn 07.35
Virtual Reality Peripheral Network
 
Loading...
Searching...
No Matches
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
17public: // 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 () {}
27public: // 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 }
50private: // variables
51 double in_;
52 double out_;
53};
54
55// Helper classes
56/*
57 * butterworth lowpass
58 */
60public: // 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 () {}
76public: // 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 }
89private: // variables
90 double in_[2];
91 double out_[2];
92};
93
95public: // constants
96
97 enum {
100 Update_Interval_Hz = 7372800 / 64 / 13 / Channels,
101 };
102 static const double Vel_Decay;
103
104public: // construction/destruction
105 // ctor
106 vrpn_inertiamouse (const char* name,
108 const char* port,
109 int baud_rate);
110
111 // factory method
112 static vrpn_inertiamouse* create (const char* name,
114 const char* port,
115 int baud_rate);
116 // dtor
118 if (vel_) {
119 try {
120 delete[] vel_;
121 } catch (...) {
122 fprintf(stderr, "vrpn_inertiamouse::~vrpn_inertiamouse(): delete failed\n");
123 return;
124 }
125 }
126 };
127
128public: // virtual methods
129
131 virtual void mainloop ();
132
133 virtual int reset(void); //< Set device back to starting config
134
135protected:
136 int status_; //< Used by mainloop() and get_report()
137 int numbuttons_; //< How many buttons to open
138 int numchannels_; //< How many analog channels to open
139
140 int expected_chars_; //< How many characters to expect in the report
141 unsigned char buffer_[512]; //< Buffer of characters in report
142 int bufcount_; //< How many characters we have so far
143
144 int null_radius_; //< The range over which no motion should be
145 // reported
146
147 struct timeval timestamp; //< Time of the last report from the device
148
149 double *vel_; // velocity update
150
151 dcblocker dcb_[Channels]; // dc blockers for all Channels
152 lowpass lp_[Channels]; // lowpass filters for all Channels
153
154 // Set all buttons, analogs and encoders back to 0
155 virtual void clear_values(void);
156
159 virtual int get_report(void);
160
162 virtual void report_changes (vrpn_uint32 class_of_service
165 virtual void report (vrpn_uint32 class_of_service
167
168 // NOTE: class_of_service is only applied to vrpn_Analog
169 // values, not vrpn_Button, which are always vrpn_RELIABLE
170};
171
172#endif
void swap(dcblocker &o)
dcblocker(dcblocker const &o)
double filter(double s)
lowpass(lowpass const &o)
double filter(double s)
vrpn_Button_Filter(const char *, vrpn_Connection *c=NULL)
Generic connection class not specific to the transport mechanism.
vrpn_Serial_Analog(const char *name, vrpn_Connection *connection, const char *port, int baud=9600, int bits=8, vrpn_SER_PARITY parity=vrpn_SER_PARITY_NONE, bool rts_flow=false)
static vrpn_inertiamouse * create(const char *name, vrpn_Connection *c, const char *port, int baud_rate)
virtual void report(vrpn_uint32 class_of_service=vrpn_CONNECTION_LOW_LATENCY)
send report whether or not changed
virtual void clear_values(void)
static const double Vel_Decay
vrpn_inertiamouse(const char *name, vrpn_Connection *c, const char *port, int baud_rate)
lowpass lp_[Channels]
virtual int get_report(void)
Try to read a report from the device. Returns 1 if complete report received, 0 otherwise....
virtual void report_changes(vrpn_uint32 class_of_service=vrpn_CONNECTION_LOW_LATENCY)
send report iff changed
dcblocker dcb_[Channels]
unsigned char buffer_[512]
struct timeval timestamp
#define VRPN_API
const vrpn_uint32 vrpn_CONNECTION_LOW_LATENCY