Supported platforms: CODESYS 3.5, CODESYS 3.5 SAFETY

 

How to validate 2 channel joystick

This section describes how to read and validate 2 channel joystick signals.  

 

This example uses the following libraries:

SafeConversion library

SafeDataValidation library

SafeJoystickCalibrationAndDiagnostic library

 

, or alternatively non-safe library

SensorsAndActuators library

 

 

S_ADCToVoltageOrCurrent POU is included in code template generated by MultiTool Creator.

 

 

The following image is an architecture example for 2-channel joystick validation.

 

 

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 reading and validating of 2 channel joystick signals (Joystick_X_A and Joystick_X_B AI signals defined in MultiTool Creator).

 

Code at safe PRG:

 

 

 

 

Initialization

Init method:

IF NOT initDone THEN

      initDone:=TRUE;

 

 

Validation init with SafeDataValidation V1.0.0.7Validation init with SafeDataValidation V1.0.0.7

Init method:


S_Validate_X_Axis.Init(

S_i_InvertedCh2 := TRUE,

S_i_DiagnosticDelay := UINT#40,

S_i_SafeOutputValue := DINT#0,

S_i_Tolerance := DINT#50,

S_i_SumValue := EPEC_HW.Constants.G_AI_5V_HIGH_VOLTAGE, // tolerance sum value for inverted mode validation

i_pEventCode := ADR(S_Inputs.o_EventCode_Joystick_X_A),

i_pEventCodeCh2 := ADR(S_Inputs.o_EventCode_Joystick_X_B) );



 

Validation init with SafeDataValidation V1.0.1.0 or newerValidation init with SafeDataValidation V1.0.1.0 or newer

Init method:


S_Validate_X_Axis.Init(

S_i_InvertedCh2 := TRUE,

S_i_DiagnosticDelay := UINT#40,

S_i_SafeOutputValue := DINT#0,

S_i_Tolerance := DINT#50,

S_i_SumValue := EPEC_HW.Constants.G_AI_5V_HIGH_VOLTAGE, // tolerance sum value for inverted mode validation

S_i_ReferenceValue := DINT#0, // reference value is not used in inverted mode

i_pEventCode:=ADR(S_Inputs.o_EventCode_Joystick_X_A),

i_pEventCodeCh2:=ADR(S_Inputs.o_EventCode_Joystick_X_B) );



 

Init method:

 

S_BoomJoystick_X.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) );

 

END_IF

 

Example code (non-safety)

The following example code reads 2-channel joystick with alternative non-safe wrapper POU.

 

Code at non-safe PRG:

 

 

 

See also

 

 

 

Source file topic100384.htm

Last updated 13-Jun-2024