Robot Example

In this example, you will load a 3D model of a robot into the voraus 3D Visualization, as seen in Fig. 45 and synchronize the joint angle positions with the voraus.core.

Robot model with synchronized joint angle positions

Fig. 45 Robot model with synchronized joint angle positions

As shown in Fig. 46, three services are used in this example: the voraus.core, the voraus 3D Visu, and the voraus-robot-sync service. From the voraus.core, the robot joint angles are read by the voraus-robot-sync service via OPC UA and sent to the voraus 3D Visu service to display the current robot pose.

The architecture of this example

Fig. 46 The architecture of this example

Note

A valid voraus.pioneer or equivalent license and Docker image is required for this example. If you do not have one, please contact the voraus support.

Open the Example in VS Code

Open the folder /examples/robot/ in VS Code, press Ctrl + Shift + P and select Dev Containers: Rebuild and Reopen in Container as shown in Fig. 47. It takes a moment for the dev container to be started.

Open the robot example in a dev container

Fig. 47 Open the robot example in the dev container

Open localhost:8077 in your web browser to display the 3D visualization (see Fig. 48). This is the initial robot position, the joint angles are currently not synchronized.

The 3D visualization with the robot model in vertical position

Fig. 48 The 3D visualization with the robot model in vertical position

Synchronize the Robot Pose

The Python file robot.py loads the 3D model of the robot into the 3D visualization. It establishes a connection via HTTP to the 3D visualization and via OPC UA to the voraus.core. The robot joint angles are cyclically queried from the voraus.core and updated in the 3D visualization. This script runs in its own Docker container as described later. The child names CS0CS5 are the names defined inside the GLB file.

 1"""Example for visualizing a robot."""
 2
 3import time
 4
 5from asyncua.sync import Client
 6
 7from voraus_3d_visu import Visu
 8
 9model = "http://voraus-core/robots/VORAUS_INDUSTRIAL_ROBOT/VORAUS_INDUSTRIAL_ROBOT_002.glb"
10
11
12if __name__ == "__main__":
13    visu = Visu("http://voraus-3d-visu/", clear_all=True)
14    client = Client("opc.tcp://voraus-core:48401/")
15
16    with visu.connection(), client:
17        robot = visu.add_model(model_url=model, position=[0, 0, 0])
18        joint_positions_node = client.get_node("ns=1;i=100111")
19
20        while True:
21            (joint_positions,) = client.read_values([joint_positions_node])
22
23            visu.update(
24                robot.child("CS0").rotation.z(joint_positions[0]),
25                robot.child("CS1").rotation.z(joint_positions[1]),
26                robot.child("CS2").rotation.z(joint_positions[2]),
27                robot.child("CS3").rotation.z(joint_positions[3]),
28                robot.child("CS4").rotation.z(joint_positions[4]),
29                robot.child("CS5").rotation.z(joint_positions[5]),
30            )
31
32            time.sleep(0.01)

Move the Robot

The Python file move.py connects to the voraus.core and defines the home position. It leads to a movement of the robot to the home pose immediately after connecting. It then waits until you press Enter before it performs a linear movement in the positive x-direction.

 1"""Example for moving a robot."""
 2
 3from voraus_robot_arm import JointPose, VorausIndustrialRobotArm, x
 4
 5robot = VorausIndustrialRobotArm()
 6home = JointPose(0, -1.57, 1.57, -1.57, -1.57, 0)
 7
 8if __name__ == "__main__":
 9    robot = VorausIndustrialRobotArm()
10    with robot.connect("voraus-core", port=48401):
11        robot.enable()
12        robot.move_ptp(home).result()
13
14        input("Press enter to move the robot.")
15        robot.move_linear_relative(x(0.2)).result()

Open a terminal in VS Code and start the move.py Python script with the following command, also shown in Fig. 49:

python move.py
Starting the robot example move Python script inside dev container

Fig. 49 Starting the robot example move Python script inside the dev container

The robot will move to the home pose immediately as shown in Fig. 50.

3D visualization with robot in home position

Fig. 50 3D visualization with robot in home position

Press the Enter key to start a linear movement in positive x-direction (see Fig. 51).

The 3D visualization with the robot moved in positive x-direction

Fig. 51 The 3D visualization with the robot moved in positive x-direction

Docker Compose File

Five services (Docker containers) are defined in the docker-compose.yml file. The CodeMeter service is required for licensing the software. The voraus.core service starts a virtual robot backend and the voraus 3D Visu service the web-based 3D visualization backend. The voraus-robot-sync starts the Python script for robot pose synchronization in its own Docker container. The dev container service is intended for development with VS Code. The complete Docker Compose file is shown below.

docker-compose.yml

 1services:
 2  codemeter:
 3    hostname: codemeter
 4    image: docker.io/wibusystems/codemeter:9.10
 5    environment:
 6      CM_REMOTE_SERVER: host.docker.internal
 7    extra_hosts:
 8      - host.docker.internal:host-gateway
 9
10  voraus-core:
11    image: voraus.jfrog.io/docker/voraus-core:2.27.1
12    hostname: voraus-core
13    ports:
14      - 8080:80
15      - 48401:48401
16    environment:
17      CODEMETER_HOST: codemeter
18    depends_on:
19      codemeter:
20        condition: service_healthy
21
22  voraus-3d-visu:
23    image: voraus.jfrog.io/docker/voraus-3d-visu:3.1.2 # x-release-please-version
24    hostname: voraus-3d-visu
25    ports:
26      - 8077:80
27    environment:
28      CODEMETER_HOST: codemeter
29      V3DVISU_ALLOWED_HOSTS: '["voraus-core"]'
30    depends_on:
31      codemeter:
32        condition: service_healthy
33
34  voraus-robot-sync:
35    image: voraus.jfrog.io/docker/voraus-3d-visu-dev-container:3.1.2 # x-release-please-version
36    environment:
37      CODEMETER_HOST: codemeter
38    volumes:
39      - ./:/examples/
40    working_dir: /examples/
41    command: ["python", "robot.py"]
42    depends_on:
43      codemeter:
44        condition: service_healthy
45      voraus-3d-visu:
46        condition: service_healthy
47      voraus-core:
48        condition: service_healthy
49
50  devcontainer:
51    image: voraus.jfrog.io/docker/voraus-3d-visu-dev-container:3.1.2 # x-release-please-version
52    volumes:
53      - .:/home/localuser/workspace:cached
54    command: /bin/sh -c "while sleep 1000; do :; done"
55    environment:
56      CODEMETER_HOST: codemeter
57    depends_on:
58      codemeter:
59        condition: service_healthy
60      voraus-core:
61        condition: service_healthy