Changeset 20886
- Timestamp:
- 10/30/07 09:46:17 (10 months ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
juggler/trunk/modules/gadgeteer/drivers/Intersense/IntersenseAPI/IntersenseAPI.cpp
r20446 r20886 127 127 void IntersenseAPI::controlLoop() 128 128 { 129 // Loop through and keep sampling until stopSampl eing is called.129 // Loop through and keep sampling until stopSampling is called. 130 130 while(!mDone) 131 131 { 132 132 this->sample(); 133 //TODO: Find a way to eliminate this sleep. If I rememeber correctly it 134 // was added because the CPU was getting pegged too fast with samples 135 // since there was no I/O wait because we are simply querying the 136 // ISense library. 137 vpr::System::msleep(50); 133 //TODO: Find a way to eliminate this sleep. Currently, the CPU is 134 // pegged aquiring samples since there was no I/O wait because 135 // we are simply querying the ISense library. 136 // Note: This sleep was 50ms but 10ms is more reasonable given 137 // the records/sec IS-900 can return. 138 vpr::System::msleep(10); 138 139 } 139 140 } … … 141 142 bool IntersenseAPI::startSampling() 142 143 { 143 // Configure the stations used by the configuration144 for( unsigned int i = 0; i < mStations.size(); ++i )145 {146 int station_index = mStations[i].stationIndex;147 148 // Load the config state from the physical tracker149 mTracker.loadConfigState(station_index);150 mTracker.setState(station_index, mStations[i].enabled);151 mTracker.setAngleFormat(station_index, ISD_EULER);152 mTracker.setInputs(station_index,153 mStations[i].useDigital || mStations[i].useAnalog);154 // Save the config state to the physical tracker.155 mTracker.saveConfigState(station_index);156 }157 158 144 // Ensure that we have not already started sampling. 159 145 if (this->isActive() == true) … … 184 170 << "failed to connect to tracker.\n" << vprDEBUG_FLUSH; 185 171 return false; 172 } 173 174 // Configure the stations used by the configuration 175 for( unsigned int i = 0; i < mStations.size(); ++i ) 176 { 177 int station_index = mStations[i].stationIndex; 178 // Reset any boresight being used by trackd or ICIDO 179 // This makes a call to the tracker and is not simply setting 180 // state on a var to configure the tracker with as done below. 181 mTracker.resetStationBoresight(station_index); 182 // Load the config state from the physical tracker 183 mTracker.loadConfigState(station_index); 184 mTracker.setState(station_index, mStations[i].enabled); 185 mTracker.setInputs(station_index, 186 mStations[i].useDigital || mStations[i].useAnalog); 187 mTracker.setTimeStamped( station_index, false ); 188 mTracker.setDefaultCoordFrame( station_index ); 189 190 // Save the config state to the physical tracker. 191 if ( ! mTracker.saveConfigState(station_index) ) 192 { 193 vprDEBUG(vprDBG_ERROR,vprDBG_CRITICAL_LVL) 194 << clrOutNORM(clrRED,"ERROR:") 195 << " [gadget::IntersenseAPI::startSampling()] mTracker.saveConfigState() " 196 << "failed to save config state to station " << i << ".\n" 197 << vprDEBUG_FLUSH; 198 199 mTracker.close(); 200 return false; 201 } 202 203 //Try to get output in quat form otherwise fallback on euler angles 204 mTracker.setAngleFormat(station_index, ISD_QUATERNION); 205 if ( ! mTracker.saveConfigState(station_index) ) 206 { 207 // Failed to set quaternion format which means it is set for euler 208 mTracker.setAngleFormat(station_index, ISD_EULER); 209 } 186 210 } 187 211 … … 219 243 } 220 244 245 // Check to see if we have new data to pull 246 if ( ! mTracker.updateData() ) 247 { 248 vprDEBUG(gadgetDBG_INPUT_MGR, vprDBG_CRITICAL_LVL) 249 << clrOutBOLD(clrRED, "[gadget::IntersenseAPI::sample()]") 250 << ": Could not read data from InterSense API driver!\n" 251 << vprDEBUG_FLUSH; 252 return false; 253 } 254 255 256 // This is the some code for the beginnings of trying to eliminate 257 // the sleep in the control loop. Needs more testing. 258 /* 259 bool has_new_data(false); 260 for ( unsigned int i = 0 ; i < mStations.size() ; ++i ) 261 { 262 // Make sure station is enabled and tracker has updated data. 263 if( mStations[i].enabled && mTracker.hasData(mStations[i].stationIndex) ) 264 { 265 has_new_data = true; 266 break; 267 } 268 } 269 270 // If there wasn't any new data then reliquish control to the cpu and return 271 if( ! has_new_data ) 272 { 273 vpr::Thread::yield(); 274 vpr::System::msleep(10); 275 } 276 */ 277 221 278 // Create the data buffers to put the new data into. 222 279 std::vector<gadget::PositionData> cur_pos_samples(mStations.size()); … … 224 281 std::vector<gadget::AnalogData> cur_analog_samples; 225 282 226 227 283 // get an initial timestamp for this entire sample. we'll copy it into 228 284 // each PositionData for this sample. … … 232 288 } 233 289 234 mTracker.updateData();235 236 vpr::Thread::yield();237 238 290 for ( unsigned int i = 0 ; i < mStations.size() ; ++i ) 239 291 { … … 241 293 int stationIndex = mStations[i].stationIndex; 242 294 295 243 296 // Set the time of each PositionData to match the first. 244 297 cur_pos_samples[i].setTime( cur_pos_samples[0].getTime() ); 245 298 299 // Don't process data from disabled stations 300 if( ! mStations[i].enabled ) 301 { 302 continue; 303 } 304 305 gmtl::identity(cur_pos_samples[i].mPosData); 246 306 // If the Intersense is returning data in Euler format. Otherwise we 247 307 // assume that it is returning data in quaternion format. 248 308 if ( mTracker.getAngleFormat(stationIndex) == ISD_EULER ) 249 309 { 250 gmtl::identity(cur_pos_samples[i].mPosData);251 310 gmtl::EulerAngleZYXf euler( gmtl::Math::deg2Rad( mTracker.zRot( stationIndex ) ), 252 311 gmtl::Math::deg2Rad( mTracker.yRot( stationIndex ) ), 253 312 gmtl::Math::deg2Rad( mTracker.xRot( stationIndex ) ) ); 254 313 gmtl::setRot( cur_pos_samples[i].mPosData, euler ); 255 gmtl::setTrans( cur_pos_samples[i].mPosData,256 gmtl::Vec3f(mTracker.xPos( stationIndex ),257 mTracker.yPos( stationIndex ),258 mTracker.zPos( stationIndex )) );259 314 } 260 315 else … … 264 319 mTracker.zQuat( stationIndex ), 265 320 mTracker.wQuat( stationIndex )); 266 gmtl::set( cur_pos_samples[i].mPosData, quatValue ); 267 } 321 gmtl::setRot( cur_pos_samples[i].mPosData, quatValue ); 322 } 323 324 gmtl::setTrans( cur_pos_samples[i].mPosData, 325 gmtl::Vec3f(mTracker.xPos( stationIndex ), 326 mTracker.yPos( stationIndex ), 327 mTracker.zPos( stationIndex )) ); 268 328 269 329 // We start at the index of the first digital item (set in the config … … 299 359 addDigitalSample(cur_digital_samples); 300 360 addPositionSample(cur_pos_samples); 301 302 361 return true; 303 362 } juggler/trunk/modules/gadgeteer/drivers/Intersense/IntersenseAPI/IntersenseAPIStandalone.h
r19894 r20886 116 116 /** 117 117 * Returns the format of the angles. 118 * ( 0 == ISD_EULER; 1== ISD_QUATERNION)118 * (1 == ISD_EULER; 2 == ISD_QUATERNION) 119 119 */ 120 120 int getAngleFormat(const unsigned int currentStation) const … … 140 140 } 141 141 142 /////////////143 //144 145 142 /** 146 143 * Return if the Station is ON or OFF. … … 148 145 void setState(const unsigned int currentStation, const bool state) 149 146 { 150 mConfigData[currentStation].State = state;147 mConfigData[currentStation].State = (state ? TRUE : FALSE); 151 148 } 152 149 … … 187 184 188 185 /** 189 * Returns the format of the angles.190 * ( 0 == ISD_EULER; 1== ISD_QUATERNION)186 * Sets the format of the angles. 187 * (1 == ISD_EULER; 2 == ISD_QUATERNION) 191 188 */ 192 189 void setAngleFormat(const unsigned int currentStation, … … 197 194 198 195 /** 199 * Returnwhether the station should send time stamps or not.196 * Sets whether the station should send time stamps or not. 200 197 */ 201 198 void setTimeStamped(const unsigned int currentStation, 202 199 const bool timeStamped) 203 200 { 204 mConfigData[currentStation].TimeStamped = timeStamped;201 mConfigData[currentStation].TimeStamped = (timeStamped ? TRUE : FALSE); 205 202 } 206 203 … … 211 208 void setInputs(const unsigned int currentStation, const bool hasInputs) 212 209 { 213 mConfigData[currentStation].GetInputs = hasInputs;210 mConfigData[currentStation].GetInputs = (hasInputs ? TRUE : FALSE); 214 211 } 215 212 … … 270 267 * Save the current configuration state to the physical tracker device. 271 268 */ 272 void saveConfigState(const int d) 273 { 274 ISD_SetStationConfig( mHandle, &mConfigData[d], d+1, mVerbose ); 269 bool saveConfigState(const int d) 270 { 271 if( ISD_SetStationConfig( mHandle, &mConfigData[d], d+1, (mVerbose ? TRUE : FALSE) ) ) 272 { 273 return true; 274 } 275 return false; 276 } 277 278 /** 279 * Reset the tracking station's boresight. 280 */ 281 bool resetStationBoresight(const int d) 282 { 283 if ( ISD_Boresight( mHandle, d+1, FALSE ) ) 284 { 285 return true; 286 } 287 return false; 288 } 289 290 /** 291 * Sets the default coordinate system for the respective station. 292 */ 293 void setDefaultCoordFrame(const unsigned int currentStation) 294 { 295 /* set frame to default */ 296 mConfigData[currentStation].CoordFrame = ISD_DEFAULT_FRAME; 297 } 298 299 /** 300 * Check to see if we have new data for the i'th receiver. 301 */ 302 bool hasData(const unsigned int i) const 303 { 304 if ( mData.Station[i].NewData ) 305 { 306 return true; 307 } 308 return false; 275 309 } 276 310 … … 328 362 float xQuat(const unsigned int i) const 329 363 { 364 return mData.Station[i].Orientation[1]; 365 } 366 367 /** 368 * Gets the y quaternion value of the i'th receiver. 369 */ 370 float yQuat(const unsigned int i) const 371 { 372 return mData.Station[i].Orientation[2]; 373 } 374 375 /** 376 * Gets the z quaternion value of the i'th receiver. 377 */ 378 float zQuat(const unsigned int i) const 379 { 380 return mData.Station[i].Orientation[3]; 381 } 382 383 /** 384 * Gets the w quaternion value of the i'th receiver. 385 */ 386 float wQuat(const unsigned int i) const 387 { 330 388 return mData.Station[i].Orientation[0]; 331 }332 333 /**334 * Gets the y quaternion value of the i'th receiver.335 */336 float yQuat(const unsigned int i) const337 {338 return mData.Station[i].Orientation[1];339 }340 341 /**342 * Gets the z quaternion value of the i'th receiver.343 */344 float zQuat(const unsigned int i) const345 {346 return mData.Station[i].Orientation[2];347 }348 349 /**350 * Gets the w quaternion value of the i'th receiver.351 */352 float wQuat(const unsigned int i) const353 {354 return mData.Station[i].Orientation[3];355 389 } 356 390
