"""Example for visualizing a robot."""

import time

from asyncua.sync import Client

from voraus_3d_visu import Visu

model = "http://voraus-core/robots/VORAUS_INDUSTRIAL_ROBOT/VORAUS_INDUSTRIAL_ROBOT_002.glb"


if __name__ == "__main__":
    visu = Visu("http://voraus-3d-visu/", clear_all=True)
    client = Client("opc.tcp://voraus-core:48401/")

    with visu.connection(), client:
        robot = visu.add_model(model_url=model, position=[0, 0, 0])
        joint_positions_node = client.get_node("ns=1;i=100111")

        while True:
            (joint_positions,) = client.read_values([joint_positions_node])

            visu.update(
                robot.child("CS0").rotation.z(joint_positions[0]),
                robot.child("CS1").rotation.z(joint_positions[1]),
                robot.child("CS2").rotation.z(joint_positions[2]),
                robot.child("CS3").rotation.z(joint_positions[3]),
                robot.child("CS4").rotation.z(joint_positions[4]),
                robot.child("CS5").rotation.z(joint_positions[5]),
            )

            time.sleep(0.01)
