# ros2TCP
Creating a bridge between ROS 2 and TCP Socket
## USAGE
Given example for using the library is given below.
### Creating TCP Socket
----
```python
# 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
----
```python
# 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
----
```python
# import server runner
from ros2tcp.plugins import run_server
# Pass the created socket
run_server(socket=server)
```
Raw data
{
"_id": null,
"home_page": "https://github.com/bonnybabukachappilly/ros2tcp",
"name": "ros2tcp",
"maintainer": "",
"docs_url": null,
"requires_python": ">=3.8",
"maintainer_email": "Bonny Babu <bonnybabukachappilly@gmail.com>",
"keywords": "ROS2,Humble,socket,TCP",
"author": "Bonny Babu",
"author_email": "Bonny Babu <bonnybabukachappilly@gmail.com>",
"download_url": "https://files.pythonhosted.org/packages/25/f3/76a28daf47ae20659ce0743ff87a76d3caade253e4cfdddc1f45fa163161/ros2tcp-0.1.2.tar.gz",
"platform": null,
"description": "# ros2TCP\nCreating a bridge between ROS 2 and TCP Socket\n\n## USAGE\nGiven example for using the library is given below.\n\n### Creating TCP Socket\n----\n\n```python\n# Import TCP Socket\nfrom ros2tcp.TCPsocket import TCPSocketServer\n\n# Create socket instance.\nserver = TCPSocketServer()\n\n# Set 'HOST' name and 'PORT'\nserver.HOST = 'localhost'\nserver.PORT = 2040\n```\n\n### Creating ROS service client\n----\n\n```python\n# Import required service type\nfrom ros2tcp.plugins import register_callback, register_service, register_plugin\nfrom std_srvs.srv import SetBool\n\n# Create service request\nrequest = SetBool.Request()\nrequest.data = True\n\n# Register service client\nsrv_1 = register_service(\n n_name='test_node_1',\n s_type=SetBool,\n s_name='test_service',\n req=request\n)\n\nsrv_2 = register_service(\n n_name='test_node_2',\n s_type=SetBool,\n s_name='test_service',\n req=request\n)\n\n# Register callback when response received from the server\n@register_callback\ndef my_callback_1(data):\n # 'data' argument is the response received from the ros service.\n # The data returned here will be send back to the socket client who requested this service.\n return data.message\n\n@register_callback\ndef my_callback_2(_):\n # The data returned here will be send back to the socket client who requested this service.\n return 'done'\n\n# Now map these service client to the plc request.\nserver.operations = register_plugin(\n srv=srv_1,\n cb=my_callback_1,\n key=1 # Whenever socket client sends '1', the 'srv_1' get called.\n)\n\nserver.operations = register_plugin(\n srv=srv_2,\n cb=my_callback_1,\n key=1 # Whenever socket client sends '3', the 'srv_2' get called.\n)\n\n# NOTE: Currently key should be an integer.\n```\n\n### Running the Socket\n----\n\n```python\n# import server runner\nfrom ros2tcp.plugins import run_server\n\n# Pass the created socket\nrun_server(socket=server)\n```\n",
"bugtrack_url": null,
"license": "",
"summary": "A bridge between TCP socket and DDS of ROS 2",
"version": "0.1.2",
"project_urls": {
"Homepage": "https://github.com/bonnybabukachappilly/ros2tcp"
},
"split_keywords": [
"ros2",
"humble",
"socket",
"tcp"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "a737f2e7d5bad3e9009cb9e727fbd41423f0af282a466e76d2dc8a1d09055840",
"md5": "be9b87d61063f273e3ae207f9d215c25",
"sha256": "223278cda226e0ba5d90640dae6697ffa87f29716a862c383e727548859454d4"
},
"downloads": -1,
"filename": "ros2tcp-0.1.2-py3-none-any.whl",
"has_sig": false,
"md5_digest": "be9b87d61063f273e3ae207f9d215c25",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.8",
"size": 20365,
"upload_time": "2023-11-26T15:36:26",
"upload_time_iso_8601": "2023-11-26T15:36:26.615679Z",
"url": "https://files.pythonhosted.org/packages/a7/37/f2e7d5bad3e9009cb9e727fbd41423f0af282a466e76d2dc8a1d09055840/ros2tcp-0.1.2-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "25f376a28daf47ae20659ce0743ff87a76d3caade253e4cfdddc1f45fa163161",
"md5": "65e9403f9168fb3200259239999acfb2",
"sha256": "3ccade961651634cc7dd48fc51c992670f6481acead436eb55fcf68146a6407f"
},
"downloads": -1,
"filename": "ros2tcp-0.1.2.tar.gz",
"has_sig": false,
"md5_digest": "65e9403f9168fb3200259239999acfb2",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.8",
"size": 20717,
"upload_time": "2023-11-26T15:36:28",
"upload_time_iso_8601": "2023-11-26T15:36:28.667365Z",
"url": "https://files.pythonhosted.org/packages/25/f3/76a28daf47ae20659ce0743ff87a76d3caade253e4cfdddc1f45fa163161/ros2tcp-0.1.2.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-11-26 15:36:28",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "bonnybabukachappilly",
"github_project": "ros2tcp",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"tox": true,
"lcname": "ros2tcp"
}