Not being able to calculate the height in ardrone gazebo simulator
Hey guys, I am relatively new to ros and c++, i am trying to implement pid controller on ardrone using ros indgio. for doing this I want to calculate(print) the height at which the quadcopter is flying. when I am doing rostopic echo "ardrone_autonomy/Navdata" , i can read the height but when I tried to subscribe to the topic to print the height, I am getting blank in the terminal. following is my code
#include "ros/ros.h"
#include "std_msgs/Empty.h"
#include "ardrone_autonomy/Navdata.h"
#include <iostream>
using namespace std;
class trajectory{
public:
void height(const ardrone_autonomy::Navdata::ConstPtr& hmsg)
{
double x = hmsg->altd; `
(ROS_INFO("HEIGHT IS : %f",x);
}
};
int main(int argc, char **argv)`
{
ros::init(argc, argv, "pid");
ros::NodeHandle n;
ros::Publisher takeoff_pub = n.advertise<std_msgs::Empty>("/ardrone/takeoff", 10);
std_msgs::Empty msg;
ros::Duration(0.5).sleep();
takeoff_pub.publish(msg);
trajectory traj;
ros::Duration(0.3).sleep();
ros::Subscriber sub = n.subscribe("/ardrone_autonomy/Navdata",100,&trajectory::height,&traj);`
ros::spin();
return 0;
}
Thank you