Пример #1
0
        public void StartMove(Vector2 direction)
        {
            if (!CenteringDone())
            {
                return;
            }
            const float deadzone = 0.5f;
            lock (_driver.SyncLock)
            {
                _driver.SetMovingSpeed(HorizontalMotorIndex, 30);
                _driver.SetMovingSpeed(VerticalMotorIndex, 20);
                if (-direction.Y > deadzone)
                {
                    _driver.SetGoalPositionInDegrees(HorizontalMotorIndex, 0);
                }
                else if (-direction.Y < -deadzone)
                {
                    _driver.SetGoalPositionInDegrees(HorizontalMotorIndex, 300);
                }
                else
                {
                    var currentPos = _driver.GetPresentPosition(HorizontalMotorIndex);
                    _driver.SetGoalPosition(HorizontalMotorIndex, currentPos);
                }

                if (direction.X > deadzone)
                {
                    _driver.SetGoalPositionInDegrees(VerticalMotorIndex, 270);
                }
                else if (direction.X < -deadzone)
                {
                    _driver.SetGoalPositionInDegrees(VerticalMotorIndex, 30);
                }
                else
                {
                    var currentPos = _driver.GetPresentPosition(VerticalMotorIndex);
                    _driver.SetGoalPosition(VerticalMotorIndex, currentPos);
                }
            }
        }