vrpn 07.36
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 }
68public: // methods
69 double filter (double s)
70 {
71 in_[0] = in_[1];
72 in_[1] = s / 6.242183581;
73 out_[0] = out_[1];
74 out_[1] = in_[0] + in_[1] + (0.6795992982 * out_[0]);
75 return out_[1];
76 }
77 void reset ()
78 {
79 in_[0] = in_[1] = out_[0] = out_[1] = 0.0;
80 }
81private: // variables
82 double in_[2];
83 double out_[2];
84};
85
87public: // constants
88
89 enum {
92 Update_Interval_Hz = 7372800 / 64 / 13 / Channels,
93 };
94 static const double Vel_Decay;
95
96public: // construction/destruction
97 // ctor
98 vrpn_inertiamouse (const char* name,
100 const char* port,
101 int baud_rate);
102
103 // factory method
104 static vrpn_inertiamouse* create (const char* name,
106 const char* port,
107 int baud_rate);
108 // dtor
110 if (vel_) {
111 try {
112 delete[] vel_;
113 } catch (...) {
114 fprintf(stderr, "vrpn_inertiamouse::~vrpn_inertiamouse(): delete failed\n");
115 return;
116 }
117 }
118 };
119
120public: // virtual methods
121
123 virtual void mainloop ();
124
125 virtual int reset(void); //< Set device back to starting config
126
127protected:
128 int status_; //< Used by mainloop() and get_report()
129 int numbuttons_; //< How many buttons to open
130 int numchannels_; //< How many analog channels to open
131
132 int expected_chars_; //< How many characters to expect in the report
133 unsigned char buffer_[512]; //< Buffer of characters in report
134 int bufcount_; //< How many characters we have so far
135
136 int null_radius_; //< The range over which no motion should be
137 // reported
138
139 struct timeval timestamp; //< Time of the last report from the device
140
141 double *vel_; // velocity update
142
143 dcblocker dcb_[Channels]; // dc blockers for all Channels
144 lowpass lp_[Channels]; // lowpass filters for all Channels
145
146 // Set all buttons, analogs and encoders back to 0
147 virtual void clear_values(void);
148
151 virtual int get_report(void);
152
154 virtual void report_changes (vrpn_uint32 class_of_service
157 virtual void report (vrpn_uint32 class_of_service
159
160 // NOTE: class_of_service is only applied to vrpn_Analog
161 // values, not vrpn_Button, which are always vrpn_RELIABLE
162};
163
164#endif
void swap(dcblocker &o)
dcblocker(dcblocker const &o)
double filter(double s)
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