예제 #1
0
        public virtual void SetTarget(ActuatorPosition targetPos, double targetPositionInPercent, bool reset = false)
        {
            if (privateState.TargetPos != targetPos || privateState.TargetPositionInPercent != targetPositionInPercent || reset)
            {
                ActuatorPosition entryTargetPos = privateState.TargetPos;
                double           entryTargetPositionInPercent = privateState.TargetPositionInPercent;

                privateState.TargetPos               = targetPos;
                privateState.TargetPosStr            = Config.ToString(targetPos);
                privateState.TargetPositionInPercent = targetPositionInPercent;

                string resetStr = (reset ? " Reset" : string.Empty);

                if (entryTargetPos != targetPos || reset)
                {
                    logger.Debug.Emit("Target position changed to:{0} [{1} {2:f1}%{3}]", privateState.TargetPosStr, privateState.TargetPos, privateState.TargetPositionInPercent, resetStr);
                }
                else if (Math.Abs(targetPositionInPercent - entryTargetPositionInPercent) > 5.0)
                {
                    logger.Debug.Emit("Target position in percent changed to: {0:f1}% [{0} {1}]", privateState.TargetPositionInPercent, privateState.TargetPosStr, privateState.TargetPos);
                }
                else
                {
                    logger.Trace.Emit("Target position in percent changed to: {0:f3}% [{0} {1}]", privateState.TargetPositionInPercent, privateState.TargetPosStr, privateState.TargetPos);
                }

                Service(TimeSpan.Zero, forcePublish: true, reset: reset);
            }
        }
예제 #2
0
 public ActuatorConfig(string pos1Name, string pos2Name, TimeSpan motion1To2Time, TimeSpan motion2To1Time, ActuatorPosition initialPos = ActuatorPosition.AtPos1)
 {
     Pos1Name       = pos1Name;
     Pos2Name       = pos2Name;
     Motion1To2Time = motion1To2Time;
     Motion2To1Time = motion2To1Time;
     InitialPos     = initialPos;
 }
예제 #3
0
        /// <summary>
        /// Method is used to help convert ActuatorPosition values into a target position in percentage
        /// </summary>
        public static double GetTargetPositionInPercent(this ActuatorPosition targetPos, bool mapInBetweenToHalfWay = false, double currentPositionInPercent = 0.0)
        {
            switch (targetPos)
            {
            case ActuatorPosition.MoveToPos1: return(0.0);

            case ActuatorPosition.MoveToPos2: return(100.0);

            case ActuatorPosition.InBetween: return(mapInBetweenToHalfWay ? 50.0 : currentPositionInPercent);

            default: return(currentPositionInPercent);
            }
        }
예제 #4
0
 /// <summary>
 /// Helper EM to generate an ActuatorPosition given atPos1 and atPos2 booleans.
 /// Returns AtPos1 (1,0), AtPos2 (0,1), InBetween (0,0) or Fault (1,1) based on the given values of atPos1 and atPos2
 /// </summary>
 public static ActuatorPosition SetFrom(this ActuatorPosition ignoredValue, bool atPos1, bool atPos2)
 {
     if (atPos1 && !atPos2)
     {
         return(ActuatorPosition.AtPos1);
     }
     else if (!atPos1 && atPos2)
     {
         return(ActuatorPosition.AtPos2);
     }
     else if (!atPos1 && !atPos2)
     {
         return(ActuatorPosition.InBetween);
     }
     else
     {
         return(ActuatorPosition.Fault);
     }
 }
예제 #5
0
        public virtual string ToString(ActuatorPosition pos)
        {
            switch (pos)
            {
            case ActuatorPosition.AtPos1: return(Pos1Name);

            case ActuatorPosition.AtPos2: return(Pos2Name);

            case ActuatorPosition.MovingToPos1: return("MovingTo" + Pos1Name);

            case ActuatorPosition.MovingToPos2: return("MovingTo" + Pos2Name);

            case ActuatorPosition.Undefined:
            case ActuatorPosition.None:
            case ActuatorPosition.InBetween:
            case ActuatorPosition.Fault:
            default:
                return(pos.ToString());
            }
        }
