Ejemplo n.º 1
0
        private PololuMaestroPoint DefaultMaxPoint()
        {
            PololuMaestroPoint point = new PololuMaestroPoint()
            {
                FalconValue = DefaultFalconMaxValue, ServoValue = 8000
            };

            point.PropertyChanged += OnPointChanged;
            return(point);
        }
Ejemplo n.º 2
0
        private void executeAddAdditionalPoint(object o)
        {
            PololuMaestroPoint previousPoint   = AdditionalPointList.LastOrDefault() ?? MinPoint;
            PololuMaestroPoint nextPoint       = MaxPoint;
            PololuMaestroPoint additionalPoint = new PololuMaestroPoint()
            {
                FalconValue = (previousPoint.FalconValue + nextPoint.FalconValue) / 2,
                ServoValue  = (ushort)((previousPoint.ServoValue + nextPoint.ServoValue) / 2)
            };

            AdditionalPointList.Add(additionalPoint);
        }
Ejemplo n.º 3
0
        private ushort FalconValueToServoValue(float?falconValue)
        {
            if (!falconValue.HasValue)
            {
                return(0);
            }

            // Clamp value to [Min, Max]
            if (falconValue.Value <= MinPoint.FalconValue)
            {
                return(MinPoint.ServoValue);
            }

            if (falconValue.Value >= MaxPoint.FalconValue)
            {
                return(MaxPoint.ServoValue);
            }

            // Find the segment that contains falconValue
            PololuMaestroPoint previousPoint = MinPoint;
            PololuMaestroPoint nextPoint     = null;

            foreach (PololuMaestroPoint additionalPoint in AdditionalPointList)
            {
                if (falconValue.Value >= additionalPoint.FalconValue)
                {
                    previousPoint = additionalPoint;
                }
                else
                {
                    nextPoint = additionalPoint;
                    break;
                }
            }

            if (nextPoint == null)
            {
                nextPoint = MaxPoint;
            }

            // Interpolate in segment
            float normalizedValue = 0.5F;

            if (previousPoint.FalconValue != nextPoint.FalconValue)
            {
                normalizedValue = (falconValue.Value - previousPoint.FalconValue) / (nextPoint.FalconValue - previousPoint.FalconValue);
            }
            return((ushort)(normalizedValue * (nextPoint.ServoValue - previousPoint.ServoValue) + previousPoint.ServoValue));
        }
Ejemplo n.º 4
0
        private bool canExecuteRemoveAdditionalPoint(object o)
        {
            PololuMaestroPoint additionalPoint = (PololuMaestroPoint)o;

            return(AdditionalPointList.Contains(additionalPoint));
        }
Ejemplo n.º 5
0
        private void executeRemoveAdditionalPoint(object o)
        {
            PololuMaestroPoint additionalPoint = (PololuMaestroPoint)o;

            AdditionalPointList.Remove(additionalPoint);
        }