示例#1
0
 public void HardwareStatusReceived(IRotatorStatus status)
 {
     Logger.Info().Message("Rotator status {status}", status).Write();
     RotatorStatus = status;
     UpdateStatus(status);
     RotatorState.StatusUpdateReceived(status);
 }
示例#2
0
        void SetRotatorState(RotatorState newState)
        {
            rotatorState = newState;

            switch (rotatorState)
            {
            case RotatorState.Spinning:
                rotatorAudioSource.loop = true;
                rotatorAudioSource.clip = rotatorSpin;
                rotatorAudioSource?.Play();
                break;

            case RotatorState.SpinningDown:
                rotatorAudioSource?.PlayOneShot(rotatorSpinDown);
                break;

            case RotatorState.SpinningUp:
                rotatorAudioSource?.PlayOneShot(rotatorSpinUp);
                break;

            case RotatorState.Nothing:
                rotatorAudioSource?.Stop();
                break;
            }
        }
        public void AzimuthEncoderTickReceived(int encoderPosition)
        {
            AzimuthEncoderPosition = encoderPosition;

            // CurrentState.RotationDetected();
            RotatorState.RotationDetected();
        }
示例#4
0
        public void SyncAzimuth(double azimuth)
        {
            Logger.Info().Message("Sync rotator azimuth to {azimuth}", azimuth).Write();
            decimal ticksPerDegree = DomeCircumference / 360.0m;
            decimal syncPosition   = (decimal)azimuth * ticksPerDegree;

            RotatorState.SyncRotatorToStepPosition((int)syncPosition);
        }
示例#5
0
        private bool IsAngleMatched(RotatorState state, float destinationAngle, float currentAngle, float previousAngle)
        {
            // Degenerate case
            if (destinationAngle == currentAngle)
            {
                return(true);
            }

            // COs we are dealing with velocities
            // we can miss our angle, so we need to check a range.
            // Howver it's not a simple number line, but a clock. so caution is required,
            if (state != RotatorState.Clockwise && state != RotatorState.Widdershins)
            {
                throw new Exception("Rotator all out of whack");
            }
            // 1. Get the difference between current and previous update (the direction informs this...Though it's not the end of t
            var angleDistance = (state == RotatorState.Clockwise) ? currentAngle - previousAngle : previousAngle - currentAngle;

            // 3. Is Our angle in the range from Current to Current-DistanceSinceLastUpdate.
            var lowerbound = 0f;
            var upperbound = 0f;

            if (state == RotatorState.Clockwise)
            {
                lowerbound = currentAngle - angleDistance;
                upperbound = (int)Math.Floor(currentAngle) % 360f; // Current angle can read as 360. This may be a bug...Not confident enough to pull it apart.
            }
            else
            {
                lowerbound = (int)Math.Floor(currentAngle); // notice same change not applied as above.
                upperbound = (angleDistance > 0f) ? currentAngle + angleDistance : 360f + angleDistance;
            }

            // if lower is greater than upper
            // we have widdershined/Clockwised around the clock. So we are calculating from the previous/next loop around.
            // or more numbersie we are using the strict numberline and not the modulo.
            // This is an odd way of managing state. We only know we've gone/goingthe clock if the one of the numbers are outside the range
            if (lowerbound > upperbound)
            {
                lowerbound = lowerbound - 360f;
            }
            // Finally is our destination angle between the lower/upperbound
            return(lowerbound <= destinationAngle && upperbound >= destinationAngle);
        }
示例#6
0
 public void SetState(RotatorState state)
 {
     this.State = state;
 }
示例#7
0
 public void AzimuthEncoderTickReceived(int encoderPosition)
 {
     Logger.Debug().Message("Rotator position received {position}", encoderPosition).Write();
     AzimuthEncoderPosition = encoderPosition;
     RotatorState.RotationDetected();
 }
示例#8
0
 public void RotateToHomePosition() => RotatorState.RotateToHomePosition();
示例#9
0
 public void RotateToStepPosition(int targetStepPosition) =>
 RotatorState.RotateToStepPosition(targetStepPosition);
示例#10
0
 public void RotateToAzimuthDegrees(double azimuth)
 {
     // CurrentState.RotateToAzimuthDegrees(azimuth);
     RotatorState.RotateToAzimuthDegrees(azimuth);
 }
示例#11
0
 public void RotationDirectionReceived(RotationDirection direction)
 {
     AzimuthDirection = direction;
     RotatorState.RotationDetected();
 }
示例#12
0
 public void AllStop()
 {
     Logger.Warn().Message("Emergency Stop requested").Write();
     ControllerActions.PerformEmergencyStop();
     RotatorState.HardStopRequested();
 }