Python Add-on to get current robot joint angles

Hello

I am new to the VC community and KukaSim.

I have a Kuka robot in my workspace and wanted to know how I can have a python program to get the joint angles of the robot selected.

Hoping to output the joint angles constantly as the robot moves

Could you help in pointing to what python methods are available and how to access it

image

Not sure if this works in KUKA Simpro, in Visual Components you only need a bit of code to get a joint value.

comp = getComponent()
node = comp.findNode('Axis 1')
print node.Dof.VALUE

what module would I have to import for the above please? and can I have the script in MyCommands as an Add-on?

Ideally I want to use make the joint values accessible by an external client.

And how do i make it constantly loop and output the joint values as the robot moves (i.e program is exectued)

This is just a Python script for the MODELING module, if you need to connect externally (I’m going to assume you want to connect to the PLC), and if you can turn on the Connectivity feature (which is turned off by default, and needs to be turned on in Options) you can use protocols such as OPC UA to connect the joint value data directly to an external variable, no additional programming is required.

If what you need is to connect to a KUKA robot controller, you can refer to a video similar to this one.

Thanks for your reply again,

I am not trying to connect to a PLC or an external KUKA system, I am just trying to expose the joint angles to be used by another bespoke system.

I tried connecting a python OPCUA server to the OPCUA client from the Connectivity Add-On. But I am not sure how to pair and read the values from the variable (i.e. the A1 VALUE which holds the joint angles)

my rough python script to get a OPCUA server is below, this script is running independent and not in Visual Components, I am trying to access the joint angles from Visual Components and print it from the external script through OPCUA

# OPC-UA Server

import asyncio
import random
from asyncua import ua, Server
import logging

logging.basicConfig(level=logging.INFO)
_logger = logging.getLogger('asyncua')


async def main():
    # setup our server
    server = Server()
    await server.init()
    server.set_endpoint('opc.tcp://localhost:4840/freeopcua/server/')
    server.set_server_name("OPC-UA Test Server")

    idx = await server.register_namespace("ns")

    obj = await server.nodes.objects.add_object(idx, 'vTestObject')

    var_joint1 = await obj.add_variable(idx, 'JointA1', 0.0)
    var_joint2 = await obj.add_variable(idx, 'JointA2', 0.0)

    _logger.info("starting server...")
    url = "opc.tcp://localhost:4840/freeopcua/server/"
    async with server:
        while True:
            # await var_joint1.write_value(random.uniform(25, 35))
            # await var_joint2.write_value(random.uniform(55, 75))

            # Insert code to read Joint angles from KUKA robot in KUKA sim through OPCUA

            await asyncio.sleep(0.1)


if __name__ == '__main__':
    asyncio.run(main())

ConnectionToOPCUAserver

Maybe this video can help; its about WinMod but should be similar for OPCUA KUKA.Sim Tutorial - Connectivity Add-On: Winmod mit einem Roboter verwenden (youtube.com)