Skip to content

Commit 09c3a85

Browse files
urrskurmahp
andauthored
Adding Simple external control server example (#22)
* Adding Simple external control server example Adding a python3 server script that can be used to serve the URCap. Co-authored-by: mahp <[email protected]>
1 parent 2be1498 commit 09c3a85

File tree

3 files changed

+78
-0
lines changed

3 files changed

+78
-0
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Simple External Control Server example
2+
3+
This simple server, serves the External Control with URScript provided by a file
4+
5+
Example of use:
6+
7+
```bash
8+
python3 simple_external_control_server.py hello_world.script
9+
```
10+
11+
To install and use the URCap external control, follow the instructions from the ROS Driver for [e-Series](https://github.com/UniversalRobots/Universal_Robots_ROS_Driver/blob/master/ur_robot_driver/doc/install_urcap_e_series.md)
12+
or for [cb3-Series](https://github.com/UniversalRobots/Universal_Robots_ROS_Driver/blob/master/ur_robot_driver/doc/install_urcap_cb3.md).
13+
14+
Once you play the program on a robot, a popup with the message "Hello World" should appear.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
popup("Hello world")
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
#!/usr/bin/env python3
2+
3+
# // -- BEGIN LICENSE BLOCK ----------------------------------------------
4+
# // Copyright 2021 Universal Robots A/S
5+
# //
6+
# // Licensed under the Apache License, Version 2.0 (the "License");
7+
# // you may not use this file except in compliance with the License.
8+
# // You may obtain a copy of the License at
9+
# //
10+
# // http://www.apache.org/licenses/LICENSE-2.0
11+
# //
12+
# // Unless required by applicable law or agreed to in writing, software
13+
# // distributed under the License is distributed on an "AS IS" BASIS,
14+
# // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
# // See the License for the specific language governing permissions and
16+
# // limitations under the License.
17+
# // -- END LICENSE BLOCK ------------------------------------------------
18+
19+
# A simple python 3 server to test the External Control URCap
20+
# The server answer request from the URCap with the context of the given file
21+
22+
import socket
23+
import socketserver
24+
import threading
25+
import argparse
26+
27+
parser = argparse.ArgumentParser(description='Simple External Control server')
28+
parser.add_argument(
29+
"file", type=str, help="Path to the UR script file, which will be sent to the robot")
30+
parser.add_argument("-p", "--port", type=int,
31+
default=50002, help="Port number to use")
32+
33+
args = parser.parse_args()
34+
35+
36+
class ThreadedTCPServer(socketserver.ThreadingMixIn, socketserver.TCPServer):
37+
daemon_threads = True
38+
allow_reuse_address = True
39+
40+
41+
class FileHandler(socketserver.StreamRequestHandler):
42+
def handle(self):
43+
client = f'{self.client_address} on {threading.currentThread().getName()}'
44+
print(f'Connected: {client}')
45+
file = open(args.file, "r")
46+
while True:
47+
data = file.read()
48+
49+
print(data)
50+
if not data:
51+
break
52+
self.wfile.write(data.encode('utf-8'))
53+
print(f'Closed: {client}')
54+
55+
56+
with ThreadedTCPServer(('', args.port), FileHandler) as server:
57+
print(f'The Simple External Control server is running on port', args.port)
58+
try:
59+
server.serve_forever()
60+
except KeyboardInterrupt:
61+
pass
62+
63+
server.server_close()

0 commit comments

Comments
 (0)