VAR
Axis1 : AXIS_REF; // Référence à l’axe
MC_Power1 : MC_Power;
MC_MoveVelocity1 : MC_MoveVelocity;
START : BOOL := FALSE; // Pour démarrer la séquence
STOP : BOOL := FALSE; // Pour arrêter la séquence
bInitDone : BOOL := FALSE; // Flag init
bTestRunning : BOOL := FALSE; // Indique si le test est actif
VelocityArray : ARRAY[0..4] OF REAL := [1000.0, 2000.0, 3000.0, 2000.0,
1000.0];
StepIndex : INT := 0;
Direction : INT := 1;
Timer : TON;
TimerDelay : TIME := T#2S;
bStepReady : BOOL := TRUE;
END_VAR
// INIT – mise sous tension de l’axe une seule fois
IF NOT bInitDone THEN
MC_Power1.Axis := Axis1;
MC_Power1.Enable := TRUE;
MC_Power1();
IF MC_Power1.Status THEN
bInitDone := TRUE;
END_IF
ELSE
MC_Power1.Enable := TRUE; // maintenir sous tension
MC_Power1();
END_IF
// Gestion des commandes START / STOP
IF START AND NOT bTestRunning THEN
bTestRunning := TRUE;
StepIndex := 0;
Direction := 1;
bStepReady := TRUE;
END_IF
IF STOP AND bTestRunning THEN
bTestRunning := FALSE;
MC_MoveVelocity1.Execute := FALSE;
END_IF
// Exécution du profil si en mode test
IF bTestRunning AND bInitDone THEN
// Timer pour avancer à l'étape suivante
Timer(IN := NOT bStepReady, PT := TimerDelay);
bStepReady := Timer.Q;
IF bStepReady AND NOT MC_MoveVelocity1.Busy THEN
// Configurer la vitesse
MC_MoveVelocity1.Axis := Axis1;
MC_MoveVelocity1.Velocity := VelocityArray[StepIndex] * Direction;
MC_MoveVelocity1.Acceleration := 1000.0;
MC_MoveVelocity1.Deceleration := 1000.0;
MC_MoveVelocity1.Execute := TRUE;
// Réinitialiser le timer et avancer
Timer(IN := FALSE);
bStepReady := FALSE;
StepIndex := StepIndex + 1;
IF StepIndex > 4 THEN
StepIndex := 0;
Direction := Direction * -1;
END_IF
ELSE
MC_MoveVelocity1.Execute := FALSE;
END_IF
MC_MoveVelocity1(); // Appel du bloc
END_IF