Supported platforms: CODESYS 3.5, CODESYS 3.5 SAFETY

 

S_ValidateJoystickWithDirSwitches (FB)

Description

This function block validates calibrated joystick control signal by direction switch statuses (negative direction, positive direction and middle position).

 

Limitations

This function block validates only one axis of joystick.

 

Initialization

Init method is used to initialize the necessary static calculation parameters for the function block instance.

The method shall be called at least once before the actual function block can be called, i.e. at the application initialization phase.

The method checks the validity of input parameters. However, none of the function block outputs are affected by the initialization.

 

A parameter error is diagnosed if:

Init method is not called before the main FB call OR

i_pEventCode = 0 OR

S_i_MidPosDirSwitchesUse = TRUE AND middle position switch channel event code pointer = 0 OR

S_i_DirSwitchesInUse = TRUE AND either of direction switch channel event code pointer = 0

 

 

The safe output of the function block is 0, so no input parameter for safe value is specified.

 

Initialization parameters

Parameter

Data type

Unit

Range

Description

S_i_DiagnosticDelay

SAFEUINT

ms

-

Delay time for diagnostics.

S_i_DirSwitchesInUse

SAFEBOOL

-

-

Direction switches are in use.

S_i_MidPosSwitchInUse

SAFEBOOL

-

-

Middle position switch is in use.

i_pEventCode

POINTER TO EventCode

-

≠0

Pointer to application variable which is type EventCode. Used with POUs that use joystick control signal data.

i_pEventCodePDS

POINTER TO EventCode

-

≠0

Pointer to application variable which is type EventCode. Used with POUs that handle positive direction switch data.

i_pEventCodeMPS

POINTER TO EventCode

-

≠0

Pointer to application variable which is type EventCode. Used with POUs that handle middle position switch data.

i_pEventCodeNDS

POINTER TO EventCode

-

≠0

Pointer to application variable which is type EventCode. Used with POUs that handle negative direction switch data.

 

Initialization method return value

TRUE: All initialization parameters ok.

FALSE: Error in initialization parameter(s).

 

 

Operation

The function block writes S_i_Control value to S_o_Control and sets o_Status.OutputValid state TRUE if

 

When S_i_Control < 0,

 

When S_i_Control = 0,

 

When S_i_Control > 0,

 

Operation in fault situations

If control value mismatch switch statuses continuously over S_i_DiagnosticDelay time, then

 

All function block statuses, including errors are reset on rising edge of i_Enable.

 

Inputs

Input variable name

Data type

Range

Description

i_Enable

BOOL

-

Enable POU operation

S_i_Control

SAFEINT

-

Input control value

S_i_PosDirSwitch

SAFEBOOL

-

Positive direction switch status

S_i_MidPosSwitch

SAFEBOOL

-

Middle position switch status

S_i_NegDirSwitch

SAFEBOOL

-

Negative direction switch status

Outputs

Output variable name

Data type

Range

Description

S_o_Control

SAFEINT

-

Validated control value

o_Status

Status

-

Status of output value. See Status structure.

Error diagnostic

See Diagnostic Interface library description of error status and event code functionality.

 

Conditions

S_o_Control

o_Status. OutputValid

o_Status error status

Event code FunctionID

Event code EventID

i_Enable TRUE

AND

init parameter error AND

 i_pEventCode valid

0

FALSE

ParameterError

VALIDATE_DIRSW

_JOYSTICK

PARAMETER

_ERROR

i_Enable TRUE

AND

init parameter error AND
i_pEventCode NULL

0

FALSE

ParameterError

-

-

i_Enable = TRUE &

 init parameters Ok & S_i_Control = 0 & S_i_PosDirSwitch = FALSE & S_i_NegDirSwitch = FALSE & S_i_MidPosSwitch = TRUE & S_i_MidPosSwitchInUse = TRUE

S_i_Control

TRUE

-

NO_FUNC

NO_ERROR

i_Enable = TRUE & init parameters Ok & S_i_Control = 0 & S_i_PosDirSwitch = FALSE & S_i_NegDirSwitch = FALSE & S_i_MidPosSwitch = FALSE & S_i_MidPosSwitchInUse = FALSE

S_i_Control

TRUE

-

NO_FUNC

NO_ERROR

i_Enable = TRUE & init parameters Ok & S_i_Control > 0 & S_i_PosDirSwitch = TRUE & S_i_NegDirSwitch = FALSE & S_i_MidPosSwitch = FALSE & S_i_DirSwitchInUse = TRUE

S_i_Control

TRUE

-

NO_FUNC

NO_ERROR

i_Enable = TRUE & init parameters Ok & S_i_Control < 0 & S_i_PosDirSwitch = FALSE & S_i_NegDirSwitch = TRUE & S_i_MidPosSwitch = FALSE & S_i_DirSwitchInUse = TRUE

S_i_Control

TRUE

-

NO_FUNC

NO_ERROR

i_Enable = TRUE & init parameters Ok & S_i_Control <> 0 & S_i_PosDirSwitch = FALSE & S_i_NegDirSwitch = FALSE & S_i_MidPosSwitch = FALSE & S_i_DirSwitchInUse = FALSE

S_i_Control

TRUE

-

NO_FUNC

NO_ERROR

i_Enable = TRUE &

 init parameters Ok &

S_i_Control = 0 & S_i_MidPosSwitch = FALSE & S_i_MidPosSwitchInUse = TRUE

0

FALSE

MidPos Switch Missing

VALIDATE_DIRSW

_JOYSTICK

MIDPOS_SWITCH

_STATUS_MISSING  

i_Enable = TRUE &

 init parameters Ok &

S_i_Control <> 0 & S_i_MidPosSwitch = TRUE

0

FALSE

MidPos Switch On Fault

