示例#1
0
        /// <summary>
        /// 点-点运动  等待停止
        /// </summary>
        /// <param name="timeout"></param>
        /// <param name="pos"></param>
        /// <param name="speed"></param>
        /// <returns></returns>
        public short GoPosTillStop(int timeout, double pos, HostarSpeed speed)
        {
            if (double.IsNaN(pos) || double.IsInfinity(pos))
            {
                return(-1);
            }

            Stopwatch a   = new Stopwatch();
            short     rtn = 0;
            var       sd  = speed.GetActSpeed(this.AxisRatio);

            this.AxisMoveTrap_Abs(pos * this.AxisRatio, sd.StartSpeed, sd.MaxSpeed, sd.AccTime, sd.DecTime);
            a.Start();

            while (!this.AxisReach(pos))
            {
                Thread.Sleep(1);

                if (a.ElapsedMilliseconds > timeout || MotionHelper.Instance.Emg)
                {
                    this.StopAxis();
                    this.ClearAxisSts();
                    return(-1);
                }
            }

            return(rtn);
        }
示例#2
0
        /// <summary>
        /// 定长运动
        /// </summary>
        /// <param name="TrimDist">定长</param>
        /// <param name="speed">速度</param>
        /// <returns></returns>
        public short MoveTrim(double TrimDist, HostarSpeed speed)
        {
            if (double.IsNaN(TrimDist) || double.IsInfinity(TrimDist))
            {
                return(-1);
            }

            this.GetAxisPos();
            return(this.GoPos(this.Pos + TrimDist, speed));
        }
        /// <summary>
        /// 根据脉冲比得到实际速度
        /// </summary>
        /// <param name="axisRatio"></param>
        /// <returns></returns>
        public HostarSpeed GetActSpeed(double axisRatio)
        {
            HostarSpeed speed = new HostarSpeed();

            speed.StartSpeed = this.StartSpeed * axisRatio;
            speed.MaxSpeed   = this.MaxSpeed * axisRatio;
            speed.AccTime    = (this.MaxSpeed * 1000 / this.AccTime) * axisRatio;
            speed.DecTime    = (this.MaxSpeed * 1000 / this.DecTime) * axisRatio;
            return(speed);
        }
        public object Clone()
        {
            HostarSpeed speed = new HostarSpeed();

            speed.StartSpeed = this.StartSpeed;
            speed.MaxSpeed   = this.MaxSpeed;
            speed.AccTime    = this.AccTime;
            speed.DecTime    = this.DecTime;
            return(speed);
        }
示例#5
0
        /// <summary>
        /// 点-点运动
        /// </summary>
        /// <param name="pos">位置</param>
        /// <param name="speed">速度</param>
        /// <returns></returns>
        public short GoPos(double pos, HostarSpeed speed)
        {
            if (double.IsNaN(pos) || double.IsInfinity(pos))
            {
                return(-1);
            }

            var sd = speed.GetActSpeed(this.AxisRatio);

            return(this.AxisMoveTrap_Abs(pos * this.AxisRatio, sd.StartSpeed, sd.MaxSpeed, sd.AccTime, sd.DecTime));
        }
示例#6
0
        /// <summary>
        /// 使用极限回原点的方式
        /// </summary>
        /// <param name="homeMode"></param>
        /// <param name="direction"></param>
        /// <param name="speed"></param>
        /// <returns></returns>
        public short GoHome(int timeout, HostarSpeed goLimit, HostarSpeed goHome, bool limit = true)
        {
            if (limit)
            {
                return(this.GoHomeWithLimit(timeout, this.HomeMode, this.HomeDirection, goLimit, goHome));
            }
            else
            {
                #region 开始回原点
                Stopwatch stopwatch = new Stopwatch();
                stopwatch.Start();
                var   homeSpeed = goHome.GetActSpeed(this.AxisRatio);
                short rtn       = this.AxisGoHome(this.HomeMode, this.HomeDirection, homeSpeed.StartSpeed, homeSpeed.MaxSpeed, homeSpeed.AccTime, homeSpeed.DecTime);
                Thread.Sleep(200);
                this.GetAxisSts();

                while (this.bAxisIsHoming || this.bAxisIsRunning)
                {
                    Thread.Sleep(1);
                    this.GetAxisSts();
                    if (stopwatch.ElapsedMilliseconds > timeout || MotionHelper.Instance.Emg)
                    {
                        stopwatch.Stop();
                        this.StopAxis();
                        this.ClearAxisSts();
                        return(-1);
                    }
                }

                this.StopAxis();
                this.ClearAxisSts();
                this.ZeroAxis();
                stopwatch.Stop();
                return(rtn);

                #endregion
            }
        }
示例#7
0
        /// <summary>
        /// Jog 运动
        /// </summary>
        /// <param name="speed">速度</param>
        /// <param name="dirct">方向</param>
        /// <returns></returns>
        public short Jog(HostarSpeed speed, bool dirct)
        {
            var newSpeed = speed.GetActSpeed(this.AxisRatio);

            return(this.AxisMoveJog(newSpeed.StartSpeed, newSpeed.MaxSpeed, newSpeed.AccTime, newSpeed.DecTime, dirct));
        }
示例#8
0
 public short GoHome(int timeout, HostarSpeed goLimit, HostarSpeed goHome, IOInput limit, bool Wait = true)
 {
     return(this.GoHomeWithInput(timeout, this.HomeMode, this.HomeDirection, goLimit, goHome, limit));
 }
示例#9
0
        private short GoHomeWithInput(int timeout, HomeMode homeMode, bool direction, HostarSpeed goLimit, HostarSpeed goHome, IOInput limit)
        {
            short     rtn       = 0;
            Stopwatch stopwatch = new Stopwatch();

            stopwatch.Start();
            this.StopAxis();
            this.GetAxisSts();

            #region 到轴的极限位置
            if (!limit.GetIO())
            {
                rtn = this.Jog(goLimit, !direction); // 到极限
                while (!limit.GetIO())
                {
                    Thread.Sleep(1);
                    this.GetAxisSts();
                    if (stopwatch.ElapsedMilliseconds > timeout || MotionHelper.Instance.Emg)
                    {
                        stopwatch.Stop();
                        this.StopAxis();
                        this.ClearAxisSts();
                        return(-1);
                    }
                }
            }

            this.StopAxis();
            #endregion
            Thread.Sleep(200);

            #region 开始回原点
            stopwatch.Reset();
            stopwatch.Start();
            var homeSpeed = goHome.GetActSpeed(this.AxisRatio);
            rtn += this.AxisGoHome(homeMode, direction, homeSpeed.StartSpeed, homeSpeed.MaxSpeed, homeSpeed.AccTime, homeSpeed.DecTime);
            Thread.Sleep(200);
            this.GetAxisSts();

            while (this.bAxisIsHoming || this.bAxisIsRunning)
            {
                Thread.Sleep(1);
                this.GetAxisSts();
                if (stopwatch.ElapsedMilliseconds > timeout || MotionHelper.Instance.Emg)
                {
                    stopwatch.Stop();
                    this.StopAxis();
                    this.ClearAxisSts();
                    return(-1);
                }
            }

            this.StopAxis();
            this.ClearAxisSts();
            this.ZeroAxis();
            stopwatch.Stop();
            return(rtn);

            #endregion
        }