//========================================================================================== // // Stops and restarts streaming // //========================================================================================== public void SoftReset() { ISenseLib.ISD_GetStationConfig(handle, ref stationInfo[station - 1], station, true); // Get station config so we don't change anything accidentally stationInfo[station - 1].State = false; // Setting state to false stops streaming ISenseLib.ISD_SetStationConfig(handle, ref stationInfo[station - 1], station, true); // Send station config back to tracker stationInfo[station - 1].State = true; // Re-enable streaming ISenseLib.ISD_SetStationConfig(handle, ref stationInfo[station - 1], station, true); // Send station config back to tracker }
//========================================================================================== // // Called once per frame. If we've connected to a tracker, get its data and move attached object with device // //========================================================================================== void Update() { if (handle > 0) { if (sync) { // Try to predict ISenseLib.ISD_STATION_DATA_TYPE bufferData = new ISenseLib.ISD_STATION_DATA_TYPE(); ISenseLib.ISD_RingBufferQuery(handle, station, ref bufferData, new IntPtr(), new IntPtr()); float dT = (float)Time.deltaTime; float curTime = bufferData.TimeStamp; //TODO: is this right? float timeToPredict = curTime + (framePredict * dT); GetRingBufferDataAtTime(timeToPredict); } else { ISenseLib.ISD_GetTrackingData(handle, ref data); // Get the tracking data } ISenseLib.ISD_STATION_DATA_TYPE dataSet = data.Station[station - 1]; // Specify the dataset // Only IS-1200 and IS-1500 have trackState if (trackerModel == ISenseLib.ISD_SYSTEM_MODEL.ISD_IS1200 || trackerModel == ISenseLib.ISD_SYSTEM_MODEL.ISD_IS1500) { trackState = dataSet.TrackingState; } Vector3 pos; // If device can control position, control position! if (trackerModel == ISenseLib.ISD_SYSTEM_MODEL.ISD_IS600 || trackerModel == ISenseLib.ISD_SYSTEM_MODEL.ISD_IS900 || trackerModel == ISenseLib.ISD_SYSTEM_MODEL.ISD_IS1200 || trackerModel == ISenseLib.ISD_SYSTEM_MODEL.ISD_IS1500) { pos = new Vector3(dataSet.Position[1], -dataSet.Position[2], dataSet.Position[0]); // Their y is up/down while that's our z transform.localPosition = pos; } // Time to deal with rotation! float[] cbn = dataSet.Cbn; float[] eulers; cbn = AngleUtil.ConvertUnityCbn(cbn); // Converts our right-handed rotation frame to unity's left-handed one. eulers = AngleUtil.Cbn2Euler(cbn); transform.localRotation = Quaternion.Euler(eulers[1], eulers[2], eulers[0]); // Pitch, Yaw, Roll } }
public void ToggleSync(bool value) { this.sync = value; //If we are syncing, turn buffer on. if (this.sync) { ISenseLib.ISD_RingBufferStart(handle, station); } else { ISenseLib.ISD_RingBufferStop(handle, station); } }
//========================================================================================== // // Attempts to initialize connection to tracker // //========================================================================================== void AttemptConnection() { DateTime maxWait = System.DateTime.Now; DateTime curTime = System.DateTime.Now; maxWait = maxWait.AddSeconds(10.0); handle = 0; while (maxWait.CompareTo(curTime) > 0 && handle < 1) //check for tracker for 10 seconds { handle = ISenseLib.ISD_OpenTracker(IntPtr.Zero, 0, false, true); if (handle < 1) { Sleep(.1f); } curTime = System.DateTime.Now; } // Check value of handle to see if tracker was located if (handle < 1) { print("Failed to detect"); print(handle); } else { print("Connected to InterSense tracking device!"); tracker = new ISenseLib.ISD_TRACKER_INFO_TYPE(); stationInfo = new ISenseLib.ISD_STATION_INFO_TYPE[8]; data = new ISenseLib.ISD_TRACKING_DATA_TYPE(); // Get tracker configuration info ISenseLib.ISD_GetTrackerConfig(handle, ref tracker, true); ISenseLib.ISD_GetStationConfig(handle, ref stationInfo[station - 1], station, true); ISenseLib.ISD_SetStationConfig(handle, ref stationInfo[station - 1], station, true); trackerModel = (ISenseLib.ISD_SYSTEM_MODEL)tracker.TrackerModel; bufferSize = 180; ISenseLib.ISD_RingBufferSetup(handle, station, null, bufferSize); ISenseLib.ISD_RingBufferStart(handle, station); } }
//========================================================================================== // // Approximates data at time using closest data in ring buffer // //========================================================================================== void GetRingBufferDataAtTime(float time) { ISenseLib.ISD_GetTrackingData(handle, ref data); float[] lastPos = new float[3]; float[] lastCbn = new float[9]; float lastTime = -1; // Search for first data point after time while (data.Station[station - 1].NewData == 1 && data.Station[station - 1].TimeStamp < time) { // Store old data for (int i = 0; i < 3; i = i + 1) { lastPos[i] = data.Station[station - 1].Position[i]; } for (int i = 0; i < 9; i = i + 1) { lastCbn[i] = data.Station[station - 1].Cbn[i]; } lastTime = data.Station[station - 1].TimeStamp; ISenseLib.ISD_GetTrackingData(handle, ref data); } // If last data was saved if (lastTime > 0) { float postTime = data.Station[station - 1].TimeStamp - time; float prevTime = time - lastTime; float postWeight = 1 - (postTime / (postTime + prevTime)); float prevWeight = 1 - (prevTime / (postTime + prevTime)); // Approximate data at time by weighing data from immediately before and immediately after for (int i = 0; i < 3; i = i + 1) { data.Station[station - 1].Position[i] = (data.Station[station - 1].Position[i] * postWeight) + (lastPos[i] * prevWeight); } for (int i = 0; i < 9; i = i + 1) { data.Station[station - 1].Cbn[i] = (data.Station[station - 1].Cbn[i] * postWeight) + (lastCbn[i] * prevWeight); } data.Station[station - 1].TimeStamp = time; } }
//========================================================================================== // // Runs when the object closes, either by turning it off within Unity or closing the program // //========================================================================================== private void OnDisable() { UnityEngine.Debug.Log("closing dll"); ISenseLib.ISD_CloseTracker(handle); // Severs the connection to the tracker // If sfHub is open, we should close it if (sfHub != null && isSfAccess) { if (!sfHub.HasExited) { UnityEngine.Debug.Log("closing sfHub"); sfHub.Kill(); sfHub.WaitForExit(); UnityEngine.Debug.Log("sfHub closed"); } sfHubLaunched = false; sfHub = null; } UnityEngine.Debug.Log("done with isense sample"); }
//========================================================================================== // // Prints pretty much everything not in ShowStationData // //========================================================================================== static public void DebugPrintEverything(int handle, ISenseLib.ISD_TRACKER_INFO_TYPE Tracker, ISenseLib.ISD_STATION_INFO_TYPE Station, ISenseLib.ISD_STATION_DATA_TYPE data) { String s; s = "isense Lib Version: " + Tracker.LibVersion; s = s + " Tracker Type: " + Tracker.TrackerType; s = s + " Tracker Model: " + Tracker.TrackerModel; s = s + " Port: " + Tracker.Port; s = s + " Records Per Second: " + Tracker.RecordsPerSec; s = s + " Kbits Per Second: " + Tracker.KBitsPerSec; s = s + " Sync State: " + Tracker.SyncState; s = s + " Sync Rate: " + Tracker.SyncRate; s = s + " Sync Phase: " + Tracker.SyncPhase; s = s + " Interface: " + Tracker.Interface; s = s + " Ult Timeout: " + Tracker.UltTimeout; s = s + " Ult Volume: " + Tracker.UltVolume; s = s + " Firmware Revision: " + Tracker.FirmwareRev; s = s + " LED Enable: " + Tracker.LedEnable; print("ISD_TRACKER_INFO_TYPE"); print(s); s = "ID: " + Station.ID; s = s + " State: " + Station.State; s = s + " Compass: "******" InertiaCube: " + Station.InertiaCube; s = s + " Enhancement: " + Station.Enhancement; s = s + " Sensitivity: " + Station.Sensitivity; s = s + " Prediction: " + Station.Prediction; s = s + " AngleFormat: " + Station.AngleFormat; s = s + " TimeStamped: " + Station.TimeStamped; s = s + " GetInputs: " + Station.GetInputs; s = s + " GetEncoderData: " + Station.GetEncoderData; s = s + " Compass Compensation: " + Station.CompassCompensation; s = s + " ImuShockSuppression: " + Station.ImuShockSuppression; s = s + " UrmRejectionFactor: " + Station.UrmRejectionFactor; s = s + " GetAHRSData: " + Station.GetAHRSData; s = s + " CoordFrame: " + Station.CoordFrame; s = s + " AccelSensitivity: " + Station.AccelSensitivity; for (int i = 0; i < 3; i = i + 1) { s = s + " TipOffset[" + i + "]: " + Station.TipOffset[i]; } s = s + " GetCameraData: " + Station.GetCameraData; s = s + " GetAuxInputs: " + Station.GetAuxInputs; s = s + " GetCovarianceData: " + Station.GetCovarianceData; s = s + " GetExtendedData: " + Station.GetExtendedData; print("ISD_STATION_INFO_TYPE"); print(s); ISenseLib.ISD_HARDWARE_INFO_TYPE hwInfo = new ISenseLib.ISD_HARDWARE_INFO_TYPE(); ISenseLib.ISD_GetSystemHardwareInfo(handle, ref hwInfo); s = "Valid: " + hwInfo.Valid; s = s + " TrackerType: " + hwInfo.TrackerType; s = s + " TrackerModel: " + hwInfo.TrackerModel; s = s + " Port: " + hwInfo.Port; s = s + " Interface: " + hwInfo.Interface; s = s + " OnHost: " + hwInfo.OnHost; s = s + " AuxSystem: " + hwInfo.AuxSystem; s = s + " FirmwareRev: " + hwInfo.FirmwareRev; s = s + " Model Name: " + hwInfo.ModelName; s = s + " Cap_Position: " + hwInfo.Cap_Position; s = s + " Cap_Orientation: " + hwInfo.Cap_Orientation; s = s + " Cap_Encoders: " + hwInfo.Cap_Encoders; s = s + " Cap_Prediction: " + hwInfo.Cap_Prediction; s = s + " Cap_Compass: "******" Cap_SelfTest: " + hwInfo.Cap_SelfTest; s = s + " Cap_ErrorLog: " + hwInfo.Cap_ErrorLog; s = s + " Cap_UltVolume: " + hwInfo.Cap_UltVolume; s = s + " Cap_UltGain: " + hwInfo.Cap_UltGain; s = s + " Cap_UltTimeout: " + hwInfo.Cap_UltTimeout; s = s + " Cap_PhotoDiode: " + hwInfo.Cap_PhotoDiode; s = s + " Cap_MaxStations: " + hwInfo.Cap_MaxStations; s = s + " Cap_MaxImus: " + hwInfo.Cap_MaxImus; s = s + " Cap_MaxFPses: " + hwInfo.Cap_MaxFPses; s = s + " Cap_MaxChannels: " + hwInfo.Cap_MaxChannels; s = s + " Cap_MaxButtons: " + hwInfo.Cap_MaxButtons; s = s + " Cap_MeasData: " + hwInfo.Cap_MeasData; s = s + " Cap_DiagData: " + hwInfo.Cap_DiagData; s = s + " Cap_PseConfig: " + hwInfo.Cap_PseConfig; s = s + " Cap_ConfigLock: " + hwInfo.Cap_ConfigLock; s = s + " Cap_UltMaxRange: " + hwInfo.Cap_UltMaxRange; s = s + " Cap_CompassCal: " + hwInfo.Cap_CompassCal; s = s + " BaudRate: " + hwInfo.BaudRate; s = s + " NumTestLevels: " + hwInfo.NumTestLevels; print("ISD_HARDWARE_INFO_TYPE"); print(s); ISenseLib.ISD_STATION_HARDWARE_INFO_TYPE sh = new ISenseLib.ISD_STATION_HARDWARE_INFO_TYPE(); ISenseLib.ISD_GetStationHardwareInfo(handle, ref sh, 0); s = "Valid: " + sh.Valid; s = s + " ID: " + sh.ID; s = s + " DescVersion: " + sh.DescVersion; s = s + " FirmwareRev: " + sh.FirmwareRev; s = s + " Serial Number: " + sh.SerialNum; s = s + " CalDate: " + sh.CalDate; s = s + " Port: " + sh.Port; s = s + " Type: " + sh.Type; print("ISD_STATION_HARDWARE_INFO_TYPE"); print(s); s = "TrackingStatus: " + data.TrackingStatus; s = s + " NewData: " + data.NewData; s = s + " CommIntegrity: " + data.CommIntegrity; s = s + " BatteryState: " + data.BatteryState; s = s + " TimeStamp: " + data.TimeStamp; s = s + " StillTime: " + data.StillTime; s = s + " BatteryLevel: " + data.BatteryLevel; s = s + " CompassYaw: " + data.CompassYaw; s = s + " MeasQuality: " + data.MeasQuality; s = s + " HardIronCal: " + data.HardIronCal; s = s + " SoftIronCal: " + data.SoftIronCal; s = s + " EnvironmentalCal: " + data.EnvironmentalCal; s = s + " TimeSTampSeconds: " + data.TimeStampSeconds; s = s + " TimeStampMicroSec: " + data.TimeStampMicroSec; s = s + " OSTimeStampSeconds: " + data.OSTimeStampSeconds; s = s + " OSTimeSTampMicroSec: " + data.OSTimeStampMicroSec; s = s + " CompassQuality: " + data.CompassQuality; s = s + " Temperature: " + data.Temperature; for (int i = 0; i < 3; i = i + 1) { s = s + " MagBodyFrame[" + i + "]: " + data.MagBodyFrame[i]; } s = s + " TrackingState: " + data.TrackingState; print("ISD_STATION_DATA_TYPE"); print(s); }
public bool BoresightReferenced(float yaw, float pitch, float roll) { return(ISenseLib.ISD_BoresightReferenced(handle, station, yaw, pitch, roll)); }
public void SetPrediction(int pred) { ISenseLib.ISD_GetStationConfig(handle, ref stationInfo[station - 1], station, true); stationInfo[station - 1].Prediction = pred; ISenseLib.ISD_SetStationConfig(handle, ref stationInfo[station - 1], station, true); }
//========================================================================================== // // Get and display tracker information // //========================================================================================== static public void showTrackerStats(int handle, ref ISenseLib.ISD_HARDWARE_INFO_TYPE hwInfo) { ISenseLib.ISD_TRACKER_INFO_TYPE Tracker; ISenseLib.ISD_STATION_INFO_TYPE Station; int i, numStations = 4; Tracker = new ISenseLib.ISD_TRACKER_INFO_TYPE(); Station = new ISenseLib.ISD_STATION_INFO_TYPE(); Console.ForegroundColor = ConsoleColor.Green; if (ISenseLib.ISD_GetTrackerConfig(handle, ref Tracker, true)) { Console.Out.WriteLine("\n\n********** InterSense Tracker Information ***********\n\n"); Console.Out.WriteLine("DLL Version: " + Tracker.LibVersion); Console.Out.WriteLine("Type: " + systemType((int)Tracker.TrackerType) + " device on port " + Tracker.Port); Console.Out.WriteLine("Model: " + (hwInfo.Valid ? new String(hwInfo.ModelName) : "Unknown Tracker")); switch (Tracker.TrackerModel) { case (int)ISenseLib.ISD_SYSTEM_MODEL.ISD_IS300: case (int)ISenseLib.ISD_SYSTEM_MODEL.ISD_IS1200: numStations = 4; break; case (int)ISenseLib.ISD_SYSTEM_MODEL.ISD_IS600: case (int)ISenseLib.ISD_SYSTEM_MODEL.ISD_IS900: numStations = ISenseLib.ISD_MAX_STATIONS; break; default: numStations = 1; break; } Console.Out.WriteLine("\nStation\tTime\tState\tCube Enhancement Sensitivity Compass Prediction"); for (i = 1; i <= numStations; i++) { Console.Out.Write("{0:d}\t", i); if (ISenseLib.ISD_GetStationConfig(handle, ref Station, i, false)) { Console.Out.WriteLine("{0:s}\t{1:s}\t{2:s}\t {3:d}\t\t{4:d}\t {5:d}\t {6:d}", Station.TimeStamped ? "ON" : "OFF", Station.State ? "ON" : "OFF", Station.InertiaCube == -1 ? "None" : Station.InertiaCube.ToString(), Station.Enhancement, Station.Sensitivity, Station.Compass, Station.Prediction); } else { Console.Out.WriteLine("ISD_GetStationConfig failed"); break; } } Console.Out.WriteLine(); } else { Console.Out.WriteLine("ISD_GetTrackerConfig failed"); } }
static void Main(string[] args) { int handle; ISenseLib.ISD_TRACKING_DATA_TYPE data; ISenseLib.ISD_STATION_INFO_TYPE[] Station; ISenseLib.ISD_TRACKER_INFO_TYPE Tracker; ISenseLib.ISD_HARDWARE_INFO_TYPE hwInfo; IntPtr handy; bool done = false; int station = 1; uint maxStations = 8; float lastTime; // Detect first tracker. If you have more than one InterSense device and // would like to have a specific tracker, connected to a known port, // initialized first, then enter the port number instead of 0. Otherwise, // tracker connected to the rs232 port with lower number is found first handy = new IntPtr(); Console.ForegroundColor = ConsoleColor.Cyan; Console.Out.WriteLine("Connecting to InterSense tracking device..."); // handle = ISenseLib.ISD_OpenTracker(IntPtr.Zero, 0, false, true); handle = ISenseLib.ISD_OpenAllTrackers(IntPtr.Zero, ref handy, false, true); // Check value of handle to see if tracker was located if (handle < 1) { Console.Out.WriteLine("Failed to detect InterSense tracking device"); } else { Console.Out.WriteLine("Connected; press 'q' to quit, 'e' for enhancement, 'i' to get info\n"); if (handle > 0) { Tracker = new ISenseLib.ISD_TRACKER_INFO_TYPE(); hwInfo = new ISenseLib.ISD_HARDWARE_INFO_TYPE(); Station = new ISenseLib.ISD_STATION_INFO_TYPE[8]; // Get tracker configuration info ISenseLib.ISD_GetTrackerConfig(handle, ref Tracker, true); if (ISenseLib.ISD_GetSystemHardwareInfo(handle, ref hwInfo)) { if (hwInfo.Valid) { maxStations = hwInfo.Cap_MaxStations; } } lastTime = ISenseLib.ISD_GetTime(); ISenseLib.ISD_GetStationConfig(handle, ref Station[station - 1], station, true); data = new ISenseLib.ISD_TRACKING_DATA_TYPE(); while (!done) { ISenseLib.ISD_GetTrackingData(handle, ref data); if (ISenseLib.ISD_GetTime() - lastTime > 0.02f) { lastTime = ISenseLib.ISD_GetTime(); showStationData(handle, Tracker, Station[station - 1], data.Station[station - 1]); } if (Console.KeyAvailable) { switch (Console.ReadKey(true).KeyChar) { case '1': station = 1; Console.Write("\n>> Current Station is set to {0:d} <<\n", station); break; case '2': if (maxStations > 1) { station = 2; Console.Write("\n>> Current Station is set to {0:d} <<\n", station); } break; case '3': if (maxStations > 2) { station = 3; Console.Write("\n>> Current Station is set to {0:d} <<\n", station); } break; case '4': if (maxStations > 3) { station = 4; Console.Write("\n>> Current Station is set to {0:d} <<\n", station); } break; case '5': if (maxStations > 4) { station = 5; Console.Write("\n>> Current Station is set to {0:d} <<\n", station); } break; case '6': if (maxStations > 5) { station = 6; Console.Write("\n>> Current Station is set to {0:d} <<\n", station); } break; case '7': if (maxStations > 6) { station = 7; Console.Write("\n>> Current Station is set to {0:d} <<\n", station); } break; case '8': if (maxStations > 7) { station = 8; Console.Write("\n>> Current Station is set to {0:d} <<\n", station); } break; case 'Q': case 'q': done = true; break; case 'I': case 'i': showTrackerStats(handle, ref hwInfo); break; case 'e': // Set enhancement; IS-x products only, not for InterTrax case 'E': // First get current station configuration if (ISenseLib.ISD_GetStationConfig(handle, ref Station[station - 1], station, true)) { // Cycle enhancement Station[station - 1].Enhancement = (Station[station - 1].Enhancement + 1) % 3; // Send the new configuration to the tracker if (ISenseLib.ISD_SetStationConfig(handle, ref Station[station - 1], station, true)) { // display the results showTrackerStats(handle, ref hwInfo); } } break; case 't': case 'T': // First get current station configuration if (ISenseLib.ISD_GetStationConfig(handle, ref Station[station - 1], station, true)) { Station[station - 1].TimeStamped = !(Station[station - 1].TimeStamped); // Send the new configuration to the tracker if (ISenseLib.ISD_SetStationConfig(handle, ref Station[station - 1], station, true)) { // display the results showTrackerStats(handle, ref hwInfo); } } break; case 'd': case 'D': showTrackerStats(handle, ref hwInfo); break; case 'p': case 'P': // First get current station configuration if (ISenseLib.ISD_GetStationConfig(handle, ref Station[station - 1], station, true)) { // Cycle enhancement Station[station - 1].Prediction = (Station[station - 1].Prediction + 10) % 60; // Send the new configuration to the tracker if (ISenseLib.ISD_SetStationConfig(handle, ref Station[station - 1], station, true)) { // display the results showTrackerStats(handle, ref hwInfo); } } break; case 's': case 'S': // First get current station configuration if (ISenseLib.ISD_GetStationConfig(handle, ref Station[station - 1], station, true)) { // Cycle enhancement Station[station - 1].Sensitivity = (Station[station - 1].Sensitivity + 1) % 5; if (Station[station - 1].Sensitivity == 0) { Station[station - 1].Sensitivity = 1; } // Send the new configuration to the tracker if (ISenseLib.ISD_SetStationConfig(handle, ref Station[station - 1], station, true)) { // display the results showTrackerStats(handle, ref hwInfo); } } break; case 'c': case 'C': // First get current station configuration if (ISenseLib.ISD_GetStationConfig(handle, ref Station[station - 1], station, true)) { // Cycle enhancement Station[station - 1].Compass = (Station[station - 1].Compass + 1) % 3; // Send the new configuration to the tracker if (ISenseLib.ISD_SetStationConfig(handle, ref Station[station - 1], station, true)) { // display the results showTrackerStats(handle, ref hwInfo); } } break; } } } ISenseLib.ISD_CloseTracker(handle); } } }