Ejemplo n.º 1
0
 public bool SetAlarmTemp(double value, ToleranceType limit, int chanelNo)
 {
     if (value <= 0)
     {
         return(false);
     }
     if (limit == ToleranceType.High)
     {
         try
         {
             byte[] bytes = this.ModbusMaster.BuildWriteMessage(this.SlaveAddr, (ushort)(this.UpLimitAlarmAddr + chanelNo * 4), this.ConvertToWriteTemp(value));
             this.EasySerialPort.SerialPort.DiscardInBuffer();
             ByteData data = this.EasySerialPort.WriteAndGetReply(bytes, TimeSpan.FromSeconds(1));
             return(true);
         }
         catch (Exception)
         {
             return(false);
         }
     }
     else
     {
         try
         {
             byte[] bytes = this.ModbusMaster.BuildWriteMessage(this.SlaveAddr, (ushort)(this.DownLimitAlarmAddr + chanelNo * 4), this.ConvertToWriteTemp(value));
             this.EasySerialPort.SerialPort.DiscardInBuffer();
             ByteData data = this.EasySerialPort.WriteAndGetReply(bytes, TimeSpan.FromSeconds(1));
             return(true);
         }
         catch (Exception)
         {
             return(false);
         }
     }
 }
Ejemplo n.º 2
0
        public PIDController(double Kp, double Ki, double Kd, double Kf,
            IPIDSource source, IPIDOutput output,
            double period)
        {
            if (source == null)
                throw new ArgumentNullException(nameof(source), "Null PIDSource was given");
            if (output == null)
                throw new ArgumentNullException(nameof(output), "Null PIDOutput was given");

            m_controlLoop = new Notifier(CallCalculate, this);

            m_P = Kp;
            m_I = Ki;
            m_D = Kd;
            m_F = Kf;

            m_ipidInput = source;
            m_ipidOutput = output;
            m_period = period;

            m_controlLoop.StartPeriodic(m_period);

            s_instances++;
            HLUsageReporting.ReportPIDController(s_instances);

            m_toleranceType = ToleranceType.NoTolerance;
        }
Ejemplo n.º 3
0
 public bool GetAlarmTemp(out double result, ToleranceType limit, int chanelNo)
 {
     try
     {
         if (limit == ToleranceType.High)
         {
             byte[] bytes = this.ModbusMaster.BuildReadMessage(this.SlaveAddr, (ushort)(this.UpLimitAlarmAddr + chanelNo * 4), 2);
             this.EasySerialPort.SerialPort.DiscardInBuffer();
             ByteData data = this.EasySerialPort.WriteAndGetReply(bytes, TimeSpan.FromSeconds(1));
             string   s1   = data.Bytes[3].ToString("X2");
             string   s2   = data.Bytes[4].ToString("X2");
             result = Convert.ToInt32((s1 + s2), 16) * 0.1;
         }
         else
         {
             byte[] bytes = this.ModbusMaster.BuildReadMessage(this.SlaveAddr, (ushort)(this.DownLimitAlarmAddr + chanelNo * 4), 2);
             this.EasySerialPort.SerialPort.DiscardInBuffer();
             ByteData data = this.EasySerialPort.WriteAndGetReply(bytes, TimeSpan.FromSeconds(1));
             string   s1   = data.Bytes[3].ToString("X2");
             string   s2   = data.Bytes[4].ToString("X2");
             result = Convert.ToInt32((s1 + s2), 16) * 0.1;
         }
         return(true);
     }
     catch (Exception)
     {
         result = 0;
         return(false);
     }
 }
