柳絮飞花
无产工程师
级别: 论坛先锋
精华主题: 0
发帖数量: 501 个
工控威望: 1212 点
下载积分: 7855 分
在线时间: 102(小时)
注册时间: 2017-06-27
最后登录: 2024-10-22
查看柳絮飞花的 主题 / 回贴
楼主  发表于: 2020-08-17 14:00
(*****************************************************************************
<FB NAME>       MC_Power_JEC                                                                        
<Description>   運転可 / Operation possible                                                                                        
                                                                                                                          
COPYRIGHT (C) 2016 MITSUBISHI ELECTRIC CORPORATION ALL RIGHT RESERVED  
*****************************************************************************)

PLS(Enable, bEnablePls);
PLF(Enable, bEnablePlf);
(*========================================================================*
* 有効ON
* Enable ON
*========================================================================*)
IF Enable THEN
    (*------------------------------------------------------------------*
    * 初期化処理
    * Initial processing
    *------------------------------------------------------------------*)
    IF bEnablePls THEN
        Status := FALSE;
        Error := FALSE;
        ErrorID := 0;
        
        bBusy := FALSE;
        bLinkReady := FALSE;
        wAxisStatus := 0;
        
        (* 入力ラベル取込 / Input labels transfer *)
        wAxisNo := Axis.AxisNo;
        MOV(((wAxisNo < 1) OR (16 < wAxisNo)), H1100, ErrorID);
        wPosTrqLimit := REAL_TO_INT(Axis.PosTrqLimit *10.0);
        MOV((ErrorID = 0) AND ((wPosTrqLimit < 0) OR (10000 < wPosTrqLimit)), H110E, ErrorID);
        wNegTrqLimit := REAL_TO_INT(Axis.NegTrqLimit *10.0);            
        MOV((ErrorID = 0) AND ((wNegTrqLimit < 0) OR (10000 < wNegTrqLimit)), H110E, ErrorID);
        
        (* リンクデバイスのオフセット計算 / Link device offset calculation *)
        IF (ErrorID = 0) THEN
            wRX3F  := ((wAxisNo - 1) * 64) + H003F;    (* サイクリック通信準備完了 / Cyclic communication ready command *)
            wRWw01 := ((wAxisNo - 1) * 32) + H0001;    (* 制御指令 / Control command *)
            wRWw14 := ((wAxisNo - 1) * 32) + H0014;    (* トルク制限値(正) / Torque limit value(positive) *)
            wRWw15 := ((wAxisNo - 1) * 32) + H0015;    (* トルク制限値(逆) / Torque limit value(negative) *)
            wRWr00 := ((wAxisNo - 1) * 32) + H0000;    (* 制御モード表示 / Control mode display *)
            wRWr02 := ((wAxisNo - 1) * 32) + H0002;    (* 制御ステータス / Control status *)
            wRWr0B := ((wAxisNo - 1) * 32) + H000B;    (* 制御出力2 / Control output 2 *)
            bBusy := TRUE;
        END_IF;
    END_IF;
    
    (*------------------------------------------------------------------*
    * 軸状態取得 & 実行条件確認
    * Axis status acquisition & execution condition check
    *------------------------------------------------------------------*)    
    IF bBusy THEN
        (* サイクリック通信状態確認 / Cyclic communication status check *)
        bLinkReady := G_stLinkBasic.bnRX[wRX3F];
        IF bLinkReady THEN
            uModeDisp := G_stLinkBasic.unRWr[wRWr00];
            bZeroVelocity:= ((G_stLinkBasic.unRWr[wRWr0B] AND H0008) = H0008);
            (* 軸状態取得 / Axis status acquisition *)
            IF ((G_stLinkBasic.unRWr[wRWr02] AND H0008) = H0008) THEN
                wAxisStatus := 1;        (* Errorstop *)
                ErrorID := H1202;    
                ELSIF ((G_stLinkBasic.unRWw[wRWw01] AND H0086) = H0002) THEN
                wAxisStatus := 2;        (* Stopping *)
                ELSIF (((G_stLinkBasic.unRWr[wRWr02] AND H000F) = H0000) OR
                ((G_stLinkBasic.unRWr[wRWr02] AND H000F) = H0001) OR
                ((G_stLinkBasic.unRWr[wRWr02] AND H000F) = H0003)) THEN
                wAxisStatus := 0;        (* Disabled *)
                ELSE
                wAxisStatus := 4;        (* Standstill *)
                IF ((G_stLinkBasic.unRWw[wRWw01] AND H0100)= H0100) THEN
                    CASE WORD_TO_INT(uModeDisp) OF
                        1,    (* Profile position mode *)
                        6:    (* Homing mode *)
                        IF ((G_stLinkBasic.unRWr[wRWr02] AND H0400) = H0000) THEN
                            wAxisStatus := 5;    (* DiscreteMotion *)        
                        END_IF;
                        3,    (* Profile Velocity mode *)
                        4:    (* Profile Torque mode *)
                        IF NOT bZeroVelocity THEN
                            wAxisStatus := 5;    (* DiscreteMotion *)        
                        END_IF;
                        ELSE
                        ;
                    END_CASE;                                
                    ELSE
                    CASE (WORD_TO_INT(uModeDisp)) OF
                        1:
                        IF ((G_stLinkBasic.unRWr[wRWr02] AND H0400) = H0000) THEN
                            wAxisStatus := 5;    (* DiscreteMotion *)
                        END_IF;
                        3,
                        4:
                        wAxisStatus := 6;    (* ContinuousMotion *)
                        6:
                        IF ((G_stLinkBasic.unRWr[wRWr02] AND H0400) = H0000) THEN
                            wAxisStatus := 3;    (* Homing *)
                        END_IF;
                        ELSE
                        ;
                    END_CASE;
                END_IF;        
            END_IF;
              
            (* 実行条件確認 / execution condition check *)
            IF bEnablePls THEN
                CASE wAxisStatus OF
                    2:    (* Stopping *)
                    ErrorID := H1204;
                    ELSE
                    ;    
                END_CASE;
            END_IF;

            (*------------------------------------------------------------------*
            * サーボON実行
            * Servo ON execution
            *------------------------------------------------------------------*)    
            IF (ErrorID =0) AND bEnablePls AND (wAxisStatus = 0) THEN
                G_stLinkBasic.unRWw[wRWw14] := INT_TO_WORD(wPosTrqLimit);    (* トルク制限値(正) / Torque limit value(positive) *)
                G_stLinkBasic.unRWw[wRWw15] := INT_TO_WORD(wNegTrqLimit);    (* トルク制限値(逆) / Torque limit value(negative) *)
                G_stLinkBasic.unRWw[wRWw01] := (G_stLinkBasic.unRWw[wRWw01] AND HFF70) OR H000F;
            END_IF;        
            IF ((G_stLinkBasic.unRWr[wRWr02] AND H006F) = H0027) THEN    (* OperationEnabled *)
                Status := TRUE;
                Error := FALSE;
                ErrorID := 0;
                ELSE
                Status := FALSE;        
            END_IF;
            ELSE
            wAxisStatus := 1;
            ErrorID := H1202;
        END_IF;
    END_IF;
    (*========================================================================*
    * エラー出力
    * Output for [Error]
    *========================================================================*)
    IF (ErrorID <> 0) THEN
        Error := TRUE;
        Status := FALSE;
        bBusy := FALSE;
    END_IF;


    (*========================================================================*
    * 有効OFF
    * Enable OFF
    *========================================================================*)    
    ELSE
    IF bEnablePlf THEN
        G_stLinkBasic.unRWw[wRWw01] := (G_stLinkBasic.unRWw[wRWw01] AND HFF70);    (* DisableOperation *)
    END_IF;
    Status := FALSE;
    Error := FALSE;
