Callback for a Ardrone Navdata Subscriber doesn't work
I want to track the state of the AR Drone. For that, I have created a Subscriber, but for some reason, it doesn't go into my callback function. This is my code:
#include "ros/ros.h"
#include "std_msgs/Empty.h"
#include "std_msgs/String.h"
#include <iostream>
#include <ardrone_autonomy/Navdata.h>
using namespace std;
using namespace ros;
using namespace std_msgs;
//from ardrone_autonomy.msg import Navdata
ardrone_autonomy::Navdata data;
int state;
void receiveNavdata(const ardrone_autonomy::Navdata& data)
{
cout<<"\nIN NAV"<<endl;
cout<<"\nState: "<< data.state<<endl;
state=data.state;
}
int main(int argc, char **argv){
init(argc, argv, "talker");
NodeHandle rospy;
Subscriber navData = rospy.subscribe("/ardrone/navdata", 1, receiveNavdata);
while( state == -1){
ros::spinOnce();
ros::Duration(0.1).sleep();
}
Publisher takeoff = rospy.advertise<Empty>("/ardrone/takeoff", 1);
while(takeoff.getNumSubscribers() < 1){
ros::Duration(0.1).sleep();
}
cout<<"\nTakeOff"<<endl;
takeoff.publish(empty);
ros::Duration(5).sleep();
return 0;
}