initNode function

Future<NodeHandle> initNode (
  1. String name,
  2. List<String> args,
  3. {bool anonymize: false,
  4. String rosMasterUri}
)

Initializes a ros node for this process

There can only be one node per process, if called twice with the same name, returns a handle to the same node

The name of the ros node Any command line arguments args Whether to anonymize the name of the node anonymize Override the ros master uri rosMasterUri

Implementation

Future<NodeHandle> initNode(
  String name,
  List<String> args, {
  bool anonymize = false,
  String rosMasterUri,
}) async {
  if (name.isEmpty) {
    throw Exception('Name must not be empty.');
  }
  // Process command line remappings
  final remappings = processRemapping(args);
  // Initializes the network utils from the remappings
  NetworkUtils.init(remappings);
  // Figures out the node name
  final nodeName = _resolveNodeName(name, remappings, anonymize);
  // Initializes the names in the namespace
  names.init(remappings, nodeName.namespace);
  // If the node has already been created return that node or an error
  if (Node.singleton != null) {
    if (nodeName.name == Node.singleton.nodeName) {
      return nh;
    } else {
      // Node name doesn't match, can't init another node with a different name in the same process
      throw Exception(
          'Unable to initialize ${nodeName.name} - node ${Node.singleton.nodeName} already exists');
    }
  }
  log.initializeNodeLogger(nodeName.name);
  final masterUri = rosMasterUri ??
      remappings['__master'] ??
      Platform.environment['ROS_MASTER_URI'];
  final node = Node(nodeName.name, masterUri);
  await node.nodeReady.future;
  await Logger.initializeRosLogger();
  await Time.initializeRosTime();
  return NodeHandle(node);
}