Esempio n. 1
0
int main(int argc, char **argv)
{
  if (argc < 2)
  {
    printf("\nusage: relay IN_TOPIC [OUT_TOPIC]\n\n");
    return 1;
  }
  std::string topic_name;
  if(!getBaseName(string(argv[1]), topic_name))
    return 1;
  ros::init(argc, argv, topic_name + string("_relay"),
            ros::init_options::AnonymousName);
  if (argc == 2)
    g_output_topic = string(argv[1]) + string("_relay");
  else // argc == 3
    g_output_topic = string(argv[2]);
  g_input_topic = string(argv[1]);
  ros::NodeHandle n;
  g_node = &n;
  
  ros::NodeHandle pnh("~");
  bool unreliable = false;
  pnh.getParam("unreliable", unreliable);
  pnh.getParam("lazy", g_lazy);
  if (unreliable)
    g_th.unreliable().reliable(); // Prefers unreliable, but will accept reliable.

  g_sub = new ros::Subscriber(n.subscribe<ShapeShifter>(g_input_topic, 10, &in_cb, g_th));
  ros::spin();
  return 0;
}
Esempio n. 2
0
int main(int argc, char **argv) {
    if (argc < 2) {
        printf("\nusage: relay TOPIC [VARIANT_TOPIC]\n\n");
        return 1;
    }

    if (!getTopicBase((argv[1]), publisherTopic)) {
        ROS_ERROR("Failed to extract topic base from [%s]", argv[1]);
        return 1;
    }

    ros::init(argc, argv, publisherTopic+"_relay",
              ros::init_options::AnonymousName);

    if (argc == 2)
        publisherTopic = std::string(argv[1])+"_relay";
    else
        publisherTopic = argv[2];
    subscriberTopic = argv[1];

    nodeHandle.reset(new ros::NodeHandle("~"));

    bool unreliable = false;
    nodeHandle->getParam("unreliable", unreliable);
    nodeHandle->getParam("lazy", lazy);

    if (unreliable)
        subscriberTransportHints.unreliable().reliable();

    subscribe();
    ros::spin();

    return 0;
}