GithubHelp home page GithubHelp logo

Comments (7)

mani-monaj avatar mani-monaj commented on June 4, 2024

That's odd. Is that all your code? Is there any particular reason that you are not using a ROS loop?

from ardrone_autonomy.

dmillard avatar dmillard commented on June 4, 2024

Here's the main method:

ros::init(argc, argv, <nodename>);
ros::NodeHandle n;
ros::Rate loop_rate(10);
ros::Duration(1.0).sleep();

ros::Publisher launch = n.advertise<std_msgs::Empty>("ardrone/takeoff", 5);
ros::Publisher land = n.advertise<std_msgs::Empty>("ardrone/land", 5);
ros::Publisher reset = n.advertise<std_msgs::Empty>("ardrone/reset", 5);
ros::Publisher twist = n.advertise<geometry_msgs::Twist>("cmd_vel", 10);
ros::ServiceClient camchannel = n.serviceClient<ardrone_autonomy::CamSelect("ardrone/setcamchannel");

if(ros::ok()) {
    ardrone_autonomy::CamSelect camsrv;
    camsrv.request.channel = 1;
    camchannel.call(camsrv)
    launch.publish(at.empty_msg)
}

while(ros::ok()) {
    ros::spinOnce()
    loop_rate.sleep()
}

There's also a subscriber and a callback happening that I've left out: the problem existed before and after the subscriber was added. However, I have noticed that the seemingly extraneous ros::Duration(1.0).sleep() statement is actually in the wrong place: it's meant to be after the initialization of the publishers, etc. This was adapted from code with the sleep statement in the "correct" place, that did not have this problem.

I'll check when I have access to the drone and report back tomorrow.

from ardrone_autonomy.

parcon avatar parcon commented on June 4, 2024

Where do you define the empty message? Also, I've found that sending the message for a small period of time gets past that problem. Example code here. Although you can use a much shorter time period as you see fit or watch the state of the robot to know when you can stop sending the takeoff message (much better)

from ardrone_autonomy.

dmillard avatar dmillard commented on June 4, 2024

Moving the sleep statement to in between the publisher initialization and the first message did the trick for me. However, I'll rewrite to check the state of the drone: that seems much more reliable.

Thanks for the help.

from ardrone_autonomy.

walk1ndude avatar walk1ndude commented on June 4, 2024

Also we can use getNumSubscribers() method, like this:

int main(int argc, char **argv) {
...
ros::Publisher takeoff_topic = nh.advertise<std_msgs::Empty>("ardrone/takeoff");
while (takeoff_topic.getNumSubscribers() == 0) {
sleep(1); //sleep a bit
}
takeoff_topic.publish(std_msgs::Empty()); //now we're ready to go

from ardrone_autonomy.

zubair123khan avatar zubair123khan commented on June 4, 2024

I am getting following error :

‘Empty’ is not a member of ‘std_msgs’
ros::Publisher launch = nh.advertise<std_msgs::Empty>("/ardrone/takeoff", 5);

any help please !

from ardrone_autonomy.

xiaoshan-lin avatar xiaoshan-lin commented on June 4, 2024

You should include #include <std_msgs/Empty.h> in your header file

from ardrone_autonomy.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.