Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Window gives No Responde afte use of rotate() with big angle #1091

Open
NoahBeck01 opened this issue Apr 11, 2024 · 1 comment
Open

Window gives No Responde afte use of rotate() with big angle #1091

NoahBeck01 opened this issue Apr 11, 2024 · 1 comment

Comments

@NoahBeck01
Copy link

Hello, I'm trying to make an animation of a robot arm with vedo but whenever I make a large rotation angle the animation starts but then it stops and the window says "No Responde" and shortly afterwards it continues but the animation is already completed. I don't know if it might be my laptop. Sorry if my code looks terrible, I'm still a beginner

#ModelMain.py
from vedo import *
import numpy as np
import time
import os
from settings import *
# TODO
# Gripper1/2
# Bewegung hoch und runter einschränken in Auto Modus
# ty lagg fix
# Auto Kallibration


TurnArray = {turnTable, middle, middle_point, forearm, forearm_point, grip, grip_point, gripper1, gripper2}
MiddelArray = {middle, middle_point, forearm, forearm_point, grip, grip_point, gripper1, gripper2}
ForeArmArray = {forearm, forearm_point, grip, grip_point, gripper1, gripper2}
GripArray = {grip, grip_point, gripper1, gripper2}
Gripper1Array = {gripper1, gripper1_point}
Gripper2Array = {gripper2, gripper2_point}


Manuell = False

# Ermitteln des Verzeichnisses des aktuellen Skripts
script_dir = os.path.dirname(os.path.abspath(__file__))

# Dateiname
file_name = 'commands.eCode'

file_path = os.path.join(script_dir, file_name)

def transfrom_matrix(array):
    # Konvertieren Sie das Set in eine Liste
    mesh_list = list(array)
    # Greifen Sie auf das erste Element der Liste zu
    mesh = mesh_list[0]
    transform_matrix = mesh.transform.matrix
    rotation_matrix = transform_matrix[:3, :3]

    direction_vectors = rotation_matrix.T

    return direction_vectors[0]


def buttonfunc(obj, ename):
    array_test()


def rotate(array, angle):
    rotation_point = []
    v = vector(1, 0, 0)
    if array == TurnArray:
        rotation_point = turnTable_point.pos()
        v = vector(0, 0, 1)
    elif array == MiddelArray:
        matrix = transfrom_matrix(array)
        v = vector(matrix)
        if angle > 27:
            angle = 27
        elif angle < -27:
            angle = -27
        rotation_point = middle_point.pos()
    elif array == ForeArmArray:
        rotation_point = forearm_point.pos()
        matrix = transfrom_matrix(array)
        v = vector(matrix)
    elif array == GripArray:
        rotation_point = grip_point.pos()
        matrix = transfrom_matrix(array)
        v = vector(matrix)

    # Überprüfen, ob der Winkel negativ ist
    if angle < 0:
        rotation_direction = 1
    else:
        rotation_direction = -1
    # Anzahl der Schritte basierend auf dem absoluten Winkelwert
    steps = abs(angle) // 2
    for y in range(steps):
        # update_positions(np.radians(angle), rotation_point)
        for i in array:
            i.rotate(2 * rotation_direction, axis=v, point=rotation_point)
        plt.render()
        if angle > 180:
            time.sleep(0.01)  # Schnellere Rotation für hohe Winkel
        else:
            time.sleep(0.05)  # Langsamere Rotation für niedrige Winkel

def chose_array(inputs):
    angle = 0
    try:
        teile = inputs.split(",")

        Array = teile[0].strip()
        a = teile[1].strip().lower()

        # Check if the angle is provided as a boolean value
        if a == "true":
            angle = 27
        elif a == "false":
            angle = -27
        else:
            # Attempt to convert the angle to an integer
            angle = int(a)


        if Array == "S1":
            rotate(TurnArray, angle)
        elif Array == "S2":
            rotate(ForeArmArray, angle)
        elif Array == "S3":
            rotate(GripArray, angle)
        elif Array == "M1":
            rotate(MiddelArray, angle)
        else:
            pass

    except ValueError as e:
        # Handle the case where the angle cannot be converted to an integer
        print(f"Error: Invalid angle value '{a}'. Expected an integer or 'true'/'false'.")
    except Exception as e:
        print(e)
        print(inputs)
        pass


def array_test():
    if Manuell:
        eingabe = input(">")
        chose_array(eingabe)
    elif not Manuell:
        if os.path.exists(file_path):
            with open(file_path, 'r') as file:
                for line in file:
                    print(f"Processing command: {line.strip()}") # Logging the command being processed
                    chose_array(line)
                    plt.render() # Ensure rendering after processing each command
                    time.sleep(0.1) # Adjust sleep interval if necessary
        else:
            print(f"Error {file_path} does not exist!")
    else:
        print(f"Error can't use {file_or_not}!")



plt = Plotter(axes=11)

bu = plt.add_button(
    buttonfunc,
    pos=(0.5, 0.15),
    states=["Start"],
    c=["w"],
    bc=["black"],
    font="ComicMono",
    size=30,
    bold=False,
    italic=False,

)

l1 = Light(light, c="w", intensity=10)
l2 = Light(light2, c="w", intensity=5)

# forearm.pos([-370, 220, 405])


cubemap_path = 'assets/wide_street_02_8k.hdr'

transform_matrix = turnTable.transform.matrix
rotation_matrix = transform_matrix[:3, :3]

direction_vectors = rotation_matrix.T

print("Richtungsvektor 1:", direction_vectors[0])
print("Richtungsvektor 2:", direction_vectors[1])
file_or_not = input("Manuel Or Auto?(m/a)\n")
if file_or_not.lower() == "m":
    Manuell = True
else:
    pass
plt.show(base, turnTable, middle, forearm, grip, gripper1, gripper2, l1, l2, turnTable_point, forearm_point,
         middle_point, light, point_400, grip_point,
         __doc__, axes=1, viewup="z", title="RobotArm")
#settings.py
from vedo import *
import numpy as np

point_400 = Point([-500, -500, 0], alpha=0)
light = Point([200, 200, 400], alpha=0)
light2 = Point([200, 200, 800], alpha=0)
forearm_point = Point([-150, -30, 430])
turnTable_point = Point([-150, -180, 130])
middle_point = Point([-150, -250, 210])
grip_point = Point([-150, 255, 300])
gripper1_point = Point()
gripper2_point = Point()

base = load('assets/base.stl')
turnTable = load('assets/turnTable.stl')
middle = load('assets/middel.stl')
forearm = load('assets/forearm2.stl')
grip = load('assets/grip.stl')
gripper1 = load('assets/gripper1.stl')
gripper2 = load('assets/gripper2.stl')

base.c('Black').lighting(roughness=0.8, metallicity=0.1)
turnTable.c('gray').lighting(roughness=0.5, metallicity=0.4)
middle.c('silver').lighting(roughness=0.5, metallicity=0.7)
forearm.c('silver').lighting(roughness=0.3, metallicity=0.7)
grip.c('silver').lighting(roughness=0.5, metallicity=0.7)
gripper1.c('silver').lighting(roughness=0.3, metallicity=0.7)
gripper2.c('silver').lighting(roughness=0.3, metallicity=0.7)

Thats the Robot Arm
image

@marcomusy
Copy link
Owner

Uhm I cannot reproduce your code - may you can try adding plt.process_events() in your rotate() function?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants