Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5

Modify external axes behavior using setParam

#1
I'm trying to create a script to switch the external rotary axis (see photo), but when I run my script, nothing changes. I think there's an issue with the setParam function. Could you help me?

Code:
import tkinter as tk
from tkinter import messagebox
from robodk import robolink    # RoboDK API
# Connexion à RoboDK
RDK = robolink.Robolink()
# Fonction pour activer un axe externe spécifique
def activer_axe_externe(nom_axe):
    # Récupérer tous les robots (y compris ceux ayant des axes externes)
    robots = [item for item in RDK.ItemList() if item.Type() == robolink.ITEM_TYPE_ROBOT]
    for robot in robots:
        # Vérifier si le robot a des axes externes
        ext_joints = robot.getParam('ExtJoints')
        if ext_joints:
            # Désactiver tous les axes en mettant une liste vide
            robot.setParam('ExtJoints', '')
            robot.setParam("Synchro", "0")  # Désynchroniser d'abord
    # Activer l'axe externe sélectionné
    axe_externe = RDK.Item(nom_axe, robolink.ITEM_TYPE_ROBOT)
    if axe_externe.Valid():
        axe_externe.setParam('ExtJoints', '7')  # Activer l'axe externe (valeur 1)
        robot.setParam("Synchro", "1")
        messagebox.showinfo("Succès", f"Axe externe activé: {nom_axe}")
    else:
        messagebox.showerror("Erreur", f"Axe externe non trouvé: {nom_axe}")


Attached Files
.png   Capture d’écran 2025-03-28 154635.png (Size: 87.18 KB / Downloads: 41)
#2
You can find an example on how to change configurations for external axes here:
https://robodk.com/doc/en/PythonAPI/exam...n-settings

What exactly are you trying to do?
#3
RoboDK can only handle a single independent rotary axis. I created a script with a pop-up to associate the desired external axis.

Here is the code:
Code:
import tkinter as tk
from tkinter import messagebox
from robodk import robolink    # RoboDK API

# Connexion à RoboDK
RDK = robolink.Robolink()

# Fonction pour activer un axe externe spécifique
def activer_axe_externe(nom_axe):
    # Récupérer tous les robots (y compris ceux ayant des axes externes)
    robots = [item for item in RDK.ItemList() if item.Type() == robolink.ITEM_TYPE_ROBOT ]

    for robot in robots:
        # Vérifier si le robot a des axes externes
        ext_joints = robot.getParam('ExtJoints')
        if ext_joints:
            # Désactiver tous les axes en mettant une liste vide
            robot.setParam('ExtJoints', '')
            robot.setParam("Synchro", "0")  # Désynchroniser d'abord

    # Activer l'axe externe sélectionné
    axe_externe = RDK.Item(nom_axe, robolink.ITEM_TYPE_ROBOT )
    if axe_externe.Valid():
        axe_externe.setParam('ExtJoints', '8')  # Activer l'axe externe (valeur 1)
        robot.setParam("Synchro", "1")
        messagebox.showinfo("Succès", f"Axe externe activé: {nom_axe}")
    else:
        messagebox.showerror("Erreur", f"Axe externe non trouvé: {nom_axe}")

# Fonction appelée lorsque le bouton "Valider" est cliqué
def valider():
    selection = var.get()
    if selection:
        activer_axe_externe(selection)
    else:
        messagebox.showwarning("Avertissement", "Veuillez sélectionner un axe.")
       

# Création de la fenêtre principale
root = tk.Tk()
root.title("ACTEMIUM - Sélection de l'Axe Externe")
root.geometry("400x250")  # Définir la taille de la fenêtre
root.configure(bg="white")  # Définir le fond de la fenêtre en blanc

# Ajout d'un texte explicatif
explication = ("Choisissez un axe externe à activer. "
              "Tous les autres axes seront désactivés.")
tk.Label(root, text=explication, wraplength=350, bg="white", justify="center", font=("Helvetica", 12)).pack(pady=20)

# Liste des axes externes
axes_externes = ['TIG', 'MAG']
# Variable pour stocker la sélection de l'utilisateur
var = tk.StringVar(value=axes_externes[0])

# Création des boutons radio pour chaque axe
for axe in axes_externes:
  tk.Radiobutton(root, text=axe, variable=var, value=axe, bg="white", font=("Helvetica", 10, "bold")).pack(anchor=tk.CENTER, pady=5)


# Boutons de validation et d'annulation avec marges ajustées et taille augmentée
tk.Button(root, text="Annuler", command=root.destroy, font=("Helvetica", 12), width=10, height=2).pack(side=tk.LEFT, padx=40, pady=20)
tk.Button(root, text="Valider", command=valider, font=("Helvetica", 12), width=10, height=2).pack(side=tk.RIGHT, padx=40, pady=20)

# Lancement de la boucle principale de l'interface
root.mainloop()


Attached Files
.png   Image.png (Size: 81.2 KB / Downloads: 38)
.png   Capture d’écran 2025-03-28 154635.png (Size: 87.18 KB / Downloads: 37)
#4
You can find an example synchronizing a robot with a 3 axis turntable for welding here:
https://robodk.com/example/Synchronizati...0ID-8-2-00

I also attached a sample project that is similar to what you describe that we'll soon add to the library.

Where did you get the parameters ExtJoints and Synchro from? I don't think they are documented and should have no effect.


Attached Files
.rdk   Welding-with-3ax.rdk (Size: 6.82 MB / Downloads: 36)
#5
(03-31-2025, 07:16 AM)Albert Wrote: You can find an example on how to change configurations for external axes here:
https://robodk.com/doc/en/PythonAPI/exam...n-settings

What exactly are you trying to do?

I am looking to change the mechanism, not to modify these parameters.
#6
(03-31-2025, 09:10 AM)Albert Wrote: You can find an example synchronizing a robot with a 3 axis turntable for welding here:
https://robodk.com/example/Synchronizati...0ID-8-2-00

I also attached a sample project that is similar to what you describe that we'll soon add to the library.

Where did you get the parameters ExtJoints and Synchro from? I don't think they are documented and should have no effect.

Thank you for your feedback, but there is no script that handles the mechanism change. The 'ExtJoints' parameter is likely incorrect (I had asked an AI). In the API documentation, I can't find the function that could perform the change shown in the photo attached to the post.


Attached Files
.png   List_Mecanisme.png (Size: 109.88 KB / Downloads: 34)
#7
The mechanism change can be done using the API and the setLink function.

Example:
Code:
robot = RDK.Item('robot name')
axis_1 = RDK.Item('Axis_1')
axis_2 = RDK.Item('Axis_2')
axis_3 = RDK.Item('Axis_3')

# Set axis one at the desired location (0 deg for example)
axis_1_joints = [0]
axis_1.MoveJ(axis_1_joints)

# Synchronize the axes
robot.setLink(axis_3)
#8
Here's the corrected code, in case it's helpful to anyone, and thanks again for the support.

Code:
import tkinter as tk
from tkinter import messagebox
from tkinter import ttk
from robodk import robolink
# Connection to RoboDK
RDK = robolink.Robolink()
# Get the list of robots with 3 or more axes
robots_3axes = []
robots = [item for item in RDK.ItemList() if item.Type() == robolink.ITEM_TYPE_ROBOT]
for robot in robots:
    if len(robot.Joints().list()) > 3:  # Filter
        robots_3axes.append(robot)
robot_names = [robot.Name() for robot in robots_3axes]
# Create the main window
root = tk.Tk()
root.title("ACTEMIUM - External Axis Selection")
root.geometry("400x300")
root.configure(bg="white")
# Variable to store the selected robot
selected_robot = tk.StringVar(value=robot_names[0] if robot_names else "")
# List of external axes
external_axes = ['Plateau', 'TIG', 'MAG']
external_axes_display = ['TIG', 'MAG']
external_axes_pos_plateau = [0, 180]
axis_var = tk.StringVar(value=external_axes_display[0] if external_axes_display else "")
# Function to activate a specific external axis
def activate_external_axis(axis_name, robot_name):
    if robot_name:
        try:
            robot = RDK.Item(robot_name, robolink.ITEM_TYPE_ROBOT)
            if robot.Valid():
                full_axis_name = ""
                for full_name in external_axes:
                    if axis_name in full_name:
                        full_axis_name = full_name
                        break
                if full_axis_name:
                    axis_item = RDK.Item(full_axis_name)
                    if axis_item.Valid():
                        robot.setLink(RDK.Item('Plateau'))
                        if axis_name == 'TIG':
                            robot.MoveJ([0, 0, 0, 0, 0, 0, external_axes_pos_plateau[0]])
                        elif axis_name == 'MAG':
                            robot.MoveJ([0, 0, 0, 0, 0, 0, external_axes_pos_plateau[1]])
                        robot.setLink(axis_item)
                        messagebox.showinfo("Success", f"External axis activated: {axis_name} on {robot_name}")
                        robot.MoveJ([0, 0, 0, 0, 0, 0, 0])
                    else:
                        messagebox.showerror("Error", f"External axis not found: {full_axis_name}")
                else:
                    messagebox.showerror("Error", f"External axis not found: {axis_name}")
            else:
                messagebox.showerror("Error", f"Robot not found: {robot_name}")
        except Exception as e:
            messagebox.showerror("Error", f"An error occurred: {e}")
    else:
        messagebox.showwarning("Warning", "Please select a robot.")
# Function called when the "Validate" button is clicked
def validate():
    selected_axis = axis_var.get()
    selected_robot_name = selected_robot.get()
    if selected_axis and selected_robot_name:
        activate_external_axis(selected_axis, selected_robot_name)
    else:
        messagebox.showwarning("Warning", "Please select an axis and a robot.")
# Dropdown list for robot selection
ttk.Label(root, text="Select Robot:", background="white").pack(pady=(20, 5))
robot_combobox = ttk.Combobox(root, textvariable=selected_robot, values=robot_names)
robot_combobox.pack(pady=5)
# Set the default selection only if robot_names is not empty
if robot_names:
    robot_combobox.current(0)
# Explanation text
explanation = ("Choose an external axis to activate. "
              "All other axes will be deactivated.")
tk.Label(root, text=explanation, wraplength=350, bg="white", justify="center", font=("Helvetica", 12)).pack(pady=10)
# Radio buttons for each axis
if external_axes_display:
    for axis in external_axes_display:
        tk.Radiobutton(root, text=axis, variable=axis_var, value=axis, bg="white", font=("Helvetica", 10, "bold")).pack(anchor=tk.CENTER, pady=5)
else:
    tk.Label(root, text="No external axes available.", bg="white").pack(pady=10)
# Validate and Cancel buttons
tk.Button(root, text="Cancel", command=root.destroy, font=("Helvetica", 12), width=10, height=2).pack(side=tk.LEFT, padx=40, pady=20)
tk.Button(root, text="Validate", command=validate, font=("Helvetica", 12), width=10, height=2).pack(side=tk.RIGHT, padx=40, pady=20)
# Start the main loop
root.mainloop()
#9
Great! Thank you for your feedback.
  




Users browsing this thread:
1 Guest(s)