Habe mit Chat GPT gespielt....ist hier was sinnvolles rausgekommen?

More
21 Dec 2025 10:40 - 21 Dec 2025 11:06 #340364 by gravedigger
Ich habe für Buttons und Handrad chatGPT bemüht. Linux 2.9.7 mit Gmoccapy .
Leider kann ich nicht beurteilen, ob das alles Sinnvoll ist. Kann jemand Wissender drüberschauen?
Handrad:
#* Handrad-Encoder
#* Achswahl X/Y/Z über Drehschalter
#* Vorschubfaktor 1 / 10 / 100
#* Jog Mode über GPIO 041 („Stop sofort“ oder „Schritte zu Ende“)
#* Debounce für alle Schalter
#* Saubere Logik für gmoccapy

#



#
# ==========================================================
# mpg_2.9.7.hal
#
# Handrad-Pendant für GMoccapy / LinuxCNC 2.9.7
# Mesa 7i96S + 7i73
#
# Funktionen:
# - Achswahl X/Y/Z
# - Vorschubfaktor 1 / 10 / 100
# - Jog Mode über GPIO 041
# - Handrad Encoder
# ==========================================================

#
# Komponenten laden
#
loadrt debounce cfg=7
loadrt and2 count=6
loadrt mux4 count=1
loadrt scale count=1

addf debounce.0 servo-thread
addf and2.0 servo-thread
addf and2.1 servo-thread
addf and2.2 servo-thread
addf and2.3 servo-thread
addf and2.4 servo-thread
addf and2.5 servo-thread
addf mux4.0 servo-thread
addf scale.0 servo-thread


# ==========================================================
# Handrad Encoder Eingang
# ==========================================================
# Encoder: hm2_7i96s.0.7i73.0.0.enc0.count
net mpg-count hm2_7i96s.0.7i73.0.0.enc0.count


# ==========================================================
# Jog Mode Input
# ==========================================================
# GPIO 041: TRUE = Stop sofort, FALSE = Schritte zu Ende
net jogmode-raw hm2_7i96s.0.gpio.041.in => debounce.0.6.in
net jogmode debounce.0.6.out => halui.axis.jog-mode


# ==========================================================
# Achswahl X/Y/Z über Drehschalter
# ==========================================================
net axis-x-raw hm2_7i96s.0.gpio.034.in => debounce.0.0.in
net axis-y-raw hm2_7i96s.0.gpio.036.in => debounce.0.1.in
net axis-z-raw hm2_7i96s.0.gpio.038.in => debounce.0.2.in

net axis-x debounce.0.0.out
net axis-y debounce.0.1.out
net axis-z debounce.0.2.out


# ==========================================================
# Vorschubfaktor (1 / 10 / 100)
# ==========================================================
net scale-1-raw   hm2_7i96s.0.gpio.042.in => debounce.0.3.in
net scale-10-raw  hm2_7i96s.0.gpio.044.in => debounce.0.4.in
net scale-100-raw hm2_7i96s.0.gpio.046.in => debounce.0.5.in

net scale-1   debounce.0.3.out
net scale-10  debounce.0.4.out
net scale-100 debounce.0.5.out


# Mux4 wählt den Vorschubfaktor
setp mux4.0.in0 1
setp mux4.0.in1 10
setp mux4.0.in2 100
setp mux4.0.in3 1

# Auswahl
net scale-1  => mux4.0.sel0
net scale-10 => mux4.0.sel1
net scale-100 => mux4.0.sel2

net jog-scale mux4.0.out => scale.0.gain


# ==========================================================
# Encoder skalieren
# ==========================================================
net mpg-count => scale.0.in
net jog-count scale.0.out


# ==========================================================
# Jog nur wenn Jog-Mode aktiv
# ==========================================================
# In LinuxCNC 2.9.7 reicht halui.axis.jog-mode, daher hier nur direkte Weiterleitung
# Jog-count wird direkt an die Achsen gesendet


# ==========================================================
# Achs-Jogging für gmoccapy / HALUI
# ==========================================================
# X-Achse
net jog-count => and2.0.in0
net axis-x   => and2.0.in1
net jog-x and2.0.out => halui.axis.x.jog-counts

# Y-Achse
net jog-count => and2.1.in0
net axis-y   => and2.1.in1
net jog-y and2.1.out => halui.axis.y.jog-counts

# Z-Achse
net jog-count => and2.2.in0
net axis-z   => and2.2.in1
net jog-z and2.2.out => halui.axis.z.jog-counts


