Coder Social home page Coder Social logo

ros_nodes's Introduction

Library template made by Stagehand under a BSD-style license.

Usage

A simple subscriber example:

import 'package:ros_nodes/messages/std_msgs/String.dart';
import 'package:ros_nodes/ros_nodes.dart';

void main() async {
  var config = RosConfig(
    'ros_nodes_example_node',
    'http://192.168.1.12:11311/',
    '192.168.1.12',
    24125,
  );
  var client = RosClient(config);
  var msg = StdMsgsString();
  var topic = RosTopic('chatter', msg);
  await client.unsubscribe(topic);

  var subscriber = await client.subscribe(topic);
  subscriber.onValueUpdate.listen((type) => print('Listener 1: ${type.data}'));
  subscriber.onValueUpdate.listen((_) => print('Listener 2: ${msg.data}'));
}

onValueUpdate is broadcast Stream. This stream emmits suppplied RosMessage as stream parameter, so we don't need to save it as a variable.

subscriber.onValueUpdate.listen((type) => print('Listener 1: ${type.data}'));
subscriber.onValueUpdate.listen((_) => print('Listener 2: ${msg.data}'));

It's important to say, that supplied RosMessage object, here StdMsgsString, is used as container for all data changes, both for publishing and getting data from other nodes. That's why both listeners will print the same data, both approaches are consider valid.

A simple publisher example:

import 'dart:async';
import 'package:ros_nodes/messages/std_msgs/String.dart';
import 'package:ros_nodes/ros_nodes.dart';

void main() async {
  var config = RosConfig(
    'ros_nodes_example_node',
    'http://192.168.1.12:11311/',
    '192.168.1.12',
    24125,
  );
  var client = RosClient(config);
  var topic = RosTopic('chatter', StdMsgsString());
  await client.unregister(topic);

  var publisher = await client.register(topic,
      publishInterval: Duration(milliseconds: 1000));

  var i = 0;
  Timer.periodic(
    Duration(milliseconds: 500),
    (_) {
      i += 1;
      topic.msg.data = i.toString();
    },
  );
}

By default RosPublisher will send updates every second. To change the interval you need to supply publishInterval parameter.

var i = 0;
Timer.periodic(
  Duration(milliseconds: 500),
  (_) {
    i += 1;
    topic.msg.data = i.toString();
  },
);

To change the published data we operate on supplied RosMessage type, in this case it's StdMsgsString.

All currently implemented messages are placed in lib/messages, where direct .dart files are wrappers for base type messages like RosString in String.dart file, and subfolders are meant for published messages like tf/tfMessage.dart as TfTfMessage or std_msgs/String.dart for aforementioned StdMsgsString.

Features and bugs

Please file feature requests and bugs at the issue tracker.

ros_nodes's People

Contributors

sashiri avatar rongix avatar yungkk98 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.