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.
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())