Teach

Teach 1:

This core function is used for referencing analog encoder systems.

Syntax:

FUNCTION_BLOCK FB_Teach EXTENDS FB_CorefunctionFeedback

Teach 2: Properties

Name

Type

Access

Description

InitState

BOOL

Get, Set

The core function is not completely and successfully initialized.

FB_Teach

AllowAxisDisable

BOOL

Get, Set

If TRUE, the axis is automatically switched off when DoUpdate() is called up so that the scaling determined can be applied.

WARNING Only use this option if it is safe to switch off the axis spontaneously.

IncrNeg

DINT

Get, (Set)

The recorded value when executing TeachNeg() in analog increments.

IncrPos

DINT

Get, (Set)

The recorded value when executing TeachPos() in analog increments.

MinResolution

UDINT

Get, Set

The minimum resolution (between IncrNeg and IncrPos) required to achieve a usable result

MinStroke

LREAL

Get, Set

The minimum stroke required for a meaningful result.

Position

LREAL

Get, Set

The position setpoint to be set at the taught (teach) position. If SetUpperPosition is set, this position is taken into account at the top end.

SetUpperPosition

BOOL

Get, Set

If TRUE, the position setpoint defined at Position is set at the upper end of the measured scale.

Stroke

LREAL

Get, Set

The distance (or stroke) that is spanned between IncrNeg and IncrPos by the axis.

Valid

BOOL

Get

Two valid values were recorded.

FB_CorefunctionFeedback

AbortedState

BOOL

Get, Set

Signals the abort of a command by another Corefunction.

BusyState

BOOL

Get, Set

Signals the active execution of a command.

DoneState

BOOL

Get, Set

Signals the successful execution of a command.

IdleState

BOOL

Get, Set

The Corefunction is ready for operation and commandable.

IsCommanded

BOOL

Get

Signals the pending of a command.

FB_Corefunction

FailedState

BOOL

Get, Set

If IsActivated is TRUE at the same time: Signals the failure of an accepted command.

If IsActivated is FALSE at the same time: Signals the rejection of a command.

HasFeedback

BOOL

Get

The core function has responded to a pending command.

IsActivated

BOOL

Get

The core function has an accepted command pending.

IsLocalCmd

BOOL

Get

Signals that the axis is assigned with a command of this core function.

ReadyState

BOOL

Get, Set

The Corefunction is ready for operation, but is not commandable at this time.

Possible reasons are:
- The axis is not enabled.
- Another Corefunction is active.
- The Corefunction does not support any commands.

Teach 3: Methods

Name

Description

[INTERN] Cyclic()

This method is called cyclically by the axis.

FB_Teach

DoTeach(bExecute)

Sets the axis to teaching mode. Teaching mode is ended prematurely on a falling edge.

DoUpdate(bExecute)

Triggers the final calculation of the encoder parameters.

TeachNeg(bExecute)

Triggers the recording of the lower position.

TeachPos (bExecute)

Triggers the recording of the upper position.

Teach 4: Interfaces

Type

Description

I_Corefunction

Standard interface on FB_Corefunction.

FB_Teach

I_Teach

Standard interface on FB_Teach.

I_TeachDev

Extended interface with access to the inaccessible properties.

I_TeachPosition

Compatibility interface to the obsolete FB_TeachPosition function.

I_TeachUpdate

Compatibility interface to the obsolete FB_TeachUpdate function.

I_CorefunctionFeedback

Standard interface on FB_CorefunctionFeedback.

Example:

CASE nState OF
    
0:  // activate the teach mode
    IF bStartTeaching AND iAxisBase.Teach.IdleState THEN
        iAxisBase.Teach.DoTeach(TRUE);
        
    ELSIF iAxisBase.Teach.BusyState THEN
        nState := nState + 1;
    ELSIF iAxisBase.Teach.FailedState THEN
        nState := -1;
    END_IF

1:  // move to the first teach position

    // approaching the upper position by a jog command 
    // e.g. by pressing a push button
    iAxisBase.Jog.DoJogP(bButtonFwd);
    
    // on reaching final position, use a second button to teach the value
    iAxisBase.Teach.TeachPos(bTeach);
    
    IF bTeach THEN
        iAxisBase.Jog.DoJogP(FALSE);
        nState := nState + 1;
    END_IF
    
2:  // wait for teach button release
    IF NOT bTeach THEN
        nState := nState + 1;
    END_IF
    
3:  // move in the opposite direction for the second teach position

    // approaching the lower position by a jog command 
    // e.g. by pressing a push button
    iAxisBase.Jog.DoJogM(bButtonBwd);
    
    // on reaching final position, use the second button again to teach the value
    iAxisBase.Teach.TeachNeg(bTeach);
    
    IF bTeach THEN
        iAxisBase.Jog.DoJogM(FALSE);
        nState := nState + 1;
    END_IF
    
4:  // configure teach parameters and update the axis by the taught positions

    iAxisBase.Teach.AllowAxisDisable := TRUE;
    iAxisBase.Teach.Position := 0.0;    // mm
    iAxisBase.Teach.Stroke := 200.0;    // mm
    
    IF iAxisBase.Teach.Valid THEN
        iAxisBase.Teach.DoUpdate(TRUE);
        nState := nState + 1;
    ELSE 
        nState := -1;
    END_IF

5:  // wait for the update procedure getting done

    IF iAxisBase.Teach.DoneState THEN
        nState := nState + 1;
    ELSIF iAxisBase.Teach.FailedState THEN
        nState := -1;
    END_IF
    
6,  // teaching done
-1: // error

    iAxisBase.Teach.DoTeach(FALSE);
    iAxisBase.Teach.DoUpdate(FALSE);
    
END_CASE

Requirements

Development environment

Target platform

PLC libraries to include

TwinCAT v3.1.4024.71

PC or CX (x64, x86)

Tc3_PlasticFunctions (>= v12.12.0.0)