Skip to main content

ros2TCP

Creating a bridge between ROS 2 and TCP Socket

USAGE

Given example for using the library is given below.

Creating TCP Socket


# Import TCP Socket
from ros2tcp.TCPsocket import TCPSocketServer

# Create socket instance.
server = TCPSocketServer()

# Set 'HOST' name and 'PORT'
server.HOST = 'localhost'
server.PORT = 2040

Creating ROS service client


# Import required service type
from ros2tcp.plugins import register_callback, register_service, register_plugin
from std_srvs.srv import SetBool

# Create service request
request = SetBool.Request()
request.data = True

# Register service client
srv_1 = register_service(
    n_name='test_node_1',
    s_type=SetBool,
    s_name='test_service',
    req=request
)

srv_2 = register_service(
    n_name='test_node_2',
    s_type=SetBool,
    s_name='test_service',
    req=request
)

# Register callback when response received from the server
@register_callback
def my_callback_1(data):
    # 'data' argument is the response received from the ros service.
    # The data returned here will be send back to the socket client who requested this service.
    return data.message

@register_callback
def my_callback_2(_):
    # The data returned here will be send back to the socket client who requested this service.
    return 'done'

# Now map these service client to the plc request.
server.operations = register_plugin(
    srv=srv_1,
    cb=my_callback_1,
    key=1 # Whenever socket client sends '1', the 'srv_1' get called.
)

server.operations = register_plugin(
    srv=srv_2,
    cb=my_callback_1,
    key=1 # Whenever socket client sends '3', the 'srv_2' get called.
)

# NOTE: Currently key should be an integer.

Running the Socket


# import server runner
from ros2tcp.plugins import run_server

# Pass the created socket
run_server(socket=server)

Metadata

Release files for ros2tcp 0.1.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for ros2tcp 0.1.2
File Size Uploaded
ros2tcp-0.1.2.tar.gz 20.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for ros2tcp 0.1.2
File Interpreter ABI Platform
ros2tcp-0.1.2-py3-none-any.whl Python 3 none any Details

Total release size: 41.1 kB

Release files / ros2tcp-0.1.2.tar.gz

Download URL ros2tcp-0.1.2.tar.gz
Size 20.7 kB
Tags Source
SHA-256 checksum
How to use checksums
3ccade961651634cc7dd48fc51c992670f6481acead436eb55fcf68146a6407f
BLAKE2b-256 checksum
How to use checksums
25f376a28daf47ae20659ce0743ff87a76d3caade253e4cfdddc1f45fa163161
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.10.12

Release files / ros2tcp-0.1.2-py3-none-any.whl

Download URL ros2tcp-0.1.2-py3-none-any.whl
Size 20.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
223278cda226e0ba5d90640dae6697ffa87f29716a862c383e727548859454d4
BLAKE2b-256 checksum
How to use checksums
a737f2e7d5bad3e9009cb9e727fbd41423f0af282a466e76d2dc8a1d09055840
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.10.12

Release history Release notifications | RSS feed

This release

0.1.2 This release

2 release files

0.1.1

2 release files

0.1

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page