Skip to content

klpanagi/ros2broker

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

29 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ros2broker

ROS/ROS2 to AMQP (Rabbitmq) protocol connectors

executor

CLI Usage

First create a model as defined by the language. An example model can be found here.

Generator

Run the generator (bin/ros2broker)

./ros2broker gen --model-file <PATH_TO_MODEL_FILE>

Executor

./ros2broker run --model-file <PATH_TO_MODEL_FILE>

Examples

Example 1 - Dynamically create and run model instances from input model file

from __future__ import (
    absolute_import,
    division,
    print_function,
    unicode_literals
)

import sys

from ros2broker import (
    ConnectorThreadExecutor,
    YAMLParser
)


def main():
    model_path = ''
    if len(sys.argv) < 2:
        model_path = 'example_model.yaml'
    else:
        model_path = sys.argv[1]
    c_list = YAMLParser.load(model_path)
    executor = ConnectorThreadExecutor()
    for c in c_list:
        executor.run_connector(c)

    try:
        executor.run_forever()
    except Exception as exc:
        sys.exit(1)


if __name__ == "__main__":
    main()

Example 2 - Dynamically create and run model instances programmatically

The below example creates a Sub and a Pub Connector and runs them in an Executor.

#!/usr/bin/python2

from ros2broker import (
    PubConnector, ROSPubEndpoint, BrokerPubEndpoint,
    SubConnector, ROSSubEndpoint, BrokerSubEndpoint,
    RPCConnector, ROSServiceEndpoint, BrokerRPCEndpoint,
    BrokerAuthPlain, BrokerDefinition,
    ConnectorThreadExecutor
)

import sys


def main():
    broker = BrokerDefinition(
        name=None,
        host='155.207.33.189',
        port='5672',
        vhost='/',
        global_ns=''
    )

    ros_ep_1 = ROSPubEndpoint(
        msg_type='std_msgs/String',
        uri='/test_pub_con',
        name='test_pub_con'
    )

    broker_ep_1 = BrokerPubEndpoint(
        uri='test_pub_con',
        name='test_pub_con',
        broker_ref=broker,
        auth=BrokerAuthPlain(username='bot', password='b0t')
    )

    ros_ep_2 = ROSSubEndpoint(
        msg_type='std_msgs/String',
        uri='/test_sub_con',
        name='test_sub_con'
    )

    broker_ep_2 = BrokerSubEndpoint(
        uri='test_sub_con',
        name='test_sub_con',
        broker_ref=broker,
        auth=BrokerAuthPlain(username='bot', password='b0t')
    )

    ros_ep_3 = ROSServiceEndpoint(
        srv_type='std_srvs/Empty',
        uri='/test_srv_con',
        name='test_srv_con'
    )

    broker_ep_3 = BrokerRPCEndpoint(
        uri='test_srv_con',
        name='test_srv_con',
        broker_ref=broker,
        auth=BrokerAuthPlain(username='bot', password='b0t')
    )

    pc = PubConnector(ros_ep_1, broker_ep_1)
    sc = SubConnector(ros_ep_2, broker_ep_2)
    rpc_con = RPCConnector(ros_ep_3, broker_ep_3)

    executor = ConnectorThreadExecutor()
    executor.run_connector(pc)
    executor.run_connector(sc)
    executor.run_connector(rpc_con)

    executor.run_forever()


if __name__ == "__main__":
    main()

The example can also be found here.

Example 3 - Generate bridge from input model file

from __future__ import (
    absolute_import,
    division,
    print_function,
    unicode_literals
)

import sys

from ros2broker import (
    BridgeGenerator
)


def main():
    model_path = ''
    if len(sys.argv) < 2:
        model_path = 'example_model.yaml'
    else:
        model_path = sys.argv[1]
    bgen = BridgeGenerator()
    bgen.gen_from_yaml(model_path)


if __name__ == "__main__":
    main()

About

Bridging ROS to Brokered Systems

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages