Ask Your Question
0

How can I store the AR.Drone's height in order to control it?

asked 2013-07-20 07:08:32 -0500

Pedro_85 gravatar image

updated 2014-01-28 17:17:20 -0500

ngrennan gravatar image

I am trying to get the int32 message published in /ardrone/navdata/altd in order to control the ARDrone's height. Here is the code I have:

#include <ros/ros.h>
#include "std_msgs/Int32.h"

using namespace std;

void heightControl(const std_msgs::Int32::ConstPtr& height)
{
  cout << height << endl;
}

from ardrone_autonomy.msg import Navdata

int main(int argc, char **argv)
{
  ros::init(argc,argv,"Height_Control");
  ros::NodeHandle n;
  ros::Subscriber sub = n.subscribe("ardrone/navdata/altd", 1, heightControl);
  ros::spin();
  return 0;
}

When I run this, the altitude value is not shown in the terminal screen. However, if I do rostopic echo /ardrone/navdata/altd I do get the height shown in the terminal window. Using rosmsg show ardrone_autonomy/Navdata I can see that altd is type int32.

edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted
0

answered 2013-09-25 08:12:34 -0500

Pedro_85 gravatar image

I was able to do it following these steps:

1) Added to the manifest file the dependency: <depend package="ardrone_autonomy" />

2) Fixed the code in the following way:

#include <ros/ros.h>
#include "std_msgs/Int32.h"
#include "std_msgs/Float32.h"
#include "ardrone_autonomy/Navdata.h"

using namespace std;
ardrone_autonomy::Navdata msg_in;
float drone_altd;

void heightControl(const ardrone_autonomy::Navdata& msg_in)
{
  drone_altd=msg_in.altd;
  cout << drone_altd << endl;
}

int main(int argc, char **argv)
{
  ros::init(argc,argv,"Altitude_Control");
  ros::NodeHandle n;
  ros::Subscriber sub = n.subscribe("/ardrone/navdata", 1, heightControl);
  ros::spin();
  return 0;
}

I hope this helps.

edit flag offensive delete link more

Comments

ok thanks its fine, but what shall i do when i am not getting any value when subscribing to that topic and looking for "altd" i.e., i am just getting as zero.

please help me in this

saikishor gravatar imagesaikishor ( 2015-04-08 05:29:43 -0500 )edit

Was the drone flying when you looked at altd? The AR.Drone won't publish the altd value unless its flying.

Pedro_85 gravatar imagePedro_85 ( 2015-04-08 08:24:50 -0500 )edit

the value of altd is zero even in air and landed and in both i am getting the value as zero so what should i do now i had another drone i tried it with too but i ended up with value zero in that drone also...

in case if it publishes when flying, how to access that (i will check whether i did same)

saikishor gravatar imagesaikishor ( 2015-04-08 14:28:58 -0500 )edit
1

Odd. It seems like you will need to rebuild your package. I've been using ardrone_autonomy in fuerte, groovy, and hydro with no problems. How did you install it?

Pedro_85 gravatar imagePedro_85 ( 2015-04-08 15:07:28 -0500 )edit

I have installed it in ROS Indigo and it also working well i mean rest of the things. so what should i do now @Pedro_85 Is there any way to do that?? please help me sir....

saikishor gravatar imagesaikishor ( 2015-04-09 03:31:14 -0500 )edit

Are you using the coe above to get this measurements or rostopic echo /ardrone/navdata? I strongly recommend performing an update to your ardrone_autonomy package with git pull and recompiling it.

Pedro_85 gravatar imagePedro_85 ( 2015-04-09 10:37:46 -0500 )edit

I am using rostopic echo /ardrone/navdata to get the altd value @Pedro_85

saikishor gravatar imagesaikishor ( 2015-04-09 10:54:39 -0500 )edit

It worked for me and i am getting altitude value @Pedro_85 Thank you...

saikishor gravatar imagesaikishor ( 2015-04-21 06:03:59 -0500 )edit

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

Stats

Asked: 2013-07-20 07:08:32 -0500

Seen: 1,488 times

Last updated: Sep 25 '13