END_IF;
工控普通人,学习在路上
和谐共赢
努力学习,做好工控
级别: 网络英雄

精华主题: 0
发帖数量: 1991 个
工控威望: 7813 点
下载积分: 63496 分
在线时间: 735(小时)
注册时间: 2008-01-07
最后登录: 2024-11-21
查看和谐共赢的 主题 / 回贴
1楼  发表于: 2020-08-17 19:09
看不懂,太深奥
yyande
级别: 探索解密
精华主题: 0
发帖数量: 61 个
工控威望: 132 点
下载积分: 2687 分
在线时间: 25(小时)
注册时间: 2020-05-23
最后登录: 2024-11-18
查看yyande的 主题 / 回贴
2楼  发表于: 2020-08-17 20:39
写的牛!没有控制的硬件驱动器手册,就不知道他为什么这么干   
焦刘吉
紧跟时代发展,努力做好时代青年
级别: 工控侠客
精华主题: 0
发帖数量: 1460 个
工控威望: 4682 点
下载积分: 14955 分
在线时间: 429(小时)
注册时间: 2015-05-19
最后登录: 2024-11-14
查看焦刘吉的 主题 / 回贴
3楼  发表于: 2020-08-20 21:00
来个Case语句,不如来个枚举,又能当注释,还能随意添加
Rules are always made by the strong, and history is always written by the winners.