联营板卡 控制类实现

/// <summary>
/// 联营板卡
/// </summary>
public class UWC : AxisModel
{
    //public UWC() { }
    public UWC() { }

    public override bool Home()
    {
        double speed = Param.HomevelL;//回零低速
        int rtn = UWC7000.uwc7000_go_home(AxisNum, speed);
        WaitMoveDone();
        Thread.Sleep(200);
        IsHomed = true;
        // UWC7000.uwc7000_set_coordinate(AxisNum, 0);       // 设置机械坐标
      //  UWC7000.uwc7000_set_command_count(AxisNum, 0);    // 设置指令坐标   
        return true;
    }


    private void Home(object sender, EventArgs e)    // 回零运动
    {
        int[] status = new int[1];
        int rtn = UWC7000.uwc7000_check_axis_done(0, status);
        if (0 == status[0])
        {
            MainWindow.ShowMsg("该轴处于运动状态,回零失败!");
        }
        else
        {
            rtn = UWC7000.uwc7000_go_home(0, 10);
            if (0 != rtn)
            {
                MainWindow.ShowMsg("回零失败!");
            }
        }
    }

    /// <summary>
    /// 获取移动完成状态
    /// </summary>
    /// <returns></returns>
    public bool GetMoveDone()
    {          
        int[] status = new int[1];    // 轴状态
        int rtn = UWC7000.uwc7000_check_axis_done(AxisNum, status);
        return status[0] == 0;
    }

    /// <summary>
    /// 等待移动完成
    /// </summary>
    /// <returns>完成为true</returns>
    public override bool WaitMoveDone()
    {
        while (true)
        {
            if (GetMoveDone())
            {
                Thread.Sleep(10);
                continue;
            }
            else
            {
                return true;                  
            }
        }          
    }

    /// <summary>
    /// 根据位置名称 获取位置 点位值
    /// </summary>
    /// <param name="axisPosType">位置名称</param>
    /// <returns>点位值</returns>
    public override double GetAxisPosList(string axisPosType)
    {
        double position = 0;
        if (PosList != null && PosList.Count > 0)
        {
            var posObj = PosList.FirstOrDefault(t => t.Name.Equals(axisPosType));
            if (posObj != null)
            {
                position = posObj.Position;
            }
        }
        return position;
    }

    /// <summary>
    /// 绝对运动
    /// </summary>
    /// <param name="pos">运动位置</param>
    /// <returns></returns>
    public override bool MoveAbs(double pos)
    {
        try
        {               
            double speed = Param.Vel_Run;
            if (speed > 5) speed = 5;
            UWC7000.uwc7000_single_move_to(AxisNum, speed, pos);
            return true;
        }
        catch (Exception)
        {
            return false;
        }
    }

    /// <summary>
    /// 获取当前坐标
    /// </summary>
    /// <returns></returns>
    public override double GetCurPos()
    {
        double[] position = new double[64];
        double curPos = 0; 
        int rtn = UWC7000.uwc7000_get_coordinate(position); // 机械坐标
        if (0 == rtn)
        {
            curPos = position[AxisNum];
        }
        return curPos;
    }

    /// <summary>
    /// 点动
    /// </summary>
    /// <param name="pos"></param>
    /// <returns></returns>
    public override bool MoveInc(double pos)
    {
        double dis = GetCurPos()+pos;
        double speed = Param.Vel_Run;
        UWC7000.uwc7000_single_move_to(AxisNum, speed, dis);
        return true;
    }

    /// <summary>
    /// 移动到指定位置
    /// </summary>
    /// <param name="posname">位置名称</param>
    /// <returns></returns>
    public override bool MoveAbs(string posname)
    {
        try
        {
            double dis = (double)(GetAxisPosList(posname));
            double speed = Param.Vel_Run;
            //单轴点位运动命令,使指定轴按照指定的速度移动到指定位置。
            //speed:此次点位运动速度
            //target_pos:此次点位运动的目标位置
            UWC7000.uwc7000_single_move_to(AxisNum, speed, dis);
            return true;
        }
        catch (Exception)
        {
            return false;
        }
    }

    public override bool Jog( double speed)
    {
        try
        {
            UWC7000.uwc7000_jog_move(AxisNum, speed);
            return true;
        }
        catch (Exception)
        {
            return false;
        }
    }

    /// <summary>
    /// 减速停止
    /// </summary>
    /// <returns></returns>
    public override bool Stop()
    {
        return UWC7000.uwc7000_stop(AxisNum ,0)== 0; //减速停止
    }

    /// <summary>
    /// 复位
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    private void BTnReset_Click(object sender, EventArgs e)//复位
    {
        int rtn =UWC7000.uwc7000_clean_buf(0);
        if (0 != rtn)
        {
            MainWindow.ShowMsg("清空缓存区失败!");
        }
    }

    /// <summary>
    /// 坐标清零
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    private void btnClear_Click(object sender, EventArgs e) // 坐标清零
    {
        int rtn = 0;
        rtn = UWC7000.uwc7000_set_coordinate(0, 0);       // 设置机械坐标
        rtn = UWC7000.uwc7000_set_command_count(0, 0);    // 设置指令坐标   
        if (0 != rtn)
        {
            MainWindow.ShowMsg("坐标清零失败!");
        }
    }
}

 

posted @ 2023-09-10 18:06  baivfhpwxf  阅读(22)  评论(0编辑  收藏  举报