123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144 |
- using StageController.M3H;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace StageController
- {
- internal class M3HAxis : IMotion
- {
- AxisController m_axisController;
- /// <summary>
- /// 0-999
- /// </summary>
- public int Speed { get; set; }
- public int Step { get; set; }
- /// <summary>
- /// 指令位置:用于补偿实际位置
- /// </summary>
- double Expect { get; set; }
- public double Actual
- {
- get
- {
- if (Reversed)
- return (double)(-Step * Stepping);
- return (double)(Step * Stepping);
- }
- }
- /// <summary>
- /// 0:停机自由,1:停机锁死,2:正向连续,3:反向连续,4:正向步进,5:反向步进
- /// </summary>
- public int State { get; set; }
- private Border _border;
- public int Limit
- {
- get
- {
- if (Reversed)
- {
- switch (_border)
- {
- case Border.F:
- return (int)Border.R;
- case Border.R:
- return (int)Border.F;
- }
- }
- return (int)_border;
- }
- set { _border = (Border)value; }
- }
- public M3HAxisType AxisType { get; private set; }
- /// <summary>
- /// 步距
- /// </summary>
- public double Stepping { get; set; }
- public bool Reversed { get; set; }
- public M3HAxis(M3HAxisType type, AxisController axisController)
- {
- m_axisController = axisController;
- AxisType = type;
- if (m_axisController == null)
- throw new ArgumentNullException("AxisController is Null!");
- }
- public void Move(int step, object arg = null)
- {
- if (Reversed) step = -step;
- CommandMoveByStep command = new CommandMoveByStep(AxisType, step, Speed);
- m_axisController.AddCommand(command);
- }
- public void Move(double value, object arg = null)
- {
- if (Reversed) value = -value;
- var step = GetStep(value);
- CommandMoveByStep command = new CommandMoveByStep(AxisType, step, Speed);
- m_axisController.AddCommand(command);
- }
- public void To(double value)
- {
- if (Reversed) value = -value;
- var step = GetStep(value);
- step -= Step;
- CommandMoveByStep command = new CommandMoveByStep(AxisType, step, Speed);
- m_axisController.AddCommand(command);
- }
- private int GetStep(double value)
- {
- var step = (int)(value / Stepping);
- var gap = Expect - Actual;
- if (Math.Abs(gap) > 5 * Stepping)
- {
- Expect = Actual;
- }
- else if (gap > Stepping)
- {
- step++;
- }
- else if (gap < -Stepping)
- {
- step--;
- }
- Expect += value;
- return step;
- }
- public void Stop(object arg)
- {
- HandLock handLock = (HandLock)arg;
- CommandStop command = new CommandStop(AxisType, handLock);
- m_axisController.AddCommand(command);
- }
- public void Slide(bool isPositive, object arg = null)
- {
- if (Reversed) isPositive = !isPositive;
- m_axisController.AddCommand(new CommandMoveBorder(AxisType, isPositive ? Direction.A : Direction.B, Speed));
- }
- public void ResetPosition()
- {
- m_axisController.AddCommand(new CommandResetPosition(AxisType));
- }
- }
- }
|