예제 #6
0
        public void SetTarget(ActuatorPosition targetPos, bool reset)
        {
            if (PrivateState.TargetPos != targetPos || reset)
            {
                PrivateState.TargetPos = targetPos;
                PrivateState.TargetPosStr = Config.ToString(targetPos);

                logger.Info.Emit("Target position changed to:{0} [{1}]", PrivateState.TargetPosStr, PrivateState.TargetPos);

                Service(true, QpcTimeStamp.Now, reset);
            }
        }
예제 #7
0
 public double GetTargetPositionInPercent(ActuatorPosition targetPos, bool mapInBetweenToHalfWay = false)
 {
     return(targetPos.GetTargetPositionInPercent(mapInBetweenToHalfWay: mapInBetweenToHalfWay, currentPositionInPercent: privateState.PositionInPercent));
 }
예제 #8
0
 public void SetTarget(ActuatorPosition targetPos, bool reset = false)
 {
     SetTarget(targetPos, GetTargetPositionInPercent(targetPos), reset: reset);
 }
예제 #9
0
        /// <summary>
        /// Basic service method.
        /// Advance any active motion and performs state changes based on configured behavior,
        /// most recent setpoint value and given value of measured elapsed time (dt).
        /// publishes the resulting state if any change was made or if forcePublish is true.
        /// <para/>The use of the optional reset parameter will force the actuator state directly to the target position/state.
        /// </summary>
        public virtual void Service(TimeSpan dt, bool forcePublish = false, bool reset = false)
        {
            // first update the positionInPercent

            double           nextPositionInPercent = privateState.PositionInPercent;
            ActuatorPosition nextPosState          = ActuatorPosition.None;

            if (!reset)
            {
                slewRateLimitTool.TargetValue = privateState.TargetPositionInPercent;

                bool moving = (slewRateLimitTool.Service(dt) > 0);

                nextPositionInPercent = slewRateLimitTool.Value;

                if (moving && nextPositionInPercent < privateState.TargetPositionInPercent)
                {
                    nextPosState = ActuatorPosition.MovingToPos2;
                }
                else if (moving && nextPositionInPercent > privateState.TargetPositionInPercent)
                {
                    nextPosState = ActuatorPosition.MovingToPos1;
                }
                else if (privateState.PositionInPercent <= 0.0)
                {
                    nextPosState = ActuatorPosition.AtPos1;
                }
                else if (privateState.PositionInPercent >= 100.0)
                {
                    nextPosState = ActuatorPosition.AtPos2;
                }
                else
                {
                    nextPosState = ActuatorPosition.InBetween;
                }
            }
            else
            {
                nextPositionInPercent = privateState.TargetPositionInPercent;

                slewRateLimitTool.Reset(nextPositionInPercent);

                nextPosState = ActuatorPosition.InBetween;
            }

            if (reset || (privateState.PosState != nextPosState && nextPosState != ActuatorPosition.None))
            {
                string entryStateStr = privateState.PosStateStr;

                privateState.PosState          = nextPosState;
                privateState.PosStateStr       = Config.ToString(nextPosState);
                privateState.PositionInPercent = nextPositionInPercent;

                string resetStr = (reset ? " [Reset]" : string.Empty);

                logger.Debug.Emit("State changed to {0} [{1} {2:f0}%] from {3}, target:{4}{5}", privateState.PosStateStr, privateState.PosState, privateState.PositionInPercent, entryStateStr, privateState.TargetPosStr, resetStr);

                forcePublish = true;
            }
            else if (privateState.PositionInPercent != nextPositionInPercent)
            {
                privateState.PositionInPercent = nextPositionInPercent;

                logger.Trace.Emit("Moving {0} [{1} {2:f0}%]", privateState.PosStateStr, privateState.PosState, privateState.PositionInPercent);

                forcePublish = true;
            }

            if (forcePublish || reset)
            {
                PublishState();
            }
        }
