void Awake() { if (SystemInfo.supportsGyroscope) { filter = new ComplementaryFilter(.98f, PREDICTION_TIME); Input.gyro.enabled = true; } else { filter = new ComplementaryFilter(.5f, PREDICTION_TIME); } posePredictor = new PosePredictor(PREDICTION_TIME); filterToWorldQ = Quaternion.AngleAxis(-Mathf.PI / 2, new Vector3(1, 0, 0)); originalPoseAdjustQ = Quaternion.AngleAxis(-windowOrientation * Mathf.PI / 18, new Vector3(0, 0, 1)); SetScreenTransform(); if (isLandscape) { filterToWorldQ *= inverseWorldToScreenQ; } Recenter(); }
public Game(Parameters param, int alg) { graphics = new GraphicsDeviceManager(this); Content.RootDirectory = "Content"; this.IsMouseVisible = true; this.alg = alg; dt = 1.0 / param.freq; this.COMport = "PL=PL_001{PN=COM" + param.porta + ", SENDMODE=B}"; if (alg == 1) //Complementary filter { ComplementaryFilter = new ComplementaryFilter(param); } if (alg == 2) //AHRS { AHRS = new AHRSalgorithm(); AHRS.setParamaters(param.AHRSpar1, param.AHRSpar2, param.freq); } if (alg == 3) //Kalman filter { KalmanFilter = new KalmanFilter(param); } this.Exiting += new EventHandler(Game1_Exiting); }
void Awake() { if (instance != null) { UnityEngine.Debug.LogError("More than an instance of SensorFusion detected!"); } instance = this; if (SystemInfo.supportsGyroscope) { filter = new ComplementaryFilter(.98f); Input.gyro.enabled = true; Input.gyro.updateInterval = 0.0167f; // Set the update interval to it's highest value (60 Hz) } else { Debug.LogWarning("This device doesn't have a gyroscope! Using accelerometer only (if available)"); filter = new ComplementaryFilter(.5f); } posePredictor = new PosePredictor(); filterToWorldQ = Quaternion.AngleAxis((-Mathf.PI / 2) * Mathf.Rad2Deg, new Vector3(1, 0, 0)); originalPoseAdjustQ = Quaternion.AngleAxis((-windowOrientation * Mathf.PI / 18) * Mathf.Rad2Deg, new Vector3(0, 0, 1)); SetScreenTransform(); if (isLandscape) { filterToWorldQ *= inverseWorldToScreenQ; } Recenter(); }
private async void Selector_OnBoardConnected(object sender, Treehopper.Mvvm.BoardConnectedEventArgs e) { var imu = new Mpu9250(e.Board.I2c); imu.EnableMagnetometer = false; await imu.Calibrate(); filter = new ComplementaryFilter(imu, imu, 5, true); filter.FilterUpdate += Filter_FilterUpdate; }
// Use this for initialization void Start() { complementaryFuzer = new ComplementaryFilter(); wiimote = GameObject.Find("wiimote"); Angles = new Vector3(); vSliderValuePrev = vSliderValue = 128f; timer = new Timer(500.0); timer.Elapsed += new ElapsedEventHandler(onTimerElapsed); ui = this.GetComponent <UserInterfaceWindow>(); //supporting devices with custom drivers //When you add them add specialized first then XInputDriver then wide range supporting drivers UnityDriver #if (UNITY_STANDALONE_WIN) InputManager.hidInterface.defaultDriver = new UnityDriver(); InputManager.AddDriver(new ThrustMasterDriver()); InputManager.AddDriver(new WiiDriver()); //InputManager.AddDriver(new XInputDriver()); #endif #if (UNITY_STANDALONE_OSX) //InputManager.AddDriver(new ThrustMasterDriver()); //InputManager.AddDriver(new XInputDriver()); InputManager.hidInterface.defaultDriver = new UnityDriver(); #endif #if (UNITY_STANDALONE_ANDROID) InputManager.AddDriver(new ThrustMasterDriver()); #endif //TODO think of better entry point InputManager.hidInterface.Enumerate(); // !!!Postive аxes mapping only currently(need to find way to distinct postive from negative axis in Unity way of handling) // if(Application.isPlaying) // InputManager.AddDriver(new UnityDriver()); //if you want to load some states from .xml and add custom manually first load settings xml //!!!Application.streamingAssetPath gives "Raw" folder in web player #if (UNITY_STANDALONE || UNITY_EDITOR) && !UNITY_WEBPLAYER && !UNITY_ANDROID //UnityEngine.Debug.Log("Standalone"); if (ui != null) {//settingsXML would trigger internal loading mechanism (only for testing) InputManager.loadSettings(Path.Combine(Application.streamingAssetsPath, "InputSettings.xml")); ui.settings = InputManager.Settings; } manuallyAddStateAndHandlers(); #endif #region Load InputSettings.xml Android #if UNITY_ANDROID Loader request = new Loader(); if (Application.platform == RuntimePlatform.Android) { if (File.Exists(Application.persistentDataPath + "/" + "InputSettings.xml")) { if (ui != null) { Debug.Log("Game>> Try to load from " + Application.persistentDataPath); InputManager.loadSettings(Application.persistentDataPath + "/" + "InputSettings.xml"); ui.settings = InputManager.Settings; manuallyAddStateAndHandlers(); return; } } else {// content of StreamingAssets get packed inside .APK and need to be load with WWW request.Add(Path.Combine(Application.streamingAssetsPath, "InputSettings.xml")); } request.LoadComplete += new EventHandler <LoaderEvtArgs <List <WWW> > >(onLoadComplete); request.Error += new EventHandler <LoaderEvtArgs <String> >(onLoadError); request.LoadItemComplete += new EventHandler <LoaderEvtArgs <WWW> >(onLoadItemComplete); request.load(); } else //TARGET=ANDROID but playing in EDITOR => use Standalone setup { if (ui != null) {//settingsXML would trigger internal loading mechanism (only for testing) InputManager.loadSettings(Path.Combine(Application.streamingAssetsPath, "InputSettings.xml")); ui.settings = InputManager.Settings; } manuallyAddStateAndHandlers(); } #endif #endregion #if (UNITY_WEBPLAYER || UNITY_EDITOR) && !UNITY_STANDALONE && !UNITY_ANDROID Loader request = new Loader(); //UNITY_WEBPLAYER: Application.dataPath "http://localhost/appfolder/" request.Add(Application.dataPath + "/StreamingAssets/InputSettings.xml"); request.LoadComplete += new EventHandler <LoaderEvtArgs <List <WWW> > >(onLoadComplete); request.Error += new EventHandler <LoaderEvtArgs <String> >(onLoadError); request.LoadItemComplete += new EventHandler <LoaderEvtArgs <WWW> >(onLoadItemComplete); request.load(); #endif }