vrpn  07.33
Virtual Reality Peripheral Network
vrpn_Poser.h
Go to the documentation of this file.
1 #ifndef vrpn_POSER_H
2 #define vrpn_POSER_H
3 #include <stdio.h> // for NULL
4 
5 // NOTE: the poser class borrows heavily from the vrpn_Tracker code.
6 // The poser is basically the inverse of a tracker.
7 // We are only handling pose and velocity updates for now...acceleration
8 // will come later, as needed.
9 
10 #include "vrpn_BaseClass.h" // for vrpn_Callback_List, etc
11 #include "vrpn_Configure.h" // for VRPN_CALLBACK, VRPN_API
12 #include "vrpn_Shared.h" // for timeval
13 #include "vrpn_Types.h" // for vrpn_float64, vrpn_int32
14 
16 struct vrpn_HANDLERPARAM;
17 
19 public:
20  vrpn_Poser(const char* name, vrpn_Connection* c = NULL);
21 
22  virtual ~vrpn_Poser(void);
23 
24  void p_print(); // print the current pose
25  void p_print_vel(); // print the current velocity
26 
27  // a poser server should call the following to register the
28  // default xform and workspace request handlers
29  // int register_server_handlers(void);
30 
31 protected:
32  // client-->server
33  vrpn_int32 req_position_m_id; // ID of poser position message
34  vrpn_int32 req_position_relative_m_id; // ID of poser position delta message
35  vrpn_int32 req_velocity_m_id; // ID of poser velocity message
36  vrpn_int32 req_velocity_relative_m_id; // ID of poser velocity delta message
37 
38  // Description of current state
39  vrpn_float64 p_pos[3], p_quat[4]; // Current pose, (x,y,z), (qx,qy,qz,qw)
40  vrpn_float64 p_vel[3],
41  p_vel_quat[4]; // Current velocity and dQuat/vel_quat_dt
42  vrpn_float64 p_vel_quat_dt; // delta time (in secs) for vel_quat
43  struct timeval p_timestamp; // Current timestamp
44 
45  // Minimum and maximum values available for the position and velocity values
46  // of the poser.
47  vrpn_float64 p_pos_min[3], p_pos_max[3], p_pos_rot_min[3], p_pos_rot_max[3],
48  p_vel_min[3], p_vel_max[3], p_vel_rot_min[3], p_vel_rot_max[3];
49 
50  virtual int register_types(void); // Called by BaseClass init()
51 
52  virtual int encode_to(char* buf); // Encodes the position
53  virtual int encode_vel_to(char* buf); // Encodes the velocity
54 
55  virtual void set_pose(const struct timeval t, // Sets the pose internally
56  const vrpn_float64 position[3],
57  const vrpn_float64 quaternion[4]);
58  virtual void set_pose_relative(
59  const struct timeval t, // Increments the pose internally
60  const vrpn_float64
61  position_delta[3], // pos_new = position_delta + pos_old
62  const vrpn_float64 quaternion[4]); // q_new = quaternion * q_old
63  virtual void
64  set_pose_velocity(const struct timeval t, // Sets the velocity internally
65  const vrpn_float64 position[3],
66  const vrpn_float64 quaternion[4],
67  const vrpn_float64 interval);
68  virtual void set_pose_velocity_relative(
69  const struct timeval t, // Increments the velocity internally
70  const vrpn_float64
71  velocity_delta[3], // vel_new = velocity_delta + vel_old
72  const vrpn_float64 quaternion[4], // q_new = quaternion * q_old
73  const vrpn_float64
74  interval_delta); // interval_new = interval_delta + interval_old
75 };
76 
77 //------------------------------------------------------------------------------------
78 // Server Code
79 
81 typedef struct _vrpn_POSERCB {
82  struct timeval msg_time; // Timestamp
88  vrpn_float64 pos[3];
89  vrpn_float64 quat[4];
90 } vrpn_POSERCB;
91 
92 typedef void(VRPN_CALLBACK* vrpn_POSERHANDLER)(void* userdata,
93  const vrpn_POSERCB info);
94 
95 //------------------------------------------------------------------------------------
96 // Server Code
97 // Users supply the routines to handle requests from the client
98 
99 // This is a sample basic poser server
100 //
101 
103 public:
104  vrpn_Poser_Server(const char* name, vrpn_Connection* c);
105 
107  virtual void mainloop();
108 
109  int register_change_handler(void* userdata, vrpn_POSERHANDLER handler)
110  {
111  return d_callback_list.register_handler(userdata, handler);
112  };
113  int unregister_change_handler(void* userdata, vrpn_POSERHANDLER handler)
114  {
115  return d_callback_list.unregister_handler(userdata, handler);
116  }
117 
119  vrpn_POSERHANDLER handler)
120  {
121  return d_relative_callback_list.register_handler(userdata, handler);
122  }
124  vrpn_POSERHANDLER handler)
125  {
126  return d_relative_callback_list.unregister_handler(userdata, handler);
127  }
128 
129 protected:
130  static int VRPN_CALLBACK
131  handle_change_message(void* userdata, vrpn_HANDLERPARAM p);
132  static int VRPN_CALLBACK
133  handle_relative_change_message(void* userdata, vrpn_HANDLERPARAM p);
134  static int VRPN_CALLBACK
135  handle_vel_change_message(void* userdata, vrpn_HANDLERPARAM p);
136  static int VRPN_CALLBACK
137  handle_relative_vel_change_message(void* userdata, vrpn_HANDLERPARAM p);
140 };
141 
142 //------------------------------------------------------------------------------------
143 // Client Code
144 
145 // Open a poser that is on the other end of a connection for sending updates to
146 // it.
148 public:
149  // The name of the poser to connect to, including connection name,
150  // for example "poser@magnesium.cs.unc.edu". If you already
151  // have the connection open, you can specify it as the second parameter.
152  // This allows both servers and clients in the same thread, for example.
153  // If it is not specified, then the connection will be looked up based
154  // on the name passed in.
155  vrpn_Poser_Remote(const char* name, vrpn_Connection* c = NULL);
156 
157  // unregister all of the handlers registered with the connection
158  virtual ~vrpn_Poser_Remote(void);
159 
160  // This routine calls the mainloop of the connection it's on
161  virtual void mainloop();
162 
163  // Routines to set the state of the poser
164  int request_pose(const struct timeval t, const vrpn_float64 position[3],
165  const vrpn_float64 quaternion[4]);
166  int request_pose_relative(const struct timeval t,
167  const vrpn_float64 position_delta[3],
168  const vrpn_float64 quaternion[4]);
169  int request_pose_velocity(const struct timeval t,
170  const vrpn_float64 velocity[3],
171  const vrpn_float64 quaternion[4],
172  const vrpn_float64 interval);
173  int request_pose_velocity_relative(const struct timeval t,
174  const vrpn_float64 velocity_delta[3],
175  const vrpn_float64 quaternion[4],
176  const vrpn_float64 interval_delta);
177 
178 protected:
179  virtual int
180  client_send_pose(); // Sends the current pose. Called by request_pose
181  virtual int client_send_pose_relative(); // Sends the current pose delta.
182  // Called by request_pose_relative
183  virtual int client_send_pose_velocity(); // Sends the current velocity.
184  // Called by request_pose_velocity
185  virtual int
186  client_send_pose_velocity_relative(); // Sends the current velocity delta.
187  // Called by
188  // request_pose_velocity_relative
189 };
190 
191 #endif
A structure for Call-Backs related to Vrpn Poser Server.
Definition: vrpn_Poser.h:81
vrpn_Callback_List< vrpn_POSERCB > d_callback_list
Definition: vrpn_Poser.h:138
vrpn_int32 req_velocity_m_id
Definition: vrpn_Poser.h:35
Generic connection class not specific to the transport mechanism.
vrpn_Callback_List< vrpn_POSERCB > d_relative_callback_list
Definition: vrpn_Poser.h:139
virtual int register_types(void)=0
Register the types of messages this device sends/receives. Return 0 on success, -1 on fail...
void(VRPN_CALLBACK * vrpn_POSERHANDLER)(void *userdata, const vrpn_POSERCB info)
Definition: vrpn_Poser.h:92
int register_relative_change_handler(void *userdata, vrpn_POSERHANDLER handler)
Definition: vrpn_Poser.h:118
#define VRPN_CALLBACK
vrpn_int32 req_velocity_relative_m_id
Definition: vrpn_Poser.h:36
#define VRPN_API
All types of client/server/peer objects in VRPN should be derived from the vrpn_BaseClass type descri...
int unregister_relative_change_handler(void *userdata, vrpn_POSERHANDLER handler)
Definition: vrpn_Poser.h:123
virtual void mainloop()=0
Called once through each main loop iteration to handle updates. Remote object mainloop() should call ...
This structure is what is passed to a vrpn_Connection message callback.
vrpn_float64 p_vel_quat_dt
Definition: vrpn_Poser.h:42
int register_change_handler(void *userdata, vrpn_POSERHANDLER handler)
Definition: vrpn_Poser.h:109
Class from which all user-level (and other) classes that communicate with vrpn_Connections should der...
vrpn_int32 req_position_relative_m_id
Definition: vrpn_Poser.h:34
vrpn_int32 req_position_m_id
Definition: vrpn_Poser.h:33
int unregister_change_handler(void *userdata, vrpn_POSERHANDLER handler)
Definition: vrpn_Poser.h:113