11#ifdef VRPN_USE_MICROSCRIBE
26#define STATUS_RESETTING (-1)
27#define STATUS_SYNCING (0)
28#define STATUS_READING (1)
29#define MAX_TIME_INTERVAL (2000000)
31#define MM_TO_METERS 0.001
33#define VR_PI 3.14159265359
34inline float pcos(
float x) {
return (
float)cos(
double(x)*
VR_PI/180.0f);}
35inline 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") )
68#ifdef VRPN_USE_MICROSCRIBE
70 iResult=ArmStart(NULL);
71 if(ARM_SUCCESS != iResult)
79 iResult = ArmSetErrorHandlerFunction(NO_HCI_HANDLER, NULL);
80 iResult = ArmSetErrorHandlerFunction(BAD_PORT_HANDLER, NULL);
81 iResult = ArmSetErrorHandlerFunction(CANT_OPEN_HANDLER, NULL);
82 iResult = ArmSetErrorHandlerFunction(CANT_BEGIN_HANDLER, NULL);
100 iResult = ArmConnect(0, 0);
104 if(ARM_SUCCESS != iResult)
125#ifdef VRPN_USE_MICROSCRIBE
128 iResult = ArmSetUpdate(ARM_FULL);
130 if(iResult != ARM_SUCCESS)
133 VRPN_MSG_ERROR(
"Unable to set the update type for the MicroScribe." );
138 ArmSetLengthUnits(ARM_MM);
143 length_3D tipPosition;
146 iResult = ArmGetTipPosition(&tipPosition);
147 iResult = ArmGetTipOrientationUnitVector(&tipVector);
149 if(iResult == ARM_NOT_CONNECTED)
180#ifdef VRPN_USE_MICROSCRIBE
181 length_3D tipPosition;
184 int iResult = ArmGetTipPosition(&tipPosition);
185 iResult = ArmGetTipOrientation(&tipOri);
186 iResult = ArmGetButtonsState(&buts);
187 if(iResult == ARM_NOT_CONNECTED)
201 float ori[3]={tipOri.y, tipOri.z, tipOri.x};
208 buttons[0] = ((buts & 0x02) != 0);
209 buttons[1] = ((buts & 0x01) != 0);
219 float real0,real1,real2,real;
220 float imag0,imag1,imag2,imag[3];
222 real0=
pcos(ori[0]/2);
223 real1=
pcos(ori[1]/2);
224 real2=
pcos(ori[2]/2);
226 imag0 =
psin(ori[0]/2);
227 imag1 =
psin(ori[1]/2);
228 imag2 =
psin(ori[2]/2);
231 real = real0 * real1 ;
235 else if ( real < -1 )
238 imag[0] = imag0 * real1;
239 imag[1] = real0 * imag1;
240 imag[2] = imag0 * imag1;
244 d_quat[0] = real * real2 - imag[2] * imag2 ;
248 else if (
d_quat[0] < -1 )
251 d_quat[1] = imag[0] * real2 + imag[1] * imag2;
252 d_quat[2] = imag[1] * real2 - imag[0] * imag2;
253 d_quat[3] = real * imag2 + imag[2] * real2;
301 fprintf(stderr,
"vrpn_3DMicroscribe: Unknown mode (internal error)\n");
virtual void clear_values(void)
Set all buttons, analogs and encoders back to 0.
virtual void report(vrpn_uint32 class_of_service=vrpn_CONNECTION_LOW_LATENCY)
send report whether or not changed
int _numbuttons
How many buttons to open.
int m_PortNumber
port number
virtual int reset(void)
Set device back to starting config.
long int m_BaudRate
baud rate
virtual void mainloop()
Called once through each main loop iteration to handle updates.
void ConvertOriToQuat(float ori[3])
virtual int get_report(void)
Try to read reports from the device. Returns 1 if a complete report received, 0 otherwise....
struct timeval timestamp
Time of the last report from the device.
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)
vrpn_Connection * d_connection
Connection that this object talks to.
vrpn_int32 d_sender_id
Sender ID registered with the connection.
void server_mainloop(void)
Handles functions that all servers should provide in their mainloop() (ping/pong, for example) Should...
Generic connection class not specific to the transport mechanism.
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)
All types of client/server/peer objects in VRPN should be derived from the vrpn_BaseClass type descri...
Header containing macros formerly duplicated in a lot of implementation files.
#define VRPN_MSG_ERROR(msg)
#define vrpn_gettimeofday