vrpn  07.33
Virtual Reality Peripheral Network
vrpn_Tracker_AnalogFly.h
Go to the documentation of this file.
1 #ifndef INCLUDED_ANALOGFLY
2 #define INCLUDED_ANALOGFLY
3 
4 #include <quat.h> // for q_matrix_type
5 #include <stdio.h> // for NULL
6 
7 #include "vrpn_Analog.h" // for vrpn_ANALOGCB, etc
8 #include "vrpn_Button.h" // for vrpn_BUTTONCB, etc
9 #include "vrpn_Configure.h" // for VRPN_API, VRPN_CALLBACK
10 #include "vrpn_Shared.h" // for timeval
11 #include "vrpn_Tracker.h" // for vrpn_Tracker
12 #include "vrpn_Types.h" // for VRPN_FALSE, vrpn_FALSE
13 
15 struct vrpn_HANDLERPARAM;
16 
17 // This parameter is passed to the constructor for the AnalogFly; it describes
18 // the channel mapping and parameters of that mapping, as well as the button
19 // that will be used to reset the tracker when it is pushed. Any entry which
20 // has a NULL pointer for the name is disabled.
21 
23 
24  public:
25 
27  { name = NULL; channel = 0; offset = 0.0f; thresh = 0.0f;
28  scale = 1.0f; power = 1.0f; };
29 
30  char * name; //< Name of the Analog device driving this axis
31  int channel; //< Which channel to use from the Analog device
32  float offset; //< Offset to apply to values from this channel to reach 0
33  float thresh; //< Threshold to apply after offset within which values count as zero
34  float scale; //< Scale applied to values after offset and threshold
35  float power; //< Power to which values are taken after scaling
36 };
37 
39 
40  public:
41 
43  x.name = y.name = z.name =
44  sx.name = sy.name = sz.name = reset_name = clutch_name = NULL;
45  }
46 
49 
51  vrpn_TAF_axis sx, sy, sz;
52 
54 
55  char * reset_name;
57 
59  // large distances
60 
61  char * clutch_name;
63 };
64 
65 class VRPN_API vrpn_Tracker_AnalogFly; // Forward reference
66 
68 public:
69  vrpn_TAF_fullaxis (void) { ana = NULL; value = 0.0; af = NULL; };
70 
71  vrpn_TAF_axis axis;
74  double value;
75 };
76 
78 // tracker into a tracker by interpreting the joystick
79 // positions as either position or velocity inputs and "flying" the user
80 // around based on analog values.
81 // The "absolute" parameter tells whether the tracker integrates differential
82 // changes (the default, with FALSE) or takes the analog values as absolute
83 // positions or orientations.
84 // The mapping from analog channels to directions (or orientation changes) is
85 // described in the vrpn_Tracker_AnalogFlyParam parameter. For translations,
86 // values above threshold are multiplied by the scale and then taken to the
87 // power; the result is the number of meters (or meters per second) to move
88 // in that direction. For rotations, the result is taken as the number of
89 // revolutions (or revolutions per second) around the given axis.
90 // Note that the reset button has no effect on an absolute tracker.
91 // The time reported by absolute trackers is as of the last report they have
92 // had from their analog devices. The time reported by differential trackers
93 // is the local time that the report was generated. This is to allow a
94 // gen-locked camera tracker to have its time values passed forward through
95 // the AnalogFly class.
96 
97 // If reportChanges is TRUE, updates are ONLY sent if there has been a
98 // change since the last update, in which case they are generated no faster
99 // than update_rate.
100 
101 // If worldFrame is TRUE, then translations and rotations take place in the
102 // world frame, rather than the local frame. Useful for a simulated wand
103 // when doing desktop testing of immersive apps - easier to keep under control.
104 
106  public:
107  vrpn_Tracker_AnalogFly (const char * name, vrpn_Connection * trackercon,
109  float update_rate, bool absolute = vrpn_FALSE,
110  bool reportChanges = VRPN_FALSE, bool worldFrame = VRPN_FALSE);
111 
112  virtual ~vrpn_Tracker_AnalogFly (void);
113 
114  virtual void mainloop ();
115  virtual void reset (void);
116 
117  void update (q_matrix_type &);
118 
119  static void VRPN_CALLBACK handle_joystick (void *, const vrpn_ANALOGCB);
120  static int VRPN_CALLBACK handle_newConnection (void *, vrpn_HANDLERPARAM);
121 
122  protected:
123 
124  double d_update_interval; //< How long to wait between sends
125  struct timeval d_prevtime; //< Time of the previous report
126  bool d_absolute; //< Report absolute (vs. differential)?
129 
130  vrpn_TAF_fullaxis d_x, d_y, d_z, d_sx, d_sy, d_sz;
133 
138 
139  q_matrix_type d_initMatrix, d_currentMatrix, d_clutchMatrix;
140 
141  void update_matrix_based_on_values (double time_interval);
142  void convert_matrix_to_tracker (void);
143 
144  bool shouldReport (double elapsedInterval) const;
145 
146  int setup_channel (vrpn_TAF_fullaxis * full);
147  int teardown_channel (vrpn_TAF_fullaxis * full);
148 
149  static void VRPN_CALLBACK handle_analog_update (void * userdata,
150  const vrpn_ANALOGCB info);
151  static void VRPN_CALLBACK handle_reset_press (void * userdata, const vrpn_BUTTONCB info);
152  static void VRPN_CALLBACK handle_clutch_press (void * userdata, const vrpn_BUTTONCB info);
153 };
154 
155 #endif
vrpn_Tracker_AnalogFly::d_clutch_was_off
bool d_clutch_was_off
Definition: vrpn_Tracker_AnalogFly.h:137
vrpn_Tracker_AnalogFly
class VRPN_API vrpn_Tracker_AnalogFly
Definition: vrpn_Tracker_AnalogFly.h:65
vrpn_Tracker.h
vrpn_Tracker_AnalogFlyParam::sz
vrpn_TAF_axis sz
Definition: vrpn_Tracker_AnalogFly.h:51
vrpn_Tracker
Definition: vrpn_Tracker.h:49
vrpn_TAF_fullaxis::vrpn_TAF_fullaxis
vrpn_TAF_fullaxis(void)
Definition: vrpn_Tracker_AnalogFly.h:69
vrpn_Types.h
vrpn_Tracker_AnalogFly::d_reset_button
vrpn_Button_Remote * d_reset_button
Definition: vrpn_Tracker_AnalogFly.h:131
vrpn_Tracker_AnalogFlyParam::clutch_name
char * clutch_name
Clutch device that is used to enable relative motion over.
Definition: vrpn_Tracker_AnalogFly.h:61
vrpn_Tracker_AnalogFly::d_worldFrame
bool d_worldFrame
Definition: vrpn_Tracker_AnalogFly.h:128
vrpn_Analog_Remote
Definition: vrpn_Analog.h:181
vrpn_TAF_fullaxis
Definition: vrpn_Tracker_AnalogFly.h:67
vrpn_Button_Remote
Definition: vrpn_Button.h:250
vrpn_TAF_axis::thresh
float thresh
Definition: vrpn_Tracker_AnalogFly.h:33
vrpn_Tracker_AnalogFly::d_clutch_which
int d_clutch_which
Definition: vrpn_Tracker_AnalogFly.h:135
vrpn_Tracker_AnalogFly::d_absolute
bool d_absolute
Definition: vrpn_Tracker_AnalogFly.h:126
vrpn_Tracker_AnalogFly::d_clutch_engaged
bool d_clutch_engaged
Definition: vrpn_Tracker_AnalogFly.h:136
vrpn_TAF_fullaxis::af
vrpn_Tracker_AnalogFly * af
Definition: vrpn_Tracker_AnalogFly.h:73
vrpn_Tracker_AnalogFlyParam::clutch_which
int clutch_which
Definition: vrpn_Tracker_AnalogFly.h:62
vrpn_Tracker_AnalogFly
This class will turn an analog device such as a joystick or a camera.
Definition: vrpn_Tracker_AnalogFly.h:105
vrpn_TAF_axis::vrpn_TAF_axis
vrpn_TAF_axis(void)
Definition: vrpn_Tracker_AnalogFly.h:26
vrpn_Tracker_AnalogFlyParam::vrpn_Tracker_AnalogFlyParam
vrpn_Tracker_AnalogFlyParam(void)
Definition: vrpn_Tracker_AnalogFly.h:42
vrpn_HANDLERPARAM
This structure is what is passed to a vrpn_Connection message callback.
Definition: vrpn_Connection.h:44
vrpn_Shared.h
vrpn_Tracker_AnalogFlyParam::reset_name
char * reset_name
Button device that is used to reset the matrix to the origin.
Definition: vrpn_Tracker_AnalogFly.h:55
vrpn_Tracker_AnalogFly::d_z
vrpn_TAF_fullaxis d_z
Definition: vrpn_Tracker_AnalogFly.h:130
vrpn_Button.h
vrpn_Tracker_AnalogFly::d_clutch_button
vrpn_Button_Remote * d_clutch_button
Definition: vrpn_Tracker_AnalogFly.h:134
vrpn_TAF_axis
Definition: vrpn_Tracker_AnalogFly.h:22
vrpn_Tracker_AnalogFlyParam::z
vrpn_TAF_axis z
Definition: vrpn_Tracker_AnalogFly.h:48
vrpn_BaseClass::mainloop
virtual void mainloop()=0
Called once through each main loop iteration to handle updates. Remote object mainloop() should call ...
vrpn_Tracker_AnalogFly::d_initMatrix
q_matrix_type d_initMatrix
Definition: vrpn_Tracker_AnalogFly.h:139
vrpn_TAF_axis::power
float power
Definition: vrpn_Tracker_AnalogFly.h:35
vrpn_Tracker_AnalogFly::d_which_button
int d_which_button
Definition: vrpn_Tracker_AnalogFly.h:132
vrpn_TAF_fullaxis::ana
vrpn_Analog_Remote * ana
Definition: vrpn_Tracker_AnalogFly.h:72
vrpn_Connection
Generic connection class not specific to the transport mechanism.
Definition: vrpn_Connection.h:510
vrpn_Tracker_AnalogFlyParam
Definition: vrpn_Tracker_AnalogFly.h:38
vrpn_TAF_fullaxis::value
double value
Definition: vrpn_Tracker_AnalogFly.h:74
vrpn_TAF_axis::scale
float scale
Definition: vrpn_Tracker_AnalogFly.h:34
vrpn_TAF_axis::offset
float offset
Definition: vrpn_Tracker_AnalogFly.h:32
vrpn_Analog.h
VRPN_CALLBACK
#define VRPN_CALLBACK
Definition: vrpn_Configure.h:647
vrpn_TAF_axis::channel
int channel
Definition: vrpn_Tracker_AnalogFly.h:31
vrpn_Tracker_AnalogFly::d_reportChanges
bool d_reportChanges
Definition: vrpn_Tracker_AnalogFly.h:127
vrpn_Configure.h
vrpn_Tracker_AnalogFlyParam::reset_which
int reset_which
Definition: vrpn_Tracker_AnalogFly.h:56
vrpn_Tracker_AnalogFly::d_update_interval
double d_update_interval
Definition: vrpn_Tracker_AnalogFly.h:124
VRPN_API
#define VRPN_API
Definition: vrpn_Configure.h:646