// Controls the direction the wheelchair moves private void Drive() //this function calls a function in navigator that looks for offset { // Check whether the thread has previously been named // to avoid a possible InvalidOperationException. int offset = Navigator.GetCalibrationResult(); //initial setup Vehicle.SetOffset(offset); while (this.Running) { Vector direction = Navigator.GetDirection(this.UserInput.InputDirection); if (Navigator.GetCalibrationResult() != offset) //if the offset has changed { offset = Navigator.GetCalibrationResult(); Vehicle.SetOffset(offset); //sets the offset in the wheelchair class, SetOffset does stuff } // The length should be in the range [0, 1]. Convert it to [0, 100] as the wheelchair expects int speed = (int)(direction.Length * 100); // Clamp the speed to [0, 100] speed = Math.Min(speed, 100); speed = Math.Max(speed, 0); if (direction.Length != 0) { direction.Normalize(); } this.Vehicle.SetSpeedAndDirection(speed, direction); Thread.Sleep(50); } this.Vehicle.SetSpeedAndDirection(0, new Vector(0, 0)); }