News:

SMF - Just Installed!

Main Menu

Interruptions

Started by jredrejo, May 31, 2024, 09:51:52 AM

Previous topic - Next topic

jredrejo

Hi,
I'm working on a program that's creating encoder pulses.
I'm creating them depending on the distance the axis travels.
In a good computer it works fine, however in not so powerfull computers, the number of pulses the encoder provides varies a lot depending on the speed of the axis (i.e. less pulses for the same distance). It seems the script main loop is not fast enough to track the axis movement.
Is there an alternative?
I was thinking of interrruptions, kind of the system we can use in a PLC (OB30 in Siemens Step7 for example)

Any ideas?

EasyPLC_Master

We can't help you if you don't share the code you're using.

jredrejo

Quote from: EasyPLC_Master on May 31, 2024, 08:33:19 PMWe can't help you if you don't share the code you're using.

This is the relevant part of the current program:
public void Init() {
    IOManager.SetOutputDesc(DO_Q3_M2, "Q3 (M2)"); //Motor 2 izquierdas
    IOManager.SetOutputDesc(DO_Q4_M2, "Q4 (M2)"); //Motor 2 derechas

    IOManager.SetInputDesc(DI_B3, "B3");  // Salida 1 Encoder
    IOManager.SetInputDesc(DI_B4, "B4");  // Salida 2 Encoder

    IOManager.SetAnOutputDesc(AO_PWM_M2, "PWM (M2)");  // Velocidad Motor 2

}

public float ScaleSpeed(int AnalogInput) {
    return (IOManager.GetAOutput(AnalogInput)) / 50f;
}

public void movimientoHorizontal() {
    bool brazo_saliendo = false;
    bool brazo_entrando = false;

    brazo_saliendo =(ventosa_torre.GetAnimationPosition("X") >= MIN_X) && IOManager.GetOutput(DO_Q4_M2) && !IOManager.GetOutput(DO_Q3_M2);
    if (brazo_saliendo) {
        ventosa_torre.AnimationMove("X", ScaleSpeed(AO_PWM_M2), MIN_X);
    }

    brazo_entrando =(ventosa_torre.GetAnimationPosition("X") <= MAX_X) && !IOManager.GetOutput(DO_Q4_M2) && IOManager.GetOutput(DO_Q3_M2);
    if (brazo_entrando) {
        ventosa_torre.AnimationMove("X", ScaleSpeed(AO_PWM_M2), MAX_X);
    }

if (!brazo_entrando && !brazo_saliendo) {
    ventosa_torre.BreakMovement();
}

}

 public void generacionPulsosEncoder() {   

    if (ventosa_torre.IsMoving){
        if ( (int)Math.Round(ventosa_torre.GetAnimationPosition("X")*100,0) % 2 == 0)
            {
                IOManager.SetInput(DI_B3, true);
                 IOManager.SetInput(DI_B4,  false);
            } else {
                IOManager.SetInput(DI_B3,false);
                 IOManager.SetInput(DI_B4, true);
            }
    }

}


public void Main() {
    movimientoHorizontal();
    generacionPulsosEncoder();

}