00001
00002
00003
00004
00005
00006 #include "intersense.h"
00007 #include <stdio.h>
00008 #include <math.h>
00009
00010 #ifdef _WIN32
00011 #define M_PI 3.1415927
00012 #endif
00013
00014 const char* Intersense::rcsid = "@(#) $Id: intersense.cpp,v 1.9 2001/10/17 16:49:35 kevin Exp $ $Copyright: (c)2001 National Biocomputation Center, Stanford University $";
00015 int Intersense::debug = 0;
00016
00017 short Intersense::get_shorty()
00018 {
00019 short val;
00020 GetBuffer((char*)&val, 2);
00021
00022 #ifdef _WIN32
00023 return(val);
00024 #else
00025
00026 return( ((val & 0x00ff) << 8) | ((val & 0xff00) >> 8) );
00027 #endif
00028
00029 }
00030
00031 Intersense::Intersense(char* port_name, int baud)
00032 : Sensor(Sensor::isense_sensor), SerialDevice(port_name, baud)
00033 {
00034 if (debug)
00035 cerr << "Intersense::constructor(" << port_name << ", " << baud << ")\n";
00036
00037
00038
00039
00040
00041
00042 FlushInputQueue();
00043
00044
00045 SendByte('c');
00046
00047
00048 while (GetByte() != 'o') ;
00049
00050 {
00051
00052
00053 SendByte('v'); SendByte('\000');
00054
00055
00056 char ackbuf[2];
00057 GetBuffer((char*)&ackbuf, 2);
00058
00059
00060 short device_type = get_shorty();
00061
00062
00063 short version = get_shorty()/100;
00064
00065
00066 char prodid[50];
00067 GetBuffer((char*)&prodid, 50);
00068
00069
00070 SendByte('p');
00071
00072
00073 char numdevs;
00074 GetBuffer(&numdevs, 1);
00075
00076
00077 if (debug) {
00078 cerr << "device_type = " << device_type << endl;
00079 cerr << "version = " << version << endl;
00080 cerr << "product obj_id = [" << prodid << "]\n";
00081 cerr << "number of devices = " << int(numdevs) << endl;
00082 }
00083 }
00084
00085
00086 SendByte('d');
00087
00088
00089 while (GetByte() != 'd') ;
00090
00091
00092 }
00093
00094 Intersense::~Intersense()
00095 {
00096 if (debug)
00097 cerr << "Intersense::destructor()\n";
00098 }
00099
00100 void Intersense::Update()
00101 {
00102 if (debug) cerr << "Intersense::Update()\n";
00103
00104
00105 FlushInputQueue();
00106
00107
00108 SendByte('3');
00109
00110
00111
00112
00113 short azimuth = get_shorty();
00114 short elevation = get_shorty();
00115 short twist = get_shorty();
00116
00117
00118 pos.x = pos.y = pos.z = 0.0;
00119
00120 Point3D rot;
00121 rot.x = elevation/32768.0 * 180.0;
00122 rot.y = azimuth/32768.0 * 180.0;
00123 rot.z = twist/32768.0 * 180.0;
00124
00125 {
00126 double e = -rot.y * M_PI/180.0;
00127 double a = -rot.z * M_PI/180.0;
00128 double t = -rot.x * M_PI/180.0;
00129 m.m[0][0] = cos(e)*cos(a);
00130 m.m[0][1] = cos(e)*sin(a);
00131 m.m[0][2] = -sin(e);
00132 m.m[0][3] = 0.0;
00133 m.m[1][0] = -cos(t)*sin(a) + sin(t)*sin(e)*cos(a);
00134 m.m[1][1] = cos(t)*cos(a) + sin(t)*sin(e)*sin(a);
00135 m.m[1][2] = sin(t)*cos(e);
00136 m.m[1][3] = 0.0;
00137 m.m[2][0] = sin(t)*sin(a) + cos(t)*sin(e)*cos(a);
00138 m.m[2][1] = -sin(t)*cos(a) + cos(t)*sin(e)*sin(a);
00139 m.m[2][2] = cos(t)*cos(e);
00140 m.m[2][3] = 0.0;
00141 m.m[3][0] = m.m[3][1] = m.m[3][2] = 0.0;
00142 m.m[3][3] = 1.0;
00143 }
00144
00145
00146 active[0] = 0.0;
00147 }