예제 #10
0
 public virtual string ToString(ActuatorPosition pos)
 {
     switch (pos)
     {
         case ActuatorPosition.AtPos1: return Pos1Name;
         case ActuatorPosition.AtPos2: return Pos2Name;
         case ActuatorPosition.MovingToPos1: return "MovingTo" + Pos1Name;
         case ActuatorPosition.MovingToPos2: return "MovingTo" + Pos2Name;
         case ActuatorPosition.Undefined:
         case ActuatorPosition.None:
         case ActuatorPosition.Inbetween:
         case ActuatorPosition.Fault:
         default:
             return pos.ToString();
     }
 }
예제 #11
0
 public ActuatorConfig(string name, string pos1Name, string pos2Name, TimeSpan motionTime, ActuatorPosition initialPos)
     : this(name, pos1Name, pos2Name, motionTime, motionTime, initialPos)
 {
 }
예제 #12
0
 /// <summary>Returns true if the given pos is AtPos2</summary>
 public static bool IsAtPos2(this ActuatorPosition pos)
 {
     return(pos == ActuatorPosition.AtPos2);
 }
예제 #13
0
 public void SetTarget(ActuatorPosition targetPos)
 {
     SetTarget(targetPos, false);
 }
예제 #14
0
 /// <summary>Returns true if the given pos is AtPos1, AtPos2, MovingToPos1, MovingToPos2, or Inbetween</summary>
 public static bool IsValid(this ActuatorPosition pos)
 {
     return(pos.IsAtPos1() || pos.IsAtPos2() || pos.IsInBetween() || pos.IsInMotion());
 }
예제 #15
0
        /// <summary>
        /// If the currentPos matches the AtPos2 then this method sets currentPos to MovingToPos1, otherwise currentPos is not changed.
        /// </summary>
        public static ActuatorPosition StartMotionFromPos2ToPos1(this ActuatorPosition currentPos)
        {
            ActuatorPosition nextPos = (currentPos.IsAtPos2() ? ActuatorPosition.MovingToPos1 : currentPos);

            return(nextPos);
        }
예제 #16
0
 /// <summary>Returns true if the given targetPos is MoveToPos1 (AtPos1), MoveToPos2 (AtPos2), or None.  May optionally permit InBetween</summary>
 public static bool IsTargetPositionValid(this ActuatorPosition targetPos, bool allowInBetween = false)
 {
     return(targetPos == ActuatorPosition.MoveToPos1 || targetPos == ActuatorPosition.MoveToPos2 || targetPos == ActuatorPosition.None || (allowInBetween && targetPos == ActuatorPosition.InBetween));
 }
예제 #17
0
 /// <summary>Returns true if the given pos is MovingToPos1 or MovingToPos2</summary>
 public static bool IsInMotion(this ActuatorPosition pos)
 {
     return(pos == ActuatorPosition.MovingToPos1 || pos == ActuatorPosition.MovingToPos2);
 }
예제 #18
0
 public static bool IsTargetPositionValid(ActuatorPosition pos)
 {
     return pos.IsTargetPositionValid();
 }
예제 #19
0
 public void ResetStateTo(ActuatorPosition position)
 {
     SetTarget(position, reset: true);
 }
예제 #20
0
 public ActuatorConfig(string pos1Name, string pos2Name, TimeSpan motionTime, ActuatorPosition initialPos = ActuatorPosition.AtPos1)
     : this(pos1Name, pos2Name, motionTime, motionTime, initialPos)
 {
 }
예제 #21
0
 /// <summary>Returns true if the given pos is None</summary>
 public static bool IsNone(this ActuatorPosition pos)
 {
     return(pos == ActuatorPosition.None);
 }
예제 #22
0
 public ActuatorConfig(string name, string pos1Name, string pos2Name, TimeSpan motion1To2Time, TimeSpan motion2To1Time, ActuatorPosition initialPos)
 {
     Name = name;
     Pos1Name = pos1Name;
     Pos2Name = pos2Name;
     Motion1To2Time = motion1To2Time;
     Motion2To1Time = motion2To1Time;
     InitialPos = initialPos;
 }
예제 #23
0
 /// <summary>Returns true if the given pos is AtPos2</summary>
 public static bool IsInBetween(this ActuatorPosition pos)
 {
     return(pos == ActuatorPosition.InBetween);
 }
예제 #24
0
 public void ResetStateTo(ActuatorPosition position)
 {
     SetTarget(position, true);
 }