Creating publisher or subscriber and passing CallBack in ROS 2
Hello ,
Earlier we did
ros::Publisher pub_name;
ros::Subscriber sub_name:
ros::NodeHandle nh;
However now after checking the Migration Guide :
I wanted to create couple of publishers in my class, using rclcpp guide
like:
rclcpp::Subscription<std_msgs::msg::String>::SharedPtr sub; <--- (not sure about this method)
or,
auto node = rclcpp::node::Node::make_shared("talker");
auto chatter_pub = node->create_publisher<std_msgs::msg::String>("chatter", rmw_qos_profile_default);
Which is fine. However is it the only way to create a publishers or subscribers. Can't I just declare the subscriber without stating the message type as earlier in ROS 1.0? example:
Class:
ros::Subscriber sub_;
ros:Publisher pub1, pub2;
ros::NodeHandle nh;
Library:
sub_=nh.subscribe("topic_name_sub_", 1,&Class_Name::Callback_, this);
pub1_=nh.advertise < std_msgs::String> ("topic_name_pub1", 10);
pub2_=nh.advertise < std_msgs::Int8> ("topic_name_pub2", 10);
.
.
.
.
Callback();
Also how to have callback functions to my subscriber or publisher?
Kindly advise.
I guess you mean "in ROS 1", as what you show was never supported in ROS 2 afaik.
yes sorry for the typo, i have edited my question