Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5

How can robot machine learning be realized with RoboDK API?

#11
(07-20-2023, 10:05 AM)Albert Wrote:You should be able to do both:
  1. Use one instance of RoboDK with multiple API connections (multiple instances of robolink). When you use the same instance of RoboDK, item pointers are exactly the same.
  2. Multiple instances of RoboDK running with one or more API connections each. Make sure you start RoboDK using the -NEWINSTANCE command line option so you open a new instance of RoboDK.

I chose the second method above.

However, although 3 RDKs corresponding to ports (20501, 20502, 20503) should have been started, 3 projects are added to the RDK corresponding to port (20500) which should not be used. I want to fix this bug.

In the code below three RDKs were created.
Code:
NUM_WORKERS = 3
robodk_executable_path = "/home/***/RoboDK/RoboDK-Start.sh"
for env_no in range(1, NUM_WORKERS+1):
api_port = 20500 + env_no
subprocess.Popen(["bash", robodk_executable_path, "-NEWINSTANCE", "-PORT", str(api_port)], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
Next, I planned to add projects to each RDK with the code below, but all projects were added to the RDK of port (20500) which should not exist.
Code:
class RoboController:
def __init__(self, env_no, api_port) -> None:
self.env_no = env_no
self.api_port = api_port
self.RDK = Robolink(args=["-PORT=" + str(self.api_port),])
self.project_directory = os.path.abspath(os.path.dirname(__file__))
self.RDK.AddFile(os.path.join(self.project_directory, "./rdk/Conveying.rdk"))
print(f"RDK.AddFile - RDK: {self.RDK}, API port: {self.api_port}" )
In the terminal display, it seems that projects have been added to the RDKs corresponding to the three ports. But as I wrote above, 3 projects are added to the RDK corresponding to port(20500).
Code:
(RoboController pid=1548973) RDK.AddFile - RDK: , API port: 20502
(RoboController pid=1548972) RDK.AddFile - RDK: , API port: 20501
(RoboController pid=1548974) RDK.AddFile - RDK: , API port: 20503


Attached Files Thumbnail(s)

#12
You should better use the port parameter available on the constructor. Example:
RDK = Robolink(port=20503)

This will make sure the Robolink instance also uses this port.

The port is also an environment variable set by RoboDK as ROBODK_API_PORT when a Python script is executed by RoboDK. This is handled automatically when this environment variable exists.
#13
You should better use the port parameter available on the constructor. Example:

Code:
RDK = Robolink(port=20503)

This will make sure the Robolink instance also uses this port.

The port is also an environment variable set by RoboDK as ROBODK_API_PORT when a Python script is executed by RoboDK. This is handled automatically when this environment variable exists.
#14
(07-24-2023, 05:25 PM)Albert Wrote:You should better use the port parameter available on the constructor. Example:

Code:
RDK = Robolink(port=20503)

This will make sure the Robolink instance also uses this port.

The port is also an environment variable set by RoboDK as ROBODK_API_PORT when a Python script is executed by RoboDK. This is handled automatically when this environment variable exists.
I thought I could start multiple RoboDKs by specifying the port. However, it seems that ports are assigned in the order RoboDK is started. By changing the starting number of "Port range" from '20500' to '20501' as attached, multiple RoboDKs were assigned ports '20501 to 20503'.


Attached Files Thumbnail(s)

#15
The -PORT argument is required when starting RoboDK if you want to specify the port. However, when you start RoboDK from the API it is better to use the port argument so the client API and RoboDK are both using the same port.

If you change the port range settings it allows each instance of RoboDK to use a different port. This port will be used by Python scripts triggered from RoboDK.
#16
(07-25-2023, 07:50 AM)Albert Wrote:The -PORT argument is required when starting RoboDK if you want to specify the port. However, when you start RoboDK from the API it is better to use the port argument so the client API and RoboDK are both using the same port.

If you change the port range settings it allows each instance of RoboDK to use a different port. This port will be used by Python scripts triggered from RoboDK.
I tried various things, but the default port (20500) is set instead of the specified port (here '20503').
Code:
./RoboDK -PORT 20503


- TERMINAL
Code:
Running arguments...
运行参数:“- port”
EXECUTING:"-PORT":...
-PORT:"-1"
Running parameter: "20503"
EXECUTING:"20503":...
Statusbar: "File not found: 20503"
Starting RoboDK API Server
Silent message: "Server is running at localhost:20500"
RoboDK API status: Server is running at localhost:20500
RoboDK is Running...


* Ubuntu22.04, RoboDK 5.6
#17
You should set the port using the equal sign.

Example:

Code:
./RoboDK -PORT=20503
#18
(07-26-2023, 08:32 AM)Albert Wrote:You should set the port using the equal sign.

Example:

Code:
./RoboDK -PORT=20503

nice!

Code:
jellyfish:$ sh /home/ddpg7/RoboDK/RoboDK-Start.sh
API Server Port set to 20503
Trying to run arguments on running instance... ("-PORT=20503")
No running instances of RoboDK detected
Starting RoboDK v 5.6.0 . 23250 ...
OS: LIN64
Date build: Apr 8 2023
Main process ID: 12501
Thread ID: 0x7fb53ce14a00
Processing event...
Starting RobotTools...
Loading settings...
Setting up default settings...
Default settings set
Reading saved settings...
Settings loaded
Statusbar: "Language set to English"
Updating recent files menu...
Created language menu
Setting slider style...
Done
Setting up graphics...
Setting up main window...
Starting main window...
Statusbar: "Loaded 0 plugins"
Reading preferred layout settings...
Done
Closing splash window
Initializing OpenGL...
Initializing OpenGL Functions...
Initializing OpenGL Shaders...
Loading vertex 1
Loading fragment 1
Loading vertex 2
Loading fragment 2
Loading texture vertex 1
Loading texture fragment 1
Shader pointers:
0 1 2 1 0
0 1 2 1 0
3 4 5
0 2 1 0
0 1
OpenGL Ready
Updating window title...
Entering main loop
Running arguments...
Running parameter: "-PORT=20503"
EXECUTING:"-PORT=20503":...
-PORT=20503:"-1"
Starting RoboDK API Server
Silent message: "Server is running at localhost:20503"
RoboDK API status: Server is running at localhost:20503
RoboDK is Running...
But the documentation has space characters on both ends of the '='. I'd better change that.
I think there are people who are addicted to it.


Attached Files Thumbnail(s)

#19
Thank you for reporting this issue. I'm sorry this was confusing. We'll fix this soon.
#20
(07-26-2023, 07:17 PM)Albert Wrote:Thank you for reporting this issue. I'm sorry this was confusing. We'll fix this soon.
Next is another problem.

Above, I was able to start RoboDK even if the port number was not '20500'.

However, if the port number is other than '20500', the "RDK.AddFile()" method throws an error and fails to load the '.rdk' file into the project.

-For port:20500
Code:
New connection from: QHostAddress("127.0.0.1") : 36416
API client says hello: "RDK_API"
Running API Command: "Add"
Loading file: "/home/ddpg7/ws/robodk/conveying/./rdk/Conveying.rdk"
Statusbar: "Loading: /home/ddpg7/ws/robodk/conveying/./rdk/Conveying.rdk"
Using temporary file name to load station: "/tmp/RoboDK.wfeSgr"
Loading: "/home/ddpg7/ws/robodk/conveying/./rdk/Conveying.rdk"
Version Station File 101
Statusbar: "Loading finished."
Loading complete
File loaded
Updating positions and rendering...
Done with API Command: "Add"
Running API Command: "Add"
Updating positions and rendering...
Done with API Command: "Add"
Deleted connection: QTcpSocket(0x55588a4d5e20)
-For port:20501
Code:
New connection from: QHostAddress("127.0.0.1") : 51184
API client says hello: "CMD_START"
Running API Command: "ExecArgs"
Running parameter: "-PORT=20501"
EXECUTING:"-PORT=20501":...
-PORT=20501:"20501"
Updating positions and rendering...
Done with API Command: "ExecArgs"
Deleted connection: QTcpSocket(0x7f0c9c006200)
Here is the test script.
Code:
import os
从robodk。robolink进口robolink

ROBODK_ROOT = '/home/ddpg7/RoboDK'
RDK_FILE_PATH = './rdk/Conveying.rdk'
os.chdir(ROBODK_ROOT + '/bin')

LD_LIBRARY_PATH = os.getcwd() + '/lib'
os.environ['LD_LIBRARY_PATH'] = LD_LIBRARY_PATH

QT_PLUGIN_PATH = os.getcwd() + '/plugins/'
os.environ['QT_PLUGIN_PATH'] = QT_PLUGIN_PATH

QT_QPA_PLATFORM_PLUGIN_PATH = os.getcwd() + '/plugins'
os.environ['QT_QPA_PLATFORM_PLUGIN_PATH'] = QT_QPA_PLATFORM_PLUGIN_PATH

# Specify the desired port number
#port = 20500
port = 20501

# Create a Robolink instance and connect to RoboDK on the specified port
RDK = Robolink(args=f"-PORT={port}")

# Load the .rdk file into the RoboDK project
rdk_file_path = "./rdk/Conveying.rdk"

project_directory = os.path.abspath(os.path.dirname(__file__))
project_directory = os.path.join(project_directory, rdk_file_path)
print(f"Opening station: {project_directory}")
station = RDK.AddFile(project_directory)

try:
RDK.AddFile(rdk_file_path)
except Exception as e:
print(f"Failed to RDK.AddFile: {e}")
RodoDK is starting from terminal.
Code:
- ./RoboDK -NEWINSTANCE -PORT=20500

- ./RoboDK -NEWINSTANCE -PORT=20501


Attached Files Thumbnail(s)





用户browsing this thread:
1 Guest(s)