# ==========================================================
# OPTIONAL: GPIO Invertierungen (falls Low-aktiv)
# ==========================================================
# setp hm2_7i96s.0.gpio.034.invert 1
# setp hm2_7i96s.0.gpio.036.invert 1
# setp hm2_7i96s.0.gpio.038.invert 1
# setp hm2_7i96s.0.gpio.041.invert 1
# setp hm2_7i96s.0.gpio.042.invert 1
# setp hm2_7i96s.0.gpio.044.invert 1
# setp hm2_7i96s.0.gpio.046.invert 1
```

#---

## Merkmale

#* **X/Y/Z Achswahl** über Drehschalter
#* **Vorschubfaktor 1/10/100**
#* **Jog Mode** über GPIO 041:

 # * TRUE → Stop sofort
#  * FALSE → Schritt zu Ende
#* **Handrad-Encoder** wird auf gmoccapy `jog-counts` gemappt
#* Alle Eingänge sauber **entprellt**
#* Direkt **gmoccapy-kompatibel**

Buttons:
# Funktionsbeschreibung (Übersicht)

## Hardware

#* **Mesa 7i76S**
#* Momenttaster (NO)
#* Status-LEDs über GPIO-Ausgänge

## Belegung

#| GPIO | Funktion        |
#| ---- |
|
#| 035  | Start / Resume  |
#| 037  | Feed Hold       |
#| 039  | Stop / Reset    |
#| 050  | LED „Run“       |
#| 051  | LED „Feed Hold“ |
#| 052  | LED „Fault“     |

#

## Logik & Verhalten

### ▶ START (GPIO 035)

#* Nur wirksam, wenn **Machine ON**
#* Führt aus:

 # * `program.run`
 # * `program.resume`
 #* **löst Feed Hold**
#* Funktioniert parallel zu gmoccapy-Buttons

---

### ⏸ FEED HOLD (GPIO 037)

#* Stoppt Achsbewegungen sofort
#* Interpreter läuft weiter
#* **Gesperrt bei aktivem E-Stop**

#---

### STOP / RESET (GPIO 039)

#* **Kurz drücken (<1.5 s)** → `program.stop`
#* **Lang drücken (>1.5 s)** → `program.reset`
#* Reset **nur erlaubt, wenn Programm steht**


### STATUS-LEDs

* **RUN-LED** → Programm läuft
* **FEED HOLD-LED** → Feed Hold aktiv
* **FAULT-LED** → E-Stop ODER Maschine faulted

---

# buttons_complete.hal`


# ==========================================================
# buttons_complete.hal
#
# Hardware-Buttons + Status-LEDs
# LinuxCNC / gmoccapy
# Mesa 7i76S
#
# Funktionen:
# - Start = Run + Resume + Feed Hold lösen (nur bei Machine ON)
# - Feed Hold (gesperrt bei E-Stop)
# - Stop kurz = Program Stop
# - Stop lang (>1.5s) = Reset (nur wenn Maschine steht)
# - Status LEDs: Run / Feed Hold / Fault
# ==========================================================


#
# Komponenten laden
#
loadrt debounce cfg=3
loadrt not count=2
loadrt timedelay count=1
loadrt and2 count=6
loadrt or2 count=1

addf debounce.0 servo-thread
addf not.0 servo-thread
addf not.1 servo-thread
addf timedelay.0 servo-thread
addf and2.0 servo-thread
addf and2.1 servo-thread
addf and2.2 servo-thread
addf and2.3 servo-thread
addf and2.4 servo-thread
addf and2.5 servo-thread
addf or2.0 servo-thread


#
# Status-Signale aus HALUI
#

# Maschine eingeschaltet
net machine-on halui.machine.is-on

# Programm läuft
net program-running halui.program.is-running

# Feed Hold aktiv
net feedhold-active halui.program.feed-hold

# E-Stop aktiv
net estop-active halui.estop.is-engaged

# Maschine steht (Programm läuft NICHT)
net program-running => not.0.in
net machine-idle not.0.out


# ==========================================================
# START / RESUME / FEED HOLD LÖSEN
# GPIO 035
# ==========================================================

# Rohsignal
net start-raw hm2_7i796s.0.gpio.035.in => debounce.0.0.in

# Entprellt
net start-btn debounce.0.0.out

# Start nur wenn Machine ON
net start-btn => and2.0.in0
net machine-on => and2.0.in1
net start-valid and2.0.out

# Program Run + Resume
net start-valid => halui.program.run
net start-valid => halui.program.resume

# Feed Hold beim Start sicher lösen
net start-valid => not.1.in
net feedhold-release not.1.out => halui.program.feed-hold


# ==========================================================
# FEED HOLD (verriegelt bei E-Stop)
# GPIO 037
# ==========================================================

# Rohsignal
net feedhold-raw hm2_7i796s.0.gpio.037.in => debounce.0.1.in

# Entprellt
net feedhold-btn debounce.0.1.out

# Feed Hold nur wenn KEIN E-Stop
net feedhold-btn => and2.1.in0
net estop-active => and2.1.in1
setp and2.1.in1-invert TRUE

net feedhold-valid and2.1.out => halui.program.feed-hold


# ==========================================================
# STOP kurz / RESET lang
# GPIO 039
# ==========================================================

# Rohsignal
net stop-raw hm2_7i796s.0.gpio.039.in => debounce.0.2.in

# Entprellt
net stop-btn debounce.0.2.out


# --- Langdruck-Erkennung ---
setp timedelay.0.on-delay 1.5
setp timedelay.0.off-delay 0.0
net stop-btn => timedelay.0.in
net stop-long timedelay.0.out


