[Codesys]Codesys封装的变更轴回零模式功能块-Fb_ChangeHomePara

360影视 2025-01-22 17:00 3

摘要:FUNCTION_BLOCK Fb_ChangeHomeParaVAR_INPUT PtAxis : POINTER TO AXIS_REF_SM3 ; sHomePara : HomePara_DUT ; xExecute : BOOL ;END_VARVA

今天没出去,正好早上在公司写计划书。突然想起之前有网友在找 Codesys 的回零参数功能块。这是个老需求啦,中午就利用空闲时间封装了一个。有需要的直接复制粘贴拿走就行,别客气哈。

正文:咱们都清楚,不管是用原版的 CODESYS 还是二次开发的定制版,通常都是通过驱动页面下的 SDO 配置方式来实现上电后下发的参数。当然啦,在一些实际项目的应用场合中,需要改变回零模式或者回零的速度。今天分享的就是因为这个需求而产生的功能块。

1.Code Show


1.1 HomePara_DUT

TYPE HomePara_DUT : STRUCT SiHomingMethod : SINT ; UdiHomingAcc : UDINT ; UdiHomeSpeedFast : UDINT ; UdiHomeSpeedSlow : UDINT ; END_STRUCTEND_TYPE


1.2 FB_ChanegHomePara

FUNCTION_BLOCK Fb_ChangeHomeParaVAR_INPUT PtAxis : POINTER TO AXIS_REF_SM3 ; sHomePara : HomePara_DUT ; xExecute : BOOL ;END_VARVAR_OUTPUT bDone : BOOL := FALSE ; wErrorID : WORD := 16#0000 ;END_VARVAR ReadStatus : MC_ReadStatus; WriteParameter : MC_WriteParameter; iStep : INT := 0 ;END_VARCASE iStep OF 0 : WriteParameter.Execute := FALSE ; wErrorID := 16#0000 ; //无错误 IF xExecute THEN iStep := 10 ; END_IF ; 10: IF NOT ReadStatus.Disabled THEN wErrorID := 16#0010 ; //轴状态机不允许 iStep := 90 ; //功能块错误流程 ELSE iStep := iStep + 10 ; END_IF ; 20: IF ((sHomePara.SiHomingMethod > 0) AND (sHomePara.SiHomingMethod 0) AND (sHomePara.UdiHomeSpeedFast 0) AND (sHomePara.UdiHomeSpeedSlow 0) THEN iStep := iStep + 10 ; ELSE wErrorID := 16#0100 ; //回零参数有异常 iStep := 90 ; //功能块错误流程 END_IF; 30: WriteParameter.ParameterNumber := - DWORD_TO_DINT( (SHL(TO_DWORD(1),24) + SHL(TO_DWORD(16#6098),8) + 0 ) ); WriteParameter.Value := SINT_TO_LREAL(sHomePara.SiHomingMethod); WriteParameter.Execute := TRUE ; IF WriteParameter.Done THEN WriteParameter.Execute := FALSE ; iStep := iStep + 10 ; ELSIF WriteParameter.Error THEN WriteParameter.Execute := FALSE ; wErrorID := 16#1000 ; //回零模式写入失败 iStep := 0 ; END_IF ; 40: WriteParameter.ParameterNumber := - DWORD_TO_DINT( (SHL(TO_DWORD(4),24) + SHL(TO_DWORD(16#609A),8) + 0 ) ); WriteParameter.Value := UDINT_TO_LREAL(sHomePara.UdiHomingAcc); WriteParameter.Execute := TRUE ; IF WriteParameter.Done THEN WriteParameter.Execute := FALSE ; iStep := iStep + 10 ; ELSIF WriteParameter.Error THEN WriteParameter.Execute := FALSE ; wErrorID := 16#2000 ; //回零加速度写入失败 iStep := 0 ; END_IF ; 50: WriteParameter.ParameterNumber := - DWORD_TO_DINT( (SHL(TO_DWORD(4),24) + SHL(TO_DWORD(16#6099),8) + 1 ) ); WriteParameter.Value := UDINT_TO_LREAL(sHomePara.UdiHomeSpeedFast); WriteParameter.Execute := TRUE ; IF WriteParameter.Done THEN WriteParameter.Execute := FALSE ; iStep := iStep + 10 ; ELSIF WriteParameter.Error THEN WriteParameter.Execute := FALSE ; wErrorID := 16#3000 ; //回零快速写入失败 iStep := 0 ; END_IF ; 60: WriteParameter.ParameterNumber := - DWORD_TO_DINT( (SHL(TO_DWORD(4),24) + SHL(TO_DWORD(16#6099),8) + 2 ) ); WriteParameter.Value := UDINT_TO_LREAL(sHomePara.UdiHomeSpeedSlow); WriteParameter.Execute := TRUE ; IF WriteParameter.Done THEN WriteParameter.Execute := FALSE ; iStep := iStep + 10 ; ELSIF WriteParameter.Error THEN WriteParameter.Execute := FALSE ; wErrorID := 16#4000 ; //回零快速写入失败 iStep := 0 ; END_IF ; 70: bDone := TRUE ; IF NOT xExecute THEN bDone := FALSE ; iStep := 0 ; END_IF ; 90: IF NOT xExecute THEN bDone := FALSE ; iStep := 0 ; END_IF ;END_CASE ;ReadStatus( Axis := PtAxis^, Enable := NOT ReadStatus.Error, Valid => , Busy => , Error => , ErrorID => , Disabled => , Errorstop => , Stopping => , StandStill => , DiscreteMotion => , ContinuousMotion => , SynchronizedMotion => , Homing => , ConstantVelocity => , Accelerating => , Decelerating => , FBErrorOccured => ); WriteParameter( Axis := PtAxis^, Execute := , ParameterNumber := , Value := , Done => , Busy => , Error => , ErrorID => );


1.3 测试程序

功能块已经经过实际测试啦,测试平台是雷赛 LeadsysStudio 和原版 Codesys。有需要的话,您也可以自行把它封装成库。

2025-01-18 Codesys下变更轴回零模式功能块-Fb_ChangeHomePara PLC论坛-全力打造可编程控制器专业技术论坛 -

来源:PLC技术玩

相关推荐