关于simotion建立同步/解除同步的问题

关于simotion建立同步/解除同步的问题。
问题:
【enable gearing】【disable gearing】【enable camming】【disable camming】都是一个过程,需要通过逻辑来保证该指令【能够执行一次,且仅执行一次】。

方法1)如果同步命令在background/IPO中执行,使用上升沿来保证“只执行一次”

方法2)建立【gearoff-running】【gearon-running】变量,在指令执行时置1,同步建立/解除后置0

可以参考我写的relative gear里面的时序。我的这个程序里面,方法1和方法2都用了。自己写程序可以只用其中一种方法。

    FUNCTION_BLOCK FB_RelativeGear
    //--------------------------------------------------------------------------
    // SFAE / Beijing, China
    //--------------------------------------------------------------------------
    //functionality:    two axis relative sync 
    //assignment:       Ipo task / background
    //--------------------------------------------------------------------------
    //change log table:
    //version   date        expert in charge    changes applied
    //01.00.00  24.10.2016  Zheng lei           Created
    //01.01.00  29.06.2018  Zheng lei           fix 'GearOffRunning' signal bug
    //01.01.01  28.11.2018  Zheng lei           1)reset 'GearOnRunning''GearOffRunning' signal when command change
    //                                          2)change gearRatio on-the-fly
    //==========================================================================
        
        VAR_INPUT
            TO_master       :PosAxis := TO#nil;
            TO_slave        :FollowingAxis;
            TO_slaveSync    :FollowingObjectType := TO#nil;
            GearOn          :BOOL:= FALSE;
            GearRatio       :LREAL:= 1.0;
            Acc             :LREAL:= 50.0;
            //superImpose(options)
            SPos_Length      :LREAL:= 1.0;
            SPos_Spd         :LREAL:= 2.0;
            SPos_Positive    :BOOL:= FALSE;
            SPos_Negative    :BOOL:= FALSE;
        END_VAR
        
        VAR_OUTPUT
            gearOnOK    :BOOL;
        END_VAR
        
        
        VAR
            myRetDINT       :DINT;
            rtrig_gearOn    :R_TRIG;
            ftrig_gearOff   :F_TRIG;
            GearOnRunning   :BOOL;
            GearOffRunning  :BOOL;
            GearRatioChanged :BOOL;
            oldGearRatio   :LREAL;
            PosP_Trig       :R_TRIG;
            PosN_Trig       :R_TRIG;
        END_VAR
        
        rtrig_gearOn(GearOn);//rtrig
        ftrig_gearOff(GearOn);//ftrig
        
        IF rtrig_gearOn.q OR ftrig_gearOff.q THEN
            GearOnRunning   := FALSE;
            GearOffRunning  := FALSE;
        END_IF;
        
        GearRatioChanged := (GearRatio <> oldGearRatio);
        oldGearRatio := GearRatio;
        
        //gear on 
        IF (rtrig_gearOn.q OR GearRatioChanged) 
        AND TO_slave.control = active 
        AND (TO_slave.syncMonitoring.syncState <> Yes OR GearRatioChanged) 
        AND (TO_slave.motionStateData.motionState = STANDSTILL OR GearRatioChanged)
        AND TO_master <> TO#nil
        AND TO_slave <> TO#nil
        AND TO_slaveSync <> TO#nil
        AND NOT GearOnRunning          
        THEN
            myRetDINT := _setMaster(                                //set master
                                followingObject := TO_slaveSync
                                ,master := TO_master
                                ,transientBehavior := DIRECT
                                ,nextCommand := IMMEDIATELY
                                );
                            
            myRetDINT := _enableGearing(
                                followingObject := TO_slaveSync
                                ,direction := BY_VALUE 
                                ,gearingType := RELATIVE 
                                ,gearingMode := GEARING_WITH_RATIO
                                ,gearingRatioType := DIRECT  
                                ,gearingRatio := GearRatio
                                ,synchronizingMode := IMMEDIATELY 
                                ,syncProfileReference := RELATE_SYNC_PROFILE_TO_TIME 
                                ,positiveAccelType := DIRECT
                                ,positiveAccel := Acc
                                ,negativeAccelType := DIRECT
                                ,negativeAccel := Acc
                                ,velocityProfile := TRAPEZOIDAL
                                ,mergeMode := IMMEDIATELY 
                                ,nextCommand := IMMEDIATELY
                                ,synchronizingDirection := SHORTEST_WAY 
                                );
            GearOnRunning := TRUE;
        END_IF;
            
        IF TO_slave.syncMonitoring.syncState = Yes 
            OR NOT GearOn OR TO_slave.control = INACTIVE 
        THEN //gear on finish
            GearOnRunning := FALSE;
        END_IF;
            
        //gear off
        IF TO_slave.control = active 
            AND ftrig_gearOff.q 
            AND TO_slave.syncMonitoring.syncState = Yes 
            AND NOT GearOffRunning
            AND TO_slaveSync <> TO#nil
        THEN
            GearOffRunning := TRUE;
            myRetDINT := _disableGearing(
                                followingObject := TO_slaveSync
                                ,syncOffMode := IMMEDIATELY 
                                ,syncProfileReference := RELATE_SYNC_PROFILE_TO_TIME
                                ,positiveAccelType := DIRECT
                                ,positiveAccel := Acc
                                ,negativeAccelType := DIRECT
                                ,negativeAccel := Acc
                                ,velocityProfile := TRAPEZOIDAL 
                                ,mergeMode := IMMEDIATELY 
                                ,nextCommand := IMMEDIATELY
                                );
        END_IF;
            
        IF TO_slave.syncMonitoring.syncState <> Yes THEN   //gearoff finish
            GearOffRunning         := FALSE;
        END_IF;
            
        //------------------- SuperImpose pos ------------------------
        PosP_Trig(SPos_Positive);
        PosN_Trig(SPos_Negative);
        
        IF PosP_Trig.q 
            AND TO_slave.control = active 
        THEN
            myRetDINT := _pos(
                         axis := TO_slave
                        ,direction := POSITIVE
                        ,positioningMode := RELATIVE
                        ,position := SPos_Length
                        ,velocityType := DIRECT
                        ,velocity := SPos_Spd
                        ,positiveAccelType := DIRECT
                        ,positiveAccel := Acc
                        ,negativeAccelType := DIRECT
                        ,negativeAccel := Acc
                        ,velocityProfile := TRAPEZOIDAL 
                        ,blendingMode := INACTIVE
                        ,mergeMode := SUPERIMPOSED_MOTION_MERGE 
                        ,nextCommand := IMMEDIATELY
                        );
        END_IF;
        
        IF PosN_Trig.q 
            AND TO_slave.control = active 
        THEN
            myRetDINT := _pos(
                        axis := TO_slave
                        ,direction := NEGATIVE
                        ,positioningMode := RELATIVE
                        ,position := SPos_Length
                        ,velocityType := DIRECT
                        ,velocity := SPos_Spd
                        ,positiveAccelType := DIRECT
                        ,positiveAccel := Acc
                        ,negativeAccelType := DIRECT
                        ,negativeAccel := Acc
                        ,velocityProfile := TRAPEZOIDAL 
                        ,blendingMode := INACTIVE
                        ,mergeMode := SUPERIMPOSED_MOTION_MERGE 
                        ,nextCommand := IMMEDIATELY
                        );
        END_IF;
        
        gearOnOK := TO_slave.syncMonitoring.syncState = Yes
                    AND TO_slave.control = active;
        
    END_FUNCTION_BLOCK
   

posted on 2018-11-28 11:24  lion_zheng  阅读(809)  评论(0编辑  收藏  举报

导航