Supported platforms: CODESYS 3.5, CODESYS 3.5 SAFETY

 

How to validate a joystick with direction switches  

This section describes how to read and validate a joystick signal with direction switches.  

 

This example uses the following libraries:

SafeConversion library

SafeDataValidation library

SafeJoystickCalibrationAndDiagnostic library

 

, or alternatively non-safe library

SensorsAndActuators library

 

 

 

S_ADCToVoltageOrCurrent, S_VoltageToDI and S_DebounceDI POUs are included in the code template generated by MultiTool Creator.

 

 

The following image is an architecture example for joystick validation using direction switches.

 

SafeConversion library version 1.1.0.0 or newer.SafeConversion library version 1.1.0.0 or newer.

 

SafeConversion library version 1.0.1.2SafeConversion library version 1.0.1.2.

 

Example code (safety)

When the following example is used with non-safety I/O, the I/O variables are generated in Inputs program instead of S_Inputs.

 

The following example demonstrates the validation of a joystick signal  (AI pin Joystick in MultiTool Creator) and direction switches (DI pins JoyPosDirSwitch and JoyNegDirSwitch in MultiTool Creator).

 

Safe PRG:

 

 

 

Init method:

 

IF NOT initDone THEN

S_BoomJoystick.Init(

S_i_Deadband:=5 ,

S_i_ProgressionPosDir:=0 ,

S_i_ProgressionNegDir:=0 ,

S_i_SignalErrorTolerance:=5 ,

S_i_pCalibratedMinPosition:=ADR(S_JoystickMinPosition) ,

S_i_pCalibratedMidPosition:= ADR(S_JoystickMidPosition),

S_i_pCalibratedMaxPosition:= ADR(S_JoystickMaxPosition),

i_pEventCode:=ADR(S_Inputs.o_EventCode_Joystick) );

 

S_ValidateBoomJoystick.Init(

S_i_DirSwitchesInUse:=TRUE ,

S_i_MidPosSwitchInUse:=FALSE ,

S_i_DiagnosticDelay:= 100,

i_pEventCode:=ADR(S_Inputs.o_EventCode_Joystick) ,

i_pEventCodePDS:=ADR(S_Inputs.o_EventCode_JoyPosDirSwitch) ,

i_pEventCodeMPS:= ADR(S_Inputs.o_EventCode_Joystick),

i_pEventCodeNDS:=ADR(S_Inputs.o_EventCode_JoyNegDirSwitch) );

 

initDone:=TRUE;

END_IF

 

 

 

 

Example code (non-safety)

When the following example is used with non-safety I/O, the I/O variables are generated in Inputs program instead of S_Inputs.

 

The following example code reads direction switch joystick with alternative non-safe wrapper POU.

 

 

Code at non-safe PRG:

 

 

 

See also

 

 

 

Source file topic100383.htm

Last updated 19-Dec-2024