vrpn
07.35
Virtual Reality Peripheral Network
Toggle main menu visibility
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
16
class
VRPN_API
dcblocker
{
17
public
:
// ctors, dtor
18
dcblocker
()
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
*/
59
class
VRPN_API
lowpass
{
60
public
:
// ctors, dtor
61
lowpass
()
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
94
class
VRPN_API
vrpn_inertiamouse
:
public
vrpn_Serial_Analog
,
public
vrpn_Button_Filter
{
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
() {
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
128
public
:
// virtual methods
129
131
virtual
void
mainloop ();
132
133
virtual
int
reset(
void
);
//< Set device back to starting config
134
135
protected
:
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
163
=
vrpn_CONNECTION_LOW_LATENCY
);
165
virtual
void
report
(vrpn_uint32 class_of_service
166
=
vrpn_CONNECTION_LOW_LATENCY
);
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
dcblocker
Definition
vrpn_inertiamouse.h:16
dcblocker::swap
void swap(dcblocker &o)
Definition
vrpn_inertiamouse.h:28
dcblocker::dcblocker
dcblocker()
Definition
vrpn_inertiamouse.h:18
dcblocker::~dcblocker
~dcblocker()
Definition
vrpn_inertiamouse.h:26
dcblocker::dcblocker
dcblocker(dcblocker const &o)
Definition
vrpn_inertiamouse.h:22
dcblocker::filter
double filter(double s)
Definition
vrpn_inertiamouse.h:40
dcblocker::reset
void reset()
Definition
vrpn_inertiamouse.h:46
lowpass
Definition
vrpn_inertiamouse.h:59
lowpass::lowpass
lowpass(lowpass const &o)
Definition
vrpn_inertiamouse.h:68
lowpass::lowpass
lowpass()
Definition
vrpn_inertiamouse.h:61
lowpass::~lowpass
~lowpass()
Definition
vrpn_inertiamouse.h:75
lowpass::reset
void reset()
Definition
vrpn_inertiamouse.h:85
lowpass::filter
double filter(double s)
Definition
vrpn_inertiamouse.h:77
vrpn_Button_Filter::vrpn_Button_Filter
vrpn_Button_Filter(const char *, vrpn_Connection *c=NULL)
Definition
vrpn_Button.C:129
vrpn_Connection
Generic connection class not specific to the transport mechanism.
Definition
vrpn_Connection.h:561
vrpn_Serial_Analog::vrpn_Serial_Analog
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)
Definition
vrpn_Analog.C:124
vrpn_inertiamouse::numbuttons_
int numbuttons_
Definition
vrpn_inertiamouse.h:137
vrpn_inertiamouse::create
static vrpn_inertiamouse * create(const char *name, vrpn_Connection *c, const char *port, int baud_rate)
Definition
vrpn_inertiamouse.C:54
vrpn_inertiamouse::report
virtual void report(vrpn_uint32 class_of_service=vrpn_CONNECTION_LOW_LATENCY)
send report whether or not changed
Definition
vrpn_inertiamouse.C:240
vrpn_inertiamouse::status_
int status_
Definition
vrpn_inertiamouse.h:136
vrpn_inertiamouse::vel_
double * vel_
Definition
vrpn_inertiamouse.h:149
vrpn_inertiamouse::clear_values
virtual void clear_values(void)
Definition
vrpn_inertiamouse.C:66
vrpn_inertiamouse::Vel_Decay
static const double Vel_Decay
Definition
vrpn_inertiamouse.h:102
vrpn_inertiamouse::vrpn_inertiamouse
vrpn_inertiamouse(const char *name, vrpn_Connection *c, const char *port, int baud_rate)
Definition
vrpn_inertiamouse.C:26
vrpn_inertiamouse::numchannels_
int numchannels_
Definition
vrpn_inertiamouse.h:138
vrpn_inertiamouse::lp_
lowpass lp_[Channels]
Definition
vrpn_inertiamouse.h:152
vrpn_inertiamouse::bufcount_
int bufcount_
Definition
vrpn_inertiamouse.h:142
vrpn_inertiamouse::~vrpn_inertiamouse
~vrpn_inertiamouse()
Definition
vrpn_inertiamouse.h:117
vrpn_inertiamouse::expected_chars_
int expected_chars_
Definition
vrpn_inertiamouse.h:140
vrpn_inertiamouse::get_report
virtual int get_report(void)
Try to read a report from the device. Returns 1 if complete report received, 0 otherwise....
Definition
vrpn_inertiamouse.C:90
vrpn_inertiamouse::report_changes
virtual void report_changes(vrpn_uint32 class_of_service=vrpn_CONNECTION_LOW_LATENCY)
send report iff changed
Definition
vrpn_inertiamouse.C:231
vrpn_inertiamouse::dcb_
dcblocker dcb_[Channels]
Definition
vrpn_inertiamouse.h:151
vrpn_inertiamouse::buffer_
unsigned char buffer_[512]
Definition
vrpn_inertiamouse.h:141
vrpn_inertiamouse::Channels
@ Channels
Definition
vrpn_inertiamouse.h:98
vrpn_inertiamouse::Buttons
@ Buttons
Definition
vrpn_inertiamouse.h:99
vrpn_inertiamouse::Update_Interval_Hz
@ Update_Interval_Hz
Definition
vrpn_inertiamouse.h:100
vrpn_inertiamouse::timestamp
struct timeval timestamp
Definition
vrpn_inertiamouse.h:147
vrpn_inertiamouse::null_radius_
int null_radius_
Definition
vrpn_inertiamouse.h:144
vrpn_Analog.h
vrpn_Button.h
vrpn_Configure.h
VRPN_API
#define VRPN_API
Definition
vrpn_Configure.h:648
vrpn_Connection.h
vrpn_CONNECTION_LOW_LATENCY
const vrpn_uint32 vrpn_CONNECTION_LOW_LATENCY
Definition
vrpn_Connection.h:120
vrpn_Shared.h
vrpn_Types.h
vrpn_inertiamouse.h
Generated by
1.17.0