コード例 #1
0
    def init_connection(self):
        # initiate logging
        # zenoh.init_logger()

        L.warning("[ZENOH] Openning session...")
        self.z_session = Zenoh(self.conf)

        L.warning("[ZENOH] Create New workspace...")
        self.workspace = self.z_session.workspace()
コード例 #2
0
def main(address, selector):
    # client configuration
    conf = {
        'mode': 'client',
        'peer': '{}'.format(address),
    }

    print("Openning session...")
    zenoh = Zenoh(conf)

    print("New workspace...")
    workspace = zenoh.workspace()

    # getting the data from zenoh, it can come from a storage or an eval
    print("Get Data from '{}'...".format(selector))

    output_data = []
    for data in workspace.get(selector):
        _, _, m, s, n = data.path.split('/')
        m = int(m)
        s = int(s)
        n = int(n)
        output_entry = {
            'm': m,
            's': s,
            'n': n,
            'value': data.value.get_content(),
            'timestamp': data.timestamp
        }
        output_data.append(output_entry)

    sorted_output_data = sorted(output_data, key=lambda k: k['n'])

    for data in sorted_output_data:
        print(data)

    zenoh.close()
コード例 #3
0
if __name__ == "__main__":
    if len(sys.argv) < 5:
        print(
            "Usage <address of zenohd router> <rostopic> <rostopic hz> <replay secs>"
        )
    address = sys.argv[1]
    rostopic = sys.argv[2]
    sample_rate = int(sys.argv[3])
    duration = int(sys.argv[4])

    conf = {
        'mode': 'client',
        'peer': '{}'.format(address),
    }

    print("Opening Zenoh session...")
    zenoh = Zenoh(conf)
    print(
        "Server connected to Zenoh router {}, publishing on rostopic {}, at rate {}"
        .format(address, rostopic, sample_rate))
    # Zenoh workspace creation
    print("New Zenoh workspace...")
    workspace = zenoh.workspace(storage_path)

    app = create_app(workspace, rostopic, sample_rate, duration)
    app.register_blueprint(route_blueprint)
    app.run(host='0.0.0.0', port=5000, debug=True)

    # Shutting down Zenoh
    zenoh.close()
コード例 #4
0
    if len(res) > 0 and res[0] == 'y':
        torch.save(
            global_model.state_dict(), 'global.pt'
        )  # be aware that this can overwrite a smarter model if this application is stopped and restarted
    else:
        global_model.load_state_dict(torch.load('global.pt'))
else:
    torch.save(
        global_model.state_dict(), 'global.pt'
    )  # be aware that this can overwrite a smarter model if this application is stopped and restarted

# initiate logging
zenoh.init_logger()

print("Opening session...")
z = Zenoh(conf)

print("New workspace...")
workspace = z.workspace()

# 0 - Put global model to a path where clients can get it
print("Put global model in /federated/nodes/global")
save_and_put_global_parameters(global_model.state_dict())

# 1 - Listen for notifications
notification_selector = selector + '/notifications'
print("Subscribed to '{}'...".format(notification_selector))
notification_subscriber = workspace.subscribe(notification_selector,
                                              notification_listener)

print("Press q to stop...")
コード例 #5
0
from zenoh import Zenoh

if __name__ == "__main__":
    z = Zenoh({})
    w = z.workspace('/')
    results = w.get('/myhome/kitcken/temp')
    key, value = results[0].path, results[0].value
    print('  {} : {}'.format(key, value))
コード例 #6
0
def main(stdscr):
    # --- Command line argument parsing --- --- --- --- --- ---
    parser = argparse.ArgumentParser(prog='zn_sub',
                                     description='zenoh-net sub example')
    parser.add_argument('--mode',
                        '-m',
                        dest='mode',
                        choices=['peer', 'client'],
                        type=str,
                        help='The zenoh session mode.')
    parser.add_argument(
        '--peer',
        '-e',
        dest='peer',
        metavar='LOCATOR',
        action='append',
        type=str,
        help='Peer locators used to initiate the zenoh session.')
    parser.add_argument('--listener',
                        '-l',
                        dest='listener',
                        metavar='LOCATOR',
                        action='append',
                        type=str,
                        help='Locators to listen on.')
    parser.add_argument('--config',
                        '-c',
                        dest='config',
                        metavar='FILE',
                        type=str,
                        help='A configuration file.')
    parser.add_argument('--cmd_vel',
                        dest='cmd_vel',
                        default='/rt/turtle1/cmd_vel',
                        type=str,
                        help='The "cmd_vel" ROS2 topic.')
    parser.add_argument('--rosout',
                        dest='rosout',
                        default='/rt/rosout',
                        type=str,
                        help='The "rosout" ROS2 topic.')
    parser.add_argument('--angular_scale',
                        '-a',
                        dest='angular_scale',
                        default='2.0',
                        type=float,
                        help='The angular scale.')
    parser.add_argument('--linear_scale',
                        '-x',
                        dest='linear_scale',
                        default='2.0',
                        type=float,
                        help='The linear scale.')

    args = parser.parse_args()
    conf = zenoh.config_from_file(
        args.config) if args.config is not None else {}
    if args.mode is not None:
        conf["mode"] = args.mode
    if args.peer is not None:
        conf["peer"] = ",".join(args.peer)
    if args.listener is not None:
        conf["listener"] = ",".join(args.listener)
    cmd_vel = args.cmd_vel
    rosout = args.rosout
    angular_scale = args.angular_scale
    linear_scale = args.linear_scale

    # zenoh-net code  --- --- --- --- --- --- --- --- --- --- ---

    # initiate logging
    zenoh.init_logger()

    print("Openning session...")
    z = Zenoh(conf)
    workspace = z.workspace()

    def rosout_callback(change):
        if change.value is not None:
            log = Log.deserialize(change.value.get_content())
            print('[{}.{}] [{}]: {}'.format(log.stamp.sec, log.stamp.nanosec,
                                            log.name, log.msg))

    print("Subscriber on '{}'...".format(rosout))
    sub = workspace.subscribe(rosout, rosout_callback)

    def pub_twist(linear, angular):
        print("Pub twist: {} - {}".format(linear, angular))
        t = Twist(linear=Vector3(x=linear, y=0.0, z=0.0),
                  angular=Vector3(x=0.0, y=0.0, z=angular))
        workspace.put(cmd_vel, t.serialize())

    while True:
        c = stdscr.getch()
        if c == curses.KEY_UP:
            pub_twist(1.0 * linear_scale, 0.0)
        elif c == curses.KEY_DOWN:
            pub_twist(-1.0 * linear_scale, 0.0)
        elif c == curses.KEY_LEFT:
            pub_twist(0.0, 1.0 * angular_scale)
        elif c == curses.KEY_RIGHT:
            pub_twist(0.0, -1.0 * angular_scale)
        elif c == 27 or c == ord('q'):
            break

    sub.close()
    zenoh.close()