Hello Guest it is June 22, 2025, 07:30:42 PM

Author Topic: FRO and RRO with Encoder and Smoothstepper BOB  (Read 2803 times)

0 Members and 1 Guest are viewing this topic.

FRO and RRO with Encoder and Smoothstepper BOB
« on: December 01, 2024, 08:23:44 AM »
Is there a way to control the FRO and RRO with encoders? What is the procedure here? Unfortunately, my board has no analog inputs.
Re: FRO and RRO with Encoder and Smoothstepper BOB
« Reply #1 on: December 01, 2024, 08:26:23 AM »
I switched from Pokeys 57CNC to Smoothstepper with BOB because Pokeys did not run stably.
The last resort would probably be an additional 57U/E for the analog inputs or for the encoders.

Re: FRO and RRO with Encoder and Smoothstepper BOB
« Reply #2 on: December 01, 2024, 11:50:48 AM »
ChatGPT Script....

-- Lua-Skript für FRO und SRO über einen Encoder, optimiert

-- Konstanten für die Encoder-Pins
local encPinFRO = 10  -- Beispiel: Pin für FRO
local encPinSRO = 11  -- Beispiel: Pin für SRO

-- Schwellenwert für die Änderung (um unnötige Updates zu vermeiden)
local threshold = 1  -- Minimale Änderung, um einen Update auszulösen

-- Globale Variablen zum Speichern des letzten Encoderwerts
local lastFROValue = 0
local lastSROValue = 0

-- Funktion zum Einstellen der FRO
function SetFRO(encoderValue)
    local newFRO = encoderValue / 1000  -- Umrechnung des Encoderwerts in Prozent
    if math.abs(newFRO - lastFROValue) > threshold then
        mc.mcSignalSetState(1000, newFRO)  -- Setzt den FRO-Wert
        lastFROValue = newFRO  -- Speichert den letzten Wert
    end
end

-- Funktion zum Einstellen der SRO
function SetSRO(encoderValue)
    local newSRO = encoderValue / 1000  -- Umrechnung des Encoderwerts in Prozent
    if math.abs(newSRO - lastSROValue) > threshold then
        mc.mcSignalSetState(1001, newSRO)  -- Setzt den SRO-Wert
        lastSROValue = newSRO  -- Speichert den letzten Wert
    end
end

-- Funktion zum Abrufen des Encoderwerts
function GetEncoderValue(pin)
    local value = mc.mcInputGet(pin)  -- Liest den Wert des Encoders an einem Pin
    return value
end

-- Funktion zum Überwachen des Encoders
function MonitorEncoder()
    -- Abrufen der Encoderwerte
    local encoderValueFRO = GetEncoderValue(encPinFRO)
    local encoderValueSRO = GetEncoderValue(encPinSRO)

    -- Setzen der FRO- und SRO-Werte
    SetFRO(encoderValueFRO)
    SetSRO(encoderValueSRO)
end

-- Event-Timer: 10 ms Intervall für die Überwachung
function InitMonitor()
    local rc = mc.mcCntlSetTimer(10, "MonitorEncoder")  -- Setzt einen Timer für alle 10 ms
    if rc ~= mc.MERROR_NOERROR then
        mc.mcCntlSetLastError("Fehler beim Setzen des Timers für die Überwachung")
    end
end

-- Starte die Überwachung
InitMonitor()