How can i subscribe to multiple topics when programming in C++
Hi, I want to subscribe to multiple topics i am trying the following code but doesn't work. #include "ros/ros.h" #include <robot_position num.h="">
float vk; float v ; float va; float a;
void chatterCallback(const Robot_Position::Num::ConstPtr& msg1) {
float v1 = msg1->v1;
float vr = msg1->vr;
va=(v1+vr)/2;}
void chatterCallback2(const Robot_Position::Num::ConstPtr& msg2) {
float a1 = msg2->a1;
float a2 = msg2->a2;
a=(a1+a2)/2;}
int main(int argc, char **argv) {
ros::init(argc, argv, "robot_position");
ros::NodeHandle n;
ros::Subscriber sub = n.subscribe<Robot_Position::Num>("Encoder_vel", 1000, chatterCallback);
ros::NodeHandle n;
ros::Subscriber sub = n.subscribe<Robot_Position::Num>("Accelerometer", 1000, chatterCallback2);
ros::spin();
return 0;
}