Supported platforms: CODESYS 3.5, CODESYS 3.5 SAFETY
This section describes how to calibrate one axis for a joystick implemented with the SafeJoystickCalibrationAndDiagnostic library in a S Series / E Series unit.
The following example saves calibration parameters in a control unit's application.
This section does not describe how to implement the joystick itself, only calibration. See also How to validate 2 channel joystick |
It is application specific when a joystick is allowed to be calibrated (e.g. is the machine safe state required first?). This shall be specified when designing the application. By following this example, the calibration parameters are taken into use after the calibration is finished.
|
Calibration parameter saving is always done in a non-safety related program because it is necessary to call non-safe CANopenODSave> SaveODSaveAll (FB) Callback method when using OD parameters.
|
Following is calibration example using safety joystick in Safety Control Unit.
This example assumes the following:
the joystick is part of a safety functionality (implemented in a safety related program)
Calibration parameters given to S_Joystick init method are following safety parameters:
G_CAN1_SPAR.S_Joystick_X_CalibratedMax
G_CAN1_SPAR.S_Joystick_X_CalibratedMid
G_CAN1_SPAR.S_Joystick_X_CalibratedMin
Safety parameter CRC shall be updated after calibration, otherwise, safety parameter validation will fail after the next boot-up.
|
Use program output interfaces (e.g. Main / S_Main) or global variables to relay statuses between safety and non-safety related code. See also How to transfer data between non-safety and safety related tasks
|
Definitions: |
|
PROGRAM JoystickCalibration VAR_INPUT i_Enable: BOOL; i_CalibrationRequest: BOOL; (*Activation request from e.g. HMI*) i_CalibrationDone: BOOL; (*Feedback from safety PRG, use joystick's o_Status.CalibrationDone*) END_VAR VAR_OUTPUT o_CalibrationMode: BOOL; (*To safety PRG, use this in joystick's i_CalibrationMode *) END_VAR VAR initDone: BOOL; calibrationActive: BOOL; calibrationDoneOld: BOOL; joystick_x_crc_valid: BOOL; pJoystick_x_ODEntry: POINTER TO EPEC_CANopen.ODEntry; odSaveResult: EPEC_ODSAVE.SaveODErrors; END_VAR
VAR CONSTANT JOYSTICK_X_INDEX:WORD := 16#2201; (*OD index containing calibration parameters*) END_VAR |
Code: |
|
IF NOT initDone THEN initDone := TRUE; pJoystick_x_ODEntry := CANopenODGetIndexEntryPtr(i_pOD:= ADR(G_CANopen_CAN1.OD), i_Index := JOYSTICK_X_INDEX); END_IF IF pJoystick_x_ODEntry <> DWORD#0 THEN (*Calibration mode request to joystick*) IF i_Enable AND i_CalibrationRequest THEN o_CalibrationMode := TRUE; calibrationActive := TRUE; ELSE o_CalibrationMode := FALSE; END_IF
IF i_CalibrationDone AND NOT calibrationDoneOld THEN (*Copy parameter values from safety parameters to non-safe OD PAR after calibration, note that the safety parameters are used at Joystick FB's init*) G_CAN1_PAR.Joystick_X_CalibratedMax := G_CAN1_SPAR.S_Joystick_X_CalibratedMax; G_CAN1_PAR.Joystick_X_CalibratedMid := G_CAN1_SPAR.S_Joystick_X_CalibratedMid; G_CAN1_PAR.Joystick_X_CalibratedMin := G_CAN1_SPAR.S_Joystick_X_CalibratedMin;
(*Update Joystick X parameter CRC, note use correct table index Application could also find correct array index by searching OD index from G_CAN1_VAR.SafetyParameterIndexList*) G_CAN1_VAR.SafetyParameterIndexCRCs[0] := CalculateParameterIndexCRC( i_pData := pJoystick_x_ODEntry^.IndexData.pData, i_NumberOfIndices := pJoystick_x_ODEntry^.NumOfSubids, i_DataType := EPEC_SDV.ParameterDataType.Deftype_INTEGER32, o_ParameterError => , o_OutputValid => joystick_x_crc_valid );
(*save parameters to nvram*) G_CANopen_CAN1.SaveAll.Callback(o_Error => odSaveResult);
calibrationActive := FALSE; END_IF calibrationDoneOld := i_CalibrationDone; END_IF
|
The following example image is from the Main program.
o_CalibrationMode is the Main program's output which is used in the joystick's i_CalibrationMode input
S_Main.o_CalibrationDone is the safety joystick's o_Status.CalibrationDone flag
the calibration request is application specific
Following is calibration example using non-safety joystick in
E Series Control Unit
Safety Control Unit's non-safety related code.
This example assumes the following:
the joystick is not a safety functionality (using E series unit or Safety Control Unit's non-safety related code)
Calibration parameters given to S_Joystick init method are OD parameters:
G_CAN1_PAR.Joystick_X_CalibratedMax
G_CAN1_PAR.Joystick_X_CalibratedMid
G_CAN1_PAR.Joystick_X_CalibratedMin
Definitions: |
|
PROGRAM JoystickCalibration VAR_INPUT i_Enable: BOOL; i_CalibrationRequest: BOOL; (*Activation request from e.g. HMI*) i_CalibrationDone: BOOL; (*Feedback from joystick PRG, use joystick's o_Status.CalibrationDone*) END_VAR VAR_OUTPUT o_CalibrationMode: BOOL; (*To joystick PRG, use this in joystick's i_CalibrationMode *) END_VAR VAR calibrationActive: BOOL; calibrationDoneOld: BOOL; odSaveResult: EPEC_ODSAVE.SaveODErrors; END_VAR |
Code: |
|
(*Calibration mode request to joystick*) IF i_Enable AND i_CalibrationRequest THEN o_CalibrationMode := TRUE; calibrationActive := TRUE; ELSE o_CalibrationMode := FALSE; END_IF
IF i_CalibrationDone AND NOT calibrationDoneOld THEN
(*save parameters to nvram*) G_CANopen_CAN1.SaveAll.Callback(o_Error => odSaveResult);
calibrationActive := FALSE; END_IF calibrationDoneOld := i_CalibrationDone;
|
The following example image is from the Main program.
CalibrationMode is the Main program's variable which is used in the joystick's i_CalibrationMode input
CalibrationDone is the joystick's o_Status.CalibrationDone flag
the calibration request is application specific
CANopenODSave library
Source file topic100544.htm
Last updated 19-Dec-2024