Ejemplo n.º 4
0
        /// <summary>
        /// Gets the bounds of this PathGeometry as an axis-aligned bounding box with pen and/or transform
        /// </summary>
        internal static Rect GetPathBounds(
            PathGeometryData pathData,
            Pen pen,
            Matrix worldMatrix,
            double tolerance,
            ToleranceType type,
            bool skipHollows)
        {
            if (pathData.IsEmpty())
            {
                return(Rect.Empty);
            }
            else
            {
                MilRectD bounds = PathGeometry.GetPathBoundsAsRB(
                    pathData,
                    pen,
                    worldMatrix,
                    tolerance,
                    type,
                    skipHollows);

                return(bounds.AsRect);
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Creates a new PID object with the given contants for P, I, D and F.
        /// </summary>
        /// <param name="kp">The proportional coefficient.</param>
        /// <param name="ki">The integral coefficient</param>
        /// <param name="kd">The derivative coefficient</param>
        /// <param name="kf">The feed forward term.</param>
        /// <param name="source">The PIDSource object that is used to get values.</param>
        /// <param name="output">The PIDOutput object that is set to the output percentage.</param>
        /// <param name="period">The loop time for doing calculations.</param>
        public PIDController(double kp, double ki, double kd, double kf,
                             IPIDSource source, IPIDOutput output,
                             double period)
        {
            if (source == null)
            {
                throw new ArgumentNullException(nameof(source), "Null PIDSource was given");
            }
            if (output == null)
            {
                throw new ArgumentNullException(nameof(output), "Null PIDOutput was given");
            }

            CalculateCallback = Calculate;
            m_controlLoop     = new Notifier(CalculateCallback);
            m_setpointTimer   = new Timer();
            m_setpointTimer.Start();

            m_P = kp;
            m_I = ki;
            m_D = kd;
            m_F = kf;

            PIDInput  = source;
            PIDOutput = output;
            m_period  = period;

            m_controlLoop.StartPeriodic(m_period);

            s_instances++;
            HAL.Base.HAL.Report(ResourceType.kResourceType_PIDController, (byte)s_instances);

            m_toleranceType = ToleranceType.NoTolerance;
            m_buf           = new Queue <double>(m_bufLength + 1);
        }
Ejemplo n.º 6
0
 public bool SetAlarmTemp(double value, ToleranceType limit, int chanelNo)
 {
     if (value <= 0)
     {
         return(false);
     }
     try
     {
         byte[] bytes = null;
         if (limit == ToleranceType.High)
         {
             bytes = this.ModbusMaster.BuildWriteMessage(this.AddressSlave, this.AddrUpperAlarm, this.ConvertToWriteTemp(value));
         }
         else
         {
             bytes = this.ModbusMaster.BuildWriteMessage(this.AddressSlave, this.AddrLowerAlarm, this.ConvertToWriteTemp(value));
         }
         this.EasySerialPort.SerialPort.DiscardInBuffer();
         ByteData data = this.EasySerialPort.WriteAndGetReply(bytes, TimeSpan.FromSeconds(1));
         return(true);
     }
     catch (Exception)
     {
         return(false);
     }
 }
Ejemplo n.º 7
0
        /// <summary>
        /// Gets the area of this geometry
        /// </summary>
        /// <param name="tolerance">The computational error tolerance</param>
        /// <param name="type">The way the error tolerance will be interpreted - relative or absolute</param>
        public override double GetArea(double tolerance, ToleranceType type)
        {
            ReadPreamble();

            if (IsEmpty())
            {
                return(0.0);
            }

            double radiusX = RadiusX;
            double radiusY = RadiusY;
            Rect   rect    = Rect;

            // Get the area of the bounding rectangle
            double area = Math.Abs(rect.Width * rect.Height);

            // correct it for the rounded corners
            area -= Math.Abs(radiusX * radiusY) * (4.0 - Math.PI);

            // Adjust to internal transformation
            Transform transform = Transform;

            if (!transform.IsIdentity)
            {
                area *= Math.Abs(transform.Value.Determinant);
            }

            return(area);
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Returns the axis-aligned bounding rectangle when stroked with a pen.
        /// </summary>
        /// <param name="pen">The pen</param>
        /// <param name="tolerance">The computational error tolerance</param>
        /// <param name="type">The way the error tolerance will be interpreted - relative or absolute</param>
        public virtual Rect GetRenderBounds(Pen pen, double tolerance, ToleranceType type)
        {
            ReadPreamble();

            Matrix matrix = Matrix.Identity;

            return(GetBoundsInternal(pen, matrix, tolerance, type));
        }
Ejemplo n.º 9
0
 /// <summary>
 /// Sets the absolute error which is considered tolerable for use with <see cref="OnTarget"/>.
 /// </summary>
 /// <remarks>The value is in the same range as the PIDInput values.</remarks>
 /// <param name="absTolerance">The absolute tolerance.</param>
 public void SetAbsoluteTolerance(double absTolerance)
 {
     lock (m_lockObject)
     {
         m_toleranceType = ToleranceType.AbsoluteTolerance;
         m_tolerance     = absTolerance;
     }
 }
Ejemplo n.º 10
0
 /// <summary>
 /// Set the percentage error which is considered tolerable for use with <see cref="OnTarget"/>.
 /// </summary>
 /// <param name="percent">The percent tolerance.</param>
 public void SetPercentTolerance(double percent)
 {
     lock (m_lockObject)
     {
         m_toleranceType = ToleranceType.PercentTolerance;
         m_tolerance     = percent;
     }
 }
Ejemplo n.º 11
0
        /// <summary>
        /// Serializes this instance
        /// </summary>
        internal void Serialize(XmlWriter writer)
        {
            switch (ToleranceType)
            {
            case ToleranceType.Circular when CircularToleranceRadius.HasValue:
                writer.WriteAttributeString("Type", ToleranceType.ToString());
                writer.WriteAttributeString("Radius", XmlConvert.ToString(CircularToleranceRadius.Value));
                break;

            case ToleranceType.Rectangular:
                writer.WriteAttributeString("Type", ToleranceType.ToString());

                if (RectangleToleranceHeight.HasValue)
                {
                    writer.WriteAttributeString("Height", XmlConvert.ToString(RectangleToleranceHeight.Value));
                }
                if (RectangleToleranceWidth.HasValue)
                {
                    writer.WriteAttributeString("Width", XmlConvert.ToString(RectangleToleranceWidth.Value));
                }
                break;

            case ToleranceType.Spatial:
                writer.WriteAttributeString("Type", ToleranceType.ToString());

                if (SpatialTolerance != null)
                {
                    writer.WriteAttributeString("X", XmlConvert.ToString(SpatialTolerance.X));
                    writer.WriteAttributeString("Y", XmlConvert.ToString(SpatialTolerance.Y));
                    writer.WriteAttributeString("Z", XmlConvert.ToString(SpatialTolerance.Z));
                }

                break;

            case ToleranceType.Default:
                if (IsSymmetric)
                {
                    if (Upper != null && Lower != null)
                    {
                        writer.WriteValue(XmlConvert.ToString(Upper.Value - Lower.Value));
                    }
                }
                else
                {
                    if (Lower.HasValue)
                    {
                        writer.WriteElementString("Lower", XmlConvert.ToString(Lower.Value));
                    }

                    if (Upper.HasValue)
                    {
                        writer.WriteElementString("Upper", XmlConvert.ToString(Upper.Value));
                    }
                }

                break;
            }
        }
Ejemplo n.º 12
0
        /// <summary>
        /// Returns true if point is inside the stroke of a pen on this geometry.
        /// </summary>
        /// <param name="pen">The pen used to define the stroke</param>
        /// <param name="hitPoint">The point tested for containment</param>
        /// <param name="tolerance">Acceptable margin of error in distance computation</param>
        /// <param name="type">The way the error tolerance will be interpreted - relative or absolute</param>
        public bool StrokeContains(Pen pen, Point hitPoint, double tolerance, ToleranceType type)
        {
            if (pen == null)
            {
                return(false);
            }

            return(ContainsInternal(pen, hitPoint, tolerance, type));
        }
Ejemplo n.º 13
0
 /// <summary>
 /// Returns the result of a Boolean combination of two Geometry objects.
 /// </summary>
 /// <param name="geometry1">The first Geometry object</param>
 /// <param name="geometry2">The second Geometry object</param>
 /// <param name="mode">The mode in which the objects will be combined</param>
 /// <param name="transform">A transformation to apply to the result, or null</param>
 /// <param name="tolerance">The computational error tolerance</param>
 /// <param name="type">The way the error tolerance will be interpreted - relative or absolute</param>
 public static PathGeometry Combine(
     Geometry geometry1,
     Geometry geometry2,
     GeometryCombineMode mode,
     Transform transform,
     double tolerance,
     ToleranceType type)
 {
     return(PathGeometry.InternalCombine(geometry1, geometry2, mode, transform, tolerance, type));
 }
Ejemplo n.º 14
0
        public virtual PathGeometry GetOutlinedPathGeometry(double tolerance, ToleranceType type)
        {
            ReadPreamble();

            if (IsObviouslyEmpty())
            {
                return(new PathGeometry());
            }

            PathGeometryData pathData = GetPathGeometryData();

            if (pathData.IsEmpty())
            {
                return(new PathGeometry());
            }

            PathGeometry resultGeometry = null;

            unsafe
            {
                fixed(byte *pbPathData = pathData.SerializedData)
                {
                    Invariant.Assert(pbPathData != (byte *)0);

                    FillRule fillRule = FillRule.Nonzero;

                    PathGeometry.FigureList list = new PathGeometry.FigureList();

                    int hr = UnsafeNativeMethods.MilCoreApi.MilUtility_PathGeometryOutline(
                        &pathData.Matrix,
                        pathData.FillRule,
                        pbPathData,
                        pathData.Size,
                        tolerance,
                        type == ToleranceType.Relative,
                        new PathGeometry.AddFigureToListDelegate(list.AddFigureToList),
                        out fillRule);

                    if (hr == (int)MILErrors.WGXERR_BADNUMBER)
                    {
                        // When we encounter NaNs in the renderer, we absorb the error and draw
                        // nothing. To be consistent, we return an empty geometry.
                        resultGeometry = new PathGeometry();
                    }
                    else
                    {
                        HRESULT.Check(hr);

                        resultGeometry = new PathGeometry(list.Figures, fillRule, null);
                    }
                }
            }

            return(resultGeometry);
        }
        /// <summary>
        /// Gets the area of this geometry
        /// </summary>
        /// <param name="tolerance">The computational error tolerance</param>
        /// <param name="type">The way the error tolerance will be interpreted - realtive or absolute</param>
        public override double GetArea(double tolerance, ToleranceType type)
        {
            ReadPreamble();

            // Potential speedup, to be done if proved important:  As the result of a Combine
            // operation, the result of GetAsPathGeometry() is guaranteed to be organized into
            // flattened well oriented figures.  Its area can therefore be computed much faster
            // without the heavy machinary of CArea.  This will require writing an internal
            // CShapeBase::GetRawArea method, and a utility to invoke it.  For now:
            return(GetAsPathGeometry().GetArea(tolerance, type));
        }
Ejemplo n.º 16
0
        internal static IntersectionDetail HitTestWithPathGeometry(
            Geometry geometry1,
            Geometry geometry2,
            double tolerance,
            ToleranceType type)
        {
            IntersectionDetail detail = IntersectionDetail.NotCalculated;

            unsafe
            {
                PathGeometryData data1 = geometry1.GetPathGeometryData();
                PathGeometryData data2 = geometry2.GetPathGeometryData();

                fixed(byte *pbPathData1 = data1.SerializedData)
                {
                    Debug.Assert(pbPathData1 != (byte *)0);

                    fixed(byte *pbPathData2 = data2.SerializedData)
                    {
                        Debug.Assert(pbPathData2 != (byte *)0);

                        int hr = MilCoreApi.MilUtility_PathGeometryHitTestPathGeometry(
                            &data1.Matrix,
                            data1.FillRule,
                            pbPathData1,
                            data1.Size,
                            &data2.Matrix,
                            data2.FillRule,
                            pbPathData2,
                            data2.Size,
                            tolerance,
                            type == ToleranceType.Relative,
                            &detail);

                        if (hr == (int)MILErrors.WGXERR_BADNUMBER)
                        {
                            // When we encounter NaNs in the renderer, we absorb the error and draw
                            // nothing. To be consistent, we report that the geometry is never hittable.
                            detail = IntersectionDetail.Empty;
                        }
                        else
                        {
                            HRESULT.Check(hr);
                        }
                    }
                }
            }

            Debug.Assert(detail != IntersectionDetail.NotCalculated);

            return(detail);
        }
Ejemplo n.º 17
0
        public virtual double GetArea(double tolerance, ToleranceType type)
        {
            ReadPreamble();

            if (IsObviouslyEmpty())
            {
                return(0);
            }

            PathGeometryData pathData = GetPathGeometryData();

            if (pathData.IsEmpty())
            {
                return(0);
            }

            double area;

            unsafe
            {
                // Call the core method on the path data
                fixed(byte *pbPathData = pathData.SerializedData)
                {
                    Debug.Assert(pbPathData != (byte *)0);

                    int hr = MilCoreApi.MilUtility_GeometryGetArea(
                        pathData.FillRule,
                        pbPathData,
                        pathData.Size,
                        &pathData.Matrix,
                        tolerance,
                        type == ToleranceType.Relative,
                        &area);

                    if (hr == (int)MILErrors.WGXERR_BADNUMBER)
                    {
                        // When we encounter NaNs in the renderer, we absorb the error and draw
                        // nothing. To be consistent, we report that the geometry has 0 area.
                        area = 0.0;
                    }
                    else
                    {
                        HRESULT.Check(hr);
                    }
                }
            }

            return(area);
        }
Ejemplo n.º 18
0
        /// <summary>
        /// Gets the area of this geometry
        /// </summary>
        /// <param name="tolerance">The computational error tolerance</param>
        /// <param name="type">The way the error tolerance will be interpreted - realtive or absolute</param>
        public override double GetArea(double tolerance, ToleranceType type)
        {
            ReadPreamble();

            double area = Math.Abs(RadiusX * RadiusY) * Math.PI;

            // Adjust to internal transformation
            Transform transform = Transform;

            if (transform != null && !transform.IsIdentity)
            {
                area *= Math.Abs(transform.Value.Determinant);
            }

            return(area);
        }
Ejemplo n.º 19
0
        /// <summary>
        /// Approximate this figure with a polygonal PathFigure
        /// </summary>
        /// <param name="tolerance">The approximation error tolerance</param>
        /// <param name="type">The way the error tolerance will be interpreted - relative or absolute</param>
        /// <returns>Returns the polygonal approximation as a PathFigure.</returns>
        public PathFigure GetFlattenedPathFigure(double tolerance, ToleranceType type)
        {
            PathGeometry geometry = new PathGeometry();
            geometry.Figures.Add(this);

            PathGeometry flattenedGeometry = geometry.GetFlattenedPathGeometry(tolerance, type);

            int count = flattenedGeometry.Figures.Count;

            if (count == 0)
            {
                return new PathFigure();
            }
            else if (count == 1)
            {
                return flattenedGeometry.Figures[0];
            }
            else
            {
                throw new InvalidOperationException(SR.Get(SRID.PathGeometry_InternalReadBackError));
            }
        }
Ejemplo n.º 20
0
        /// <summary>
        /// Approximate this figure with a polygonal PathFigure
        /// </summary>
        /// <param name="tolerance">The approximation error tolerance</param>
        /// <param name="type">The way the error tolerance will be interpreted - relative or absolute</param>
        /// <returns>Returns the polygonal approximation as a PathFigure.</returns>
        public PathFigure GetFlattenedPathFigure(double tolerance, ToleranceType type)
        {
            PathGeometry geometry = new PathGeometry();

            geometry.Figures.Add(this);

            PathGeometry flattenedGeometry = geometry.GetFlattenedPathGeometry(tolerance, type);

            int count = flattenedGeometry.Figures.Count;

            if (count == 0)
            {
                return(new PathFigure());
            }
            else if (count == 1)
            {
                return(flattenedGeometry.Figures[0]);
            }
            else
            {
                throw new InvalidOperationException(SR.Get(SRID.PathGeometry_InternalReadBackError));
            }
        }
Ejemplo n.º 21
0
        internal override bool ContainsInternal(Pen pen, Point hitPoint, double tolerance, ToleranceType type)
        {
            unsafe
            {
                Point *pPoints = stackalloc Point[(int)GetPointCount()];
                EllipseGeometry.GetPointList(pPoints, GetPointCount(), Center, RadiusX, RadiusY);

                fixed(byte *pTypes = GetTypeList())
                {
                    return(ContainsInternal(
                               pen,
                               hitPoint,
                               tolerance,
                               type,
                               pPoints,
                               GetPointCount(),
                               pTypes,
                               GetSegmentCount()));
                }
            }
        }
Ejemplo n.º 22
0
        /// <summary>
        /// Returns the axis-aligned bounding rectangle when stroked with a pen, after applying
        /// the supplied transform (if non-null).
        /// </summary>
        internal override Rect GetBoundsInternal(Pen pen, Matrix matrix, double tolerance, ToleranceType type)
        {
            Matrix geometryMatrix;

            Transform.GetTransformValue(Transform, out geometryMatrix);

            return(EllipseGeometry.GetBoundsHelper(
                       pen,
                       matrix,
                       Center,
                       RadiusX,
                       RadiusY,
                       geometryMatrix,
                       tolerance,
                       type));
        }
Ejemplo n.º 23
0
 /// <summary>
 /// Creates a new tolerance given a unit, value, and whether the tolerance is ±
 /// </summary>
 /// <param name="unit">The units for this tolerance</param>
 /// <param name="value">The numerical value of the tolerance</param>
 /// <param name="type">Whether the tolerance is full or half width</param>
 public Tolerance(ToleranceUnit unit, double value, ToleranceType type = ToleranceType.PlusAndMinus)
 {
     Unit = unit;
     Value = value;
     Type = type;
 }
 public virtual new double GetArea(double tolerance, ToleranceType type)
 {
   return default(double);
 }
 public bool FillContains(Geometry geometry, double tolerance, ToleranceType type)
 {
   return default(bool);
 }
 public static PathGeometry Combine(Geometry geometry1, Geometry geometry2, GeometryCombineMode mode, Transform transform, double tolerance, ToleranceType type)
 {
   return default(PathGeometry);
 }
 public bool StrokeContains(Pen pen, System.Windows.Point hitPoint, double tolerance, ToleranceType type)
 {
   return default(bool);
 }
Ejemplo n.º 28
0
 public Tolerance(ToleranceUnit unit, double experimental, double theoretical, ToleranceType type = ToleranceType.PlusAndMinus)
     : this(unit, GetTolerance(experimental, theoretical, unit), type)
 {
 }
Ejemplo n.º 29
0
 public Tolerance(ToleranceUnit unit, double value, ToleranceType type = ToleranceType.PlusAndMinus)
 {
     Unit  = unit;
     Value = value;
     Type  = type;
 }
Ejemplo n.º 30
0
 /// <summary>
 /// Gets the area of this geometry
 /// </summary>
 /// <param name="tolerance">The computational error tolerance</param>
 /// <param name="type">The way the error tolerance will be interpreted - relative or absolute</param>
 public override double GetArea(double tolerance, ToleranceType type)
 {
     return 0.0;
 }
Ejemplo n.º 31
0
        /// <summary>
        /// Returns the axis-aligned bounding rectangle when stroked with a pen, after applying
        /// the supplied transform (if non-null).
        /// </summary>
        internal override Rect GetBoundsInternal(Pen pen, Matrix worldMatrix, double tolerance, ToleranceType type)
        {
            Matrix geometryMatrix;
            
            Transform.GetTransformValue(Transform, out geometryMatrix);

            return LineGeometry.GetBoundsHelper(
                   pen,
                   worldMatrix,
                   StartPoint,
                   EndPoint,
                   geometryMatrix,
                   tolerance,
                   type);
        }
Ejemplo n.º 32
0
 /// <summary>
 /// Set the percentage error which is considered tolerable for use with <see cref="OnTarget"/>.
 /// </summary>
 /// <param name="percent">The percent tolerance.</param>
 public void SetPercentTolerance(double percent)
 {
     lock (m_lockObject)
     {
         m_toleranceType = ToleranceType.PercentTolerance;
         m_tolerance = percent;
     }
 }
Ejemplo n.º 33
0
 /// <summary>
 /// Sets the absolute error which is considered tolerable for use with <see cref="OnTarget"/>.
 /// </summary>
 /// <remarks>The value is in the same range as the PIDInput values.</remarks>
 /// <param name="absTolerance">The absolute tolerance.</param>
 public void SetAbsoluteTolerance(double absTolerance)
 {
     lock (m_lockObject)
     {
         m_toleranceType = ToleranceType.AbsoluteTolerance;
         m_tolerance = absTolerance;
     }
 }
Ejemplo n.º 34
0
        /// <summary>
        /// Creates a new PID object with the given contants for P, I, D and F.
        /// </summary>
        /// <param name="kp">The proportional coefficient.</param>
        /// <param name="ki">The integral coefficient</param>
        /// <param name="kd">The derivative coefficient</param>
        /// <param name="kf">The feed forward term.</param>
        /// <param name="source">The PIDSource object that is used to get values.</param>
        /// <param name="output">The PIDOutput object that is set to the output percentage.</param>
        /// <param name="period">The loop time for doing calculations.</param>
        public PIDController(double kp, double ki, double kd, double kf,
            IPIDSource source, IPIDOutput output,
            double period)
        {
            if (source == null)
                throw new ArgumentNullException(nameof(source), "Null PIDSource was given");
            if (output == null)
                throw new ArgumentNullException(nameof(output), "Null PIDOutput was given");

            CalculateCallback = Calculate;
            m_controlLoop = new Notifier(CalculateCallback);
            m_setpointTimer = new Timer();
            m_setpointTimer.Start();

            m_P = kp;
            m_I = ki;
            m_D = kd;
            m_F = kf;

            PIDInput = source;
            PIDOutput = output;
            m_period = period;

            m_controlLoop.StartPeriodic(m_period);

            s_instances++;
            HLUsageReporting.ReportPIDController(s_instances);

            m_toleranceType = ToleranceType.NoTolerance;
            m_buf = new Queue<double>();
        }
 public virtual new PathGeometry GetWidenedPathGeometry(Pen pen, double tolerance, ToleranceType type)
 {
   return default(PathGeometry);
 }
Ejemplo n.º 36
0
        /// <summary> 
        /// Returns the axis-aligned bounding rectangle when stroked with a pen, after applying
        /// the supplied transform (if non-null). 
        /// </summary> 
        internal override Rect GetBoundsInternal(Pen pen, Matrix matrix, double tolerance, ToleranceType type)
        { 
            Matrix geometryMatrix;

            Transform.GetTransformValue(Transform, out geometryMatrix);
 
            return EllipseGeometry.GetBoundsHelper(
                pen, 
                matrix, 
                Center,
                RadiusX, 
                RadiusY,
                geometryMatrix,
                tolerance,
                type); 
        }
 public IntersectionDetail StrokeContainsWithDetail(Pen pen, Geometry geometry, double tolerance, ToleranceType type)
 {
   return default(IntersectionDetail);
 }
Ejemplo n.º 38
0
        internal override bool ContainsInternal(Pen pen, Point hitPoint, double tolerance, ToleranceType type)
        { 
            unsafe 
            {
                Point *pPoints = stackalloc Point[(int)GetPointCount()]; 
                EllipseGeometry.GetPointList(pPoints, GetPointCount(), Center, RadiusX, RadiusY);

                fixed (byte* pTypes = GetTypeList())
                { 
                    return ContainsInternal(
                        pen, 
                        hitPoint, 
                        tolerance,
                        type, 
                        pPoints,
                        GetPointCount(),
                        pTypes,
                        GetSegmentCount()); 
                }
            } 
        } 
 public bool FillContains(System.Windows.Point hitPoint, double tolerance, ToleranceType type)
 {
   return default(bool);
 }
Ejemplo n.º 40
0
 /// <summary>Creates a new <see cref="ExitCondition"/> object.
 /// </summary>
 /// <param name="maxIterations">The maximal number of iterations.</param>
 /// <param name="maxEvaluations">The maximal number of function evaluations.</param>
 /// <param name="tolerance">The tolerance to take into account as exit condition; or <see cref="System.Double.NaN"/>.</param>
 /// <param name="toleranceType">A value indicating how to interprete <paramref name="tolerance"/>.</param>
 /// <returns>A specific <see cref="ExitCondition"/> object.</returns>
 public static ExitCondition Create(int maxIterations, int maxEvaluations = Int32.MaxValue, double tolerance = Double.NaN, ToleranceType toleranceType = ToleranceType.None)
 {
     return(new ExitCondition(maxIterations, maxEvaluations, tolerance, toleranceType));
 }
 public virtual new IntersectionDetail FillContainsWithDetail(Geometry geometry, double tolerance, ToleranceType type)
 {
   return default(IntersectionDetail);
 }
Ejemplo n.º 42
0
 /// <summary>
 /// Gets the area of this geometry
 /// </summary>
 /// <param name="tolerance">The computational error tolerance</param>
 /// <param name="type">The way the error tolerance will be interpreted - relative or absolute</param>
 public override double GetArea(double tolerance, ToleranceType type)
 {
     return(0.0);
 }
Ejemplo n.º 43
0
 public static Tolerance FromPPM(double value, ToleranceType toleranceType = ToleranceType.PlusAndMinus)
 {
     return new Tolerance(ToleranceUnit.PPM, value, toleranceType);
 }
Ejemplo n.º 44
0
        /// <summary>
        /// Returns the axis-aligned bounding rectangle when stroked with a pen, after applying
        /// the supplied transform (if non-null).
        /// </summary>
        internal override Rect GetBoundsInternal(Pen pen, Matrix worldMatrix, double tolerance, ToleranceType type)
        {
            Matrix geometryMatrix;

            Transform.GetTransformValue(Transform, out geometryMatrix);

            return(LineGeometry.GetBoundsHelper(
                       pen,
                       worldMatrix,
                       StartPoint,
                       EndPoint,
                       geometryMatrix,
                       tolerance,
                       type));
        }
Ejemplo n.º 45
0
 /// <summary>
 /// Creates a new tolerance given a unit, two points (one experimental and one theoretical), and whether the tolerance is ±
 /// </summary>
 /// <param name="unit">The units for this tolerance</param>
 /// <param name="experimental">The experimental value</param>
 /// <param name="theoretical">The theoretical value</param>
 /// <param name="type">Whether the tolerance is full or half width</param>
 public Tolerance(ToleranceUnit unit, double experimental, double theoretical, ToleranceType type = ToleranceType.PlusAndMinus)
     : this(unit, GetTolerance(experimental, theoretical, unit), type)
 {
 }
 public virtual new PathGeometry GetOutlinedPathGeometry(double tolerance, ToleranceType type)
 {
   return default(PathGeometry);
 }
Ejemplo n.º 47
0
        internal static Rect GetBoundsHelper(Pen pen, Matrix worldMatrix, Point center, double radiusX, double radiusY,
                                             Matrix geometryMatrix, double tolerance, ToleranceType type)
        {
            Rect rect;

            Debug.Assert(worldMatrix != null);
            Debug.Assert(geometryMatrix != null);

            if ((pen == null || pen.DoesNotContainGaps) &&
                worldMatrix.IsIdentity && geometryMatrix.IsIdentity)
            {
                double strokeThickness = 0.0;

                if (Pen.ContributesToBounds(pen))
                {
                    strokeThickness = Math.Abs(pen.Thickness);
                }

                rect = new Rect(
                    center.X - Math.Abs(radiusX) - 0.5 * strokeThickness,
                    center.Y - Math.Abs(radiusY) - 0.5 * strokeThickness,
                    2.0 * Math.Abs(radiusX) + strokeThickness,
                    2.0 * Math.Abs(radiusY) + strokeThickness);
            }
            else
            {
                unsafe
                {
                    Point *pPoints = stackalloc Point[(int)c_pointCount];
                    EllipseGeometry.GetPointList(pPoints, c_pointCount, center, radiusX, radiusY);

                    fixed(byte *pTypes = EllipseGeometry.s_roundedPathTypes)
                    {
                        rect = Geometry.GetBoundsHelper(
                            pen,
                            &worldMatrix,
                            pPoints,
                            pTypes,
                            c_pointCount,
                            c_segmentCount,
                            &geometryMatrix,
                            tolerance,
                            type,
                            false); // skip hollows - meaningless here, this is never a hollow
                    }
                }
            }

            return(rect);
        }
 public virtual new System.Windows.Rect GetRenderBounds(Pen pen, double tolerance, ToleranceType type)
 {
   return default(System.Windows.Rect);
 }
Ejemplo n.º 49
0
        /// <summary>
        /// Gets the bounds of this Geometry as an axis-aligned bounding box given a Pen and/or Transform
        /// </summary>
        internal override Rect GetBoundsInternal(Pen pen, Matrix matrix, double tolerance, ToleranceType type)
        { 
            if (IsObviouslyEmpty()) 
            {
                return Rect.Empty;
            }

            return GetAsPathGeometry().GetBoundsInternal(pen, matrix, tolerance, type);
        }
Ejemplo n.º 50
0
		public override double GetArea (double flatteningTolerance, ToleranceType tolerance)
		{
			throw new NotImplementedException ();
		}
Ejemplo n.º 51
0
 public static Tolerance FromMMU(double value, ToleranceType toleranceType = ToleranceType.PlusAndMinus)
 {
     return(new Tolerance(ToleranceUnit.MMU, value, toleranceType));
 }
Ejemplo n.º 52
0
        /// <summary>
        /// Returns if point is inside the filled geometry.
        /// </summary>
        internal override bool ContainsInternal(Pen pen, Point hitPoint, double tolerance, ToleranceType type)
        {
            if (pen == null)
            {
                ReadPreamble();

                // Hit the two operands
                bool hit1 = false;
                bool hit2 = false;

                Transform transform = Transform;
                if (transform != null && !transform.IsIdentity)
                {
                    // Inverse-transform the hit point
                    Matrix matrix = transform.Value;
                    if (matrix.HasInverse)
                    {
                        matrix.Invert();
                        hitPoint *= matrix;
                    }
                    else
                    {
                        // The matrix will collapse the geometry to nothing, containing nothing 
                        return false;
                    }
                }

                Geometry geometry1 = Geometry1;
                Geometry geometry2 = Geometry2;
                if (geometry1 != null)
                {
                    hit1 = geometry1.ContainsInternal(pen, hitPoint, tolerance, type);
                }
                if (geometry2 != null)
                {
                    hit2 = geometry2.ContainsInternal(pen, hitPoint, tolerance, type);
                }

                // Determine containment according to the theoretical definition
                switch (GeometryCombineMode)
                {
                    case GeometryCombineMode.Union:
                        return hit1 || hit2;

                    case GeometryCombineMode.Intersect:
                        return hit1 && hit2;

                    case GeometryCombineMode.Exclude:
                        return hit1 && !hit2;

                    case GeometryCombineMode.Xor:
                        return hit1 != hit2;
                }

                // We should have returned from one of the cases
                Debug.Assert(false);
                return false;
            }
            else
            {
                // pen != null
                return base.ContainsInternal(pen, hitPoint, tolerance, type);
            }
        }
 public override double GetArea(double tolerance, ToleranceType type)
 {
   return default(double);
 }
Ejemplo n.º 54
0
        /// <summary>
        /// Gets the area of this geometry
        /// </summary>
        /// <param name="tolerance">The computational error tolerance</param>
        /// <param name="type">The way the error tolerance will be interpreted - realtive or absolute</param>
        public override double GetArea(double tolerance, ToleranceType type)
        {
            ReadPreamble();

            // Potential speedup, to be done if proved important:  As the result of a Combine
            // operation, the result of GetAsPathGeometry() is guaranteed to be organized into
            // flattened well oriented figures.  Its area can therefore be computed much faster
            // without the heavy machinary of CArea.  This will require writing an internal 
            // CShapeBase::GetRawArea method, and a utility to invoke it.  For now:
            return GetAsPathGeometry().GetArea(tolerance, type);
        }
Ejemplo n.º 55
0
        internal static Rect GetBoundsHelper(Pen pen, Matrix worldMatrix, Point center, double radiusX, double radiusY,
                                             Matrix geometryMatrix, double tolerance, ToleranceType type) 
        {
            Rect rect; 
 
            Debug.Assert(worldMatrix != null);
            Debug.Assert(geometryMatrix != null); 

            if ( (pen == null || pen.DoesNotContainGaps) &&
                worldMatrix.IsIdentity && geometryMatrix.IsIdentity)
            { 
                double strokeThickness = 0.0;
 
                if (Pen.ContributesToBounds(pen)) 
                {
                    strokeThickness = Math.Abs(pen.Thickness); 
                }

                rect = new Rect(
                    center.X - Math.Abs(radiusX)-0.5*strokeThickness, 
                    center.Y - Math.Abs(radiusY)-0.5*strokeThickness,
                    2.0 * Math.Abs(radiusX)+strokeThickness, 
                    2.0 * Math.Abs(radiusY)+strokeThickness); 
            }
            else 
            {
                unsafe
                {
                    Point * pPoints = stackalloc Point[(int)c_pointCount]; 
                    EllipseGeometry.GetPointList(pPoints, c_pointCount, center, radiusX, radiusY);
 
                    fixed (byte *pTypes = EllipseGeometry.s_roundedPathTypes) 
                    {
                        rect = Geometry.GetBoundsHelper( 
                            pen,
                            &worldMatrix,
                            pPoints,
                            pTypes, 
                            c_pointCount,
                            c_segmentCount, 
                            &geometryMatrix, 
                            tolerance,
                            type, 
                            false); // skip hollows - meaningless here, this is never a hollow
                    }
                }
            } 

            return rect; 
        } 
Ejemplo n.º 56
0
 public virtual Rect GetRenderBounds(Pen pen, double tolerance, ToleranceType type)
 {
     return this.PlatformImpl.GetRenderBounds(pen, tolerance, type);
 }
Ejemplo n.º 57
0
        /// <summary> 
        /// Gets the area of this geometry
        /// </summary>
        /// <param name="tolerance">The computational error tolerance</param>
        /// <param name="type">The way the error tolerance will be interpreted - realtive or absolute</param> 
        public override double GetArea(double tolerance, ToleranceType type)
        { 
            ReadPreamble(); 

            double area = Math.Abs(RadiusX * RadiusY) * Math.PI; 

            // Adjust to internal transformation
            Transform transform = Transform;
            if (transform != null && !transform.IsIdentity) 
            {
                area *= Math.Abs(transform.Value.Determinant); 
            } 

            return area; 
        }
Ejemplo n.º 58
0
        internal static Rect GetBoundsHelper(Pen pen, Matrix worldMatrix, Point pt1, Point pt2,
                                             Matrix geometryMatrix, double tolerance, ToleranceType type)
        {
            Debug.Assert(worldMatrix != null);
            Debug.Assert(geometryMatrix != null);

            if (pen == null && worldMatrix.IsIdentity && geometryMatrix.IsIdentity)
            {
                return(new Rect(pt1, pt2));
            }
            else
            {
                unsafe
                {
                    Point *pPoints = stackalloc Point[2];
                    pPoints[0] = pt1;
                    pPoints[1] = pt2;

                    fixed(byte *pTypes = LineGeometry.s_lineTypes)
                    {
                        return(Geometry.GetBoundsHelper(
                                   pen,
                                   &worldMatrix,
                                   pPoints,
                                   pTypes,
                                   c_pointCount,
                                   c_segmentCount,
                                   &geometryMatrix,
                                   tolerance,
                                   type,
                                   false)); // skip hollows - meaningless here, this is never a hollow
                    }
                }
            }
        }
Ejemplo n.º 59
0
        /// <summary>Initializes a new instance of the <see cref="ExitCondition"/> class.
        /// </summary>
        /// <param name="maxIterations">The maximal number of iterations.</param>
        /// <param name="maxEvaluations">The maximal number of function evaluations.</param>
        /// <param name="tolerance">The tolerance to take into account as exit condition; or <see cref="System.Double.NaN"/>.</param>
        /// <param name="toleranceType">A value indicating how to interprete <paramref name="tolerance"/>.</param>
        protected ExitCondition(int maxIterations, int maxEvaluations = Int32.MaxValue, double tolerance = Double.NaN, ToleranceType toleranceType = ToleranceType.None)
        {
            MaxIterations  = maxIterations;
            MaxEvaluations = maxEvaluations;
            switch (toleranceType)
            {
            case ToleranceType.WithinAbsoluteTolerance:
                m_AbsoluteTolerance = tolerance;
                m_RelativeTolerance = Double.NaN;
                break;

            case ToleranceType.WithinRelativeTolerance:
                m_RelativeTolerance = tolerance;
                m_AbsoluteTolerance = Double.NaN;
                break;

            default:
                m_AbsoluteTolerance = m_RelativeTolerance = Double.NaN;
                break;
            }
        }
Ejemplo n.º 60
0
        internal override bool ContainsInternal(Pen pen, Point hitPoint, double tolerance, ToleranceType type)
        {
            unsafe
            {
                Point *pPoints = stackalloc Point[2];
                pPoints[0] = StartPoint;
                pPoints[1] = EndPoint;

                fixed(byte *pTypes = GetTypeList())
                {
                    return(ContainsInternal(
                               pen,
                               hitPoint,
                               tolerance,
                               type,
                               pPoints,
                               GetPointCount(),
                               pTypes,
                               GetSegmentCount()));
                }
            }
        }