# --- RESET nur wenn Maschine steht ---
net stop-long => and2.2.in0
net machine-idle => and2.2.in1
net reset-valid and2.2.out => halui.program.reset


# --- STOP nur bei kurzem Druck ---
net stop-btn => and2.3.in0
net stop-long => and2.3.in1
setp and2.3.in1-invert TRUE
net stop-short and2.3.out => halui.program.stop


# ==========================================================
# STATUS LEDs (GPIO Ausgänge)
# ==========================================================

# LED: Programm läuft
# net program-running => hm2_7i796s.0.gpio.050.out

# LED: Feed Hold aktiv
# net feedhold-active => hm2_7i796s.0.gpio.051.out

# LED: Fault (E-Stop oder Fault-Zustand)
# net estop-active => or2.0.in0
# net halui.machine.is-faulted => or2.0.in1
# net fault-led or2.0.out => hm2_7i796s.0.gpio.052.out


# ==========================================================
# OPTIONAL: GPIO Invertierungen (falls Low-aktiv)
# ==========================================================
# setp hm2_7i796s.0.gpio.035.invert 1
# setp hm2_7i796s.0.gpio.037.invert 1
# setp hm2_7i796s.0.gpio.039.invert 1

 
Last edit: 21 Dec 2025 11:06 by gravedigger.

Please Log in or Create an account to join the conversation.

More
21 Dec 2025 10:43 - 21 Dec 2025 10:44 #340365 by gravedigger
Das hier wäre meine Version mit dem geklautem Code aus dem Forum:



########################################
# 7i73/7i75 hal connections for the MPG#
# von Norbert Schechner kopiert #
########################################

# Here the mpg counts are connected
net jog-wheel-counts joint.0.jog-counts <= hm2_7i796s.0.7i73.0.0.enc0.count
net jog-wheel-counts joint.1.jog-counts
net jog-wheel-counts joint.2.jog-counts
net jog-wheel-counts axis.x.jog-counts
net jog-wheel-counts axis.y.jog-counts
net jog-wheel-counts axis.z.jog-counts

# we need a mux component to select the step increments
loadrt mux2 names=jog-mode-sel
addf jog-mode-sel servo-thread

net jog-scale-out jog-mode-sel.in0 <= gmoccapy.jog.jog-increment
# my default on continious jogging is 0,05 mm / count
setp jog-mode-sel.in1 0.050

# need to get the jog mode
# Mode 0 all steps will be done, Mode 1 joint will stop as soon as you stop spinning the mpg
net jog-vel-mode gmoccapy.jog.jog-inc-0 <= jog-mode-sel.sel <= hm2_7i796s.0.gpio.041.in
net jog-vel-mode joint.0.jog-vel-mode
net jog-vel-mode joint.1.jog-vel-mode
net jog-vel-mode joint.2.jog-vel-mode
net jog-vel-mode axis.x.jog-vel-mode
net jog-vel-mode axis.y.jog-vel-mode
net jog-vel-mode axis.z.jog-vel-mode

# already connected cont_joging on jog vel mode selection
# here we connect the physical buttons to select the jog increment
# net jog_cont gmoccapy.jog.jog-inc-0 <= hm2_7i76e.0.7i73.0.1.input-07
net jog_1000 gmoccapy.jog.jog-inc-1 <= hm2_7i796s.0.gpio.042.in
net jog_0100 gmoccapy.jog.jog-inc-2 <= hm2_7i796s.0.gpio.044.in
net jog_0010 gmoccapy.jog.jog-inc-3 <= hm2_7i796s.0.gpio.046.in
# net jog_0001 gmoccapy.jog.jog-inc-4 <= hm2_7i796s.0.gpio.041.in

# This is to change between jog modes 0 and 1
net jog_scale-out joint.0.jog-scale <= jog-mode-sel.out
net jog_scale-out joint.1.jog-scale
net jog_scale-out joint.2.jog-scale
net jog_scale-out axis.x.jog-scale
net jog_scale-out axis.y.jog-scale
net jog_scale-out axis.z.jog-scale

# this is to enable the selected joint / axis
net jog-x-enable joint.0.jog-enable <= hm2_7i796s.0.gpio.034.in
net jog-x-enable axis.x.jog-enable
net jog-y-enable joint.1.jog-enable <= hm2_7i796s.0.gpio.036.in
net jog-y-enable axis.y.jog-enable
net jog-z-enable joint.2.jog-enable <= hm2_7i796s.0.gpio.038.in
net jog-z-enable axis.z.jog-enable

# Buttons START PAUSE STOP mit Gmoccapy

net Button_Start gmoccapy.h-button.button-2 <= hm2_7i796s.0.gpio.035.in
net Button_Pause gmoccapy.h-button.button-4 <= hm2_7i796s.0.gpio.037.in
net Button_Stop gmoccapy.h-button.button-3 <= hm2_7i796s.0.gpio.039.in
Last edit: 21 Dec 2025 10:44 by gravedigger.

Please Log in or Create an account to join the conversation.

Time to create page: 0.090 seconds
Powered by Kunena Forum