vrpn
07.33
Virtual Reality Peripheral Network
|
Go to the documentation of this file.
11 #ifdef VRPN_USE_MICROSCRIBE
26 #define STATUS_RESETTING (-1) // Resetting the device
27 #define STATUS_SYNCING (0) // Looking for the first char of report
28 #define STATUS_READING (1) // Looking for the rest of the report
29 #define MAX_TIME_INTERVAL (2000000) // max time between reports (usec)
31 #define MM_TO_METERS 0.001
33 #define VR_PI 3.14159265359
34 inline float pcos(
float x) {
return (
float)cos(
double(x)*
VR_PI/180.0f);}
35 inline float psin(
float x) {
return (
float)sin(
double(x)*
VR_PI/180.0f);}
39 const char * Port,
long int BaudRate,
51 if(!strcmp(Port,
"COM1") )
53 else if(!strcmp(Port,
"COM2") )
55 else if(!strcmp(Port,
"COM3") )
57 else if(!strcmp(Port,
"COM4") )
66 #ifdef VRPN_USE_MICROSCRIBE
68 iResult=ArmStart(NULL);
69 if(ARM_SUCCESS != iResult)
77 iResult = ArmSetErrorHandlerFunction(NO_HCI_HANDLER, NULL);
78 iResult = ArmSetErrorHandlerFunction(BAD_PORT_HANDLER, NULL);
79 iResult = ArmSetErrorHandlerFunction(CANT_OPEN_HANDLER, NULL);
80 iResult = ArmSetErrorHandlerFunction(CANT_BEGIN_HANDLER, NULL);
98 iResult = ArmConnect(0, 0);
102 if(ARM_SUCCESS != iResult)
123 #ifdef VRPN_USE_MICROSCRIBE
126 iResult = ArmSetUpdate(ARM_FULL);
128 if(iResult != ARM_SUCCESS)
131 VRPN_MSG_ERROR(
"Unable to set the update type for the MicroScribe." );
136 ArmSetLengthUnits(ARM_MM);
141 length_3D tipPosition;
144 iResult = ArmGetTipPosition(&tipPosition);
145 iResult = ArmGetTipOrientationUnitVector(&tipVector);
147 if(iResult == ARM_NOT_CONNECTED)
178 #ifdef VRPN_USE_MICROSCRIBE
179 length_3D tipPosition;
182 int iResult = ArmGetTipPosition(&tipPosition);
183 iResult = ArmGetTipOrientation(&tipOri);
184 iResult = ArmGetButtonsState(&buts);
185 if(iResult == ARM_NOT_CONNECTED)
199 float ori[3]={tipOri.y, tipOri.z, tipOri.x};
206 buttons[0] = ((buts & 0x02) != 0);
207 buttons[1] = ((buts & 0x01) != 0);
217 float real0,real1,real2,real;
218 float imag0,imag1,imag2,imag[3];
220 real0=
pcos(ori[0]/2);
221 real1=
pcos(ori[1]/2);
222 real2=
pcos(ori[2]/2);
224 imag0 =
psin(ori[0]/2);
225 imag1 =
psin(ori[1]/2);
226 imag2 =
psin(ori[2]/2);
229 real = real0 * real1 ;
233 else if ( real < -1 )
236 imag[0] = imag0 * real1;
237 imag[1] = real0 * imag1;
238 imag[2] = imag0 * imag1;
242 d_quat[0] = real * real2 - imag[2] * imag2 ;
246 else if (
d_quat[0] < -1 )
249 d_quat[1] = imag[0] * real2 + imag[1] * imag2;
250 d_quat[2] = imag[1] * real2 - imag[0] * imag2;
251 d_quat[3] = real * imag2 + imag[2] * real2;
299 fprintf(stderr,
"vrpn_3DMicroscribe: Unknown mode (internal error)\n");
virtual int pack_message(vrpn_uint32 len, struct timeval time, vrpn_int32 type, vrpn_int32 sender, const char *buffer, vrpn_uint32 class_of_service)
Pack a message that will be sent the next time mainloop() is called. Turn off the RELIABLE flag if yo...
virtual int encode_to(char *buf)
virtual void mainloop()
Called once through each main loop iteration to handle updates.
void ConvertOriToQuat(float ori[3])
virtual void clear_values(void)
Set all buttons, analogs and encoders back to 0.
virtual int reset(void)
Set device back to starting config.
struct timeval timestamp
Time of the last report from the device.
vrpn_Connection * d_connection
Connection that this object talks to.
vrpn_int32 d_sender_id
Sender ID registered with the connection.
int _numbuttons
How many buttons to open.
Generic connection class not specific to the transport mechanism.
vrpn_3DMicroscribe(const char *name, vrpn_Connection *c, const char *Port, long int BaudRate, float OffsetX=0.0f, float OffsetY=0.0f, float OffsetZ=0.0f, float Scale=1.0f)
#define vrpn_gettimeofday
int m_PortNumber
port number
virtual void report(vrpn_uint32 class_of_service=vrpn_CONNECTION_LOW_LATENCY)
send report whether or not changed
virtual int get_report(void)
Try to read reports from the device. Returns 1 if a complete report received, 0 otherwise....
long int m_BaudRate
baud rate
Header containing macros formerly duplicated in a lot of implementation files.
#define VRPN_MSG_ERROR(msg)
void server_mainloop(void)
Handles functions that all servers should provide in their mainloop() (ping/pong, for example) Should...