ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | Q&A
Ask Your Question

Not being able to calculate the height in ardrone gazebo simulator

asked 2017-02-28 13:54:41 -0600

hpurohit gravatar image

updated 2017-02-28 14:37:21 -0600

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{
  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;
  trajectory traj;
  ros::Subscriber sub = n.subscribe("/ardrone_autonomy/Navdata",100,&trajectory::height,&traj);` 
  return 0; 

Thank you

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2017-02-28 16:37:56 -0600

hpurohit gravatar image

ok so I figured it out, i made a rookie programming error, i was subscribing to wrong topic /ardrone_autonomy/Navdata which should be /ardrone/navdata. Now its working smoothly

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2017-02-28 13:54:41 -0600

Seen: 148 times

Last updated: Feb 28 '17