VALIDATE_DIRSW

_JOYSTICK

MIDPOS_SWITCH

_STATUS_ON_FAULT

i_Enable = TRUE &

 init parameters Ok &

S_i_Control > 0 & S_i_PosDirSwitch = FALSE & S_i_DirSwitchesInUse = TRUE

0

FALSE

Positive Dir Switch Missing

VALIDATE_DIRSW

_JOYSTICK

POSDIR_SWITCH

_STATUS_MISSING

i_Enable = TRUE &

 init parameters Ok &

S_i_Control <= 0 & S_i_PosDirSwitch = TRUE

0

FALSE

Positive Dir Switch On Fault

VALIDATE_DIRSW

_JOYSTICK

POSDIR_SWITCH

_STATUS_ON_FAULT

i_Enable = TRUE &

 init parameters Ok &

S_i_Control < 0 & S_i_NegDirSwitch = FALSE & S_i_ DirSwitchesInUse = TRUE

0

FALSE

Negative Dir Switch Missing  

VALIDATE_DIRSW

_JOYSTICK

NEGDIR_SWITCH

_STATUS_MISSING

i_Enable = TRUE &

 init parameters Ok &

S_i_Control >= 0 & S_i_NegDirSwitch = TRUE

0

FALSE

Negative Dir Switch On Fault

VALIDATE_DIRSW

_JOYSTICK

NEGDIR_SWITCH

_STATUS_ON_FAULT

 

Example code

Safe definitions:

 

(* Voltage conversion FBs (generated by MT) left out of example *)

 

(* DI conversion FBs  *)

S_1_09_ToDI: EPEC_SC.S_VoltageToDI;         // generated by MT

S_1_10_ToDI: EPEC_SC.S_VoltageToDI;         // generated by MT

S_1_11_ToDI: EPEC_SC.S_VoltageToDI;         // generated by MT

 

(* DI statuses from AI values, converted with S_VoltageToDI *)

S_DI_1_09_State: SAFEBOOL := FALSE;         // generated by MT

S_DI_1_10_State: SAFEBOOL := FALSE;         // generated by MT

S_DI_1_11_State: SAFEBOOL := FALSE;         // generated by MT

 

EC_DI1_09: EPEC_DITF.EventCode;             // these event codes are generated by MT

EC_DI1_10: EPEC_DITF.EventCode;             // and used by conversions AND validation

EC_DI1_11: EPEC_DITF.EventCode;             //

 

 

// joystick and validation data is not generated by MT

S_SteeringJoystick: EPEC_SJCD.S_Joystick;   // joystick FB

EC_SteeringJoystick: EPEC_DITF.EventCode;   // event code of joystick

S_JoystickControl: SAFEINT;                 // control signal to be validated

 

S_DirSwitchValidation: EPEC_SDV.S_ValidateJoystickWithDirSwitches;

S_Joystick_DirSwitchDiagDelay: SAFEUINT:=UINT#100;

JoystickValidationStatus: EPEC_SDV.Status;

S_ValidJoystickControl: SAFEINT;            // validated control signal

 

 

 

Init at safe PRG:

 

EC_DI1_09.DeviceID := DeviceIDs.VoltageInput;

EC_DI1_09.ChannelID := ChannelIDs.Ch2;

EC_DI1_09.FunctionID := EPEC_DITF.FunctionIDs.NO_FUNC;

EC_DI1_09.EventID := EPEC_DITF.ErrorIDs.NO_ERROR;

 

EC_DI1_10.DeviceID := DeviceIDs.VoltageInput;

EC_DI1_10.ChannelID := ChannelIDs.Ch3;

EC_DI1_10.FunctionID := EPEC_DITF.FunctionIDs.NO_FUNC;

EC_DI1_10.EventID := EPEC_DITF.ErrorIDs.NO_ERROR;

 

EC_DI1_11.DeviceID := DeviceIDs.VoltageInput;

EC_DI1_11.ChannelID := ChannelIDs.Ch4;

EC_DI1_11.FunctionID := EPEC_DITF.FunctionIDs.NO_FUNC;

EC_DI1_11.EventID := EPEC_DITF.ErrorIDs.NO_ERROR;

 

EC_SteeringJoystick.DeviceID := DeviceIDs.SteeringJoystick;

EC_SteeringJoystick.ChannelID := ChannelIDs.Ch1;

EC_SteeringJoystick.FunctionID := EPEC_DITF.FunctionIDs.NO_FUNC;

EC_SteeringJoystick.EventID := EPEC_DITF.ErrorIDs.NO_ERROR;

 

 

S_DirSwitchValidation.Init(

    S_i_DirSwitchesInUse := TRUE,

    S_i_MidPosSwitchInUse := TRUE,

    S_i_DiagnosticDelay := Joystick_DirSwitchDiagDelay,

    i_pEventCode := ADR(EC_SteeringJoystick),

    i_pEventCodePDS := ADR(EC_DI1_09),

    i_pEventCodeMPS := ADR(EC_DI1_10),

    i_pEventCodeNDS := ADR(EC_DI1_11)

);

 

 

Code at safe PRG:

 

S_DirSwitchValidation(

    i_Enable := S_SteeringJoystick.o_Status.OutputValid AND

                S_1_09_ToDI.o_Status.OutputValid AND

                S_1_10_ToDI.o_Status.OutputValid AND

                S_1_11_ToDI.o_Status.OutputValid,

    S_i_Control := S_JoystickControl,

    S_i_PosDirSwitch := S_DI_1_09_State,

    S_i_MidPosSwitch := S_DI_1_10_State,

    S_i_NegDirSwitch := S_DI_1_11_State,

    S_o_Control => S_ValidJoystickControl,

    o_Status => JoystickValidationStatus

);

 

 

See also