tum-vision / tum_ardrone

Repository for the tum_ardrone ROS package, implementing autonomous flight with PTAM-based visual navigation for the Parrot AR.Drone.
http://wiki.ros.org/tum_ardrone
GNU General Public License v3.0
226 stars 192 forks source link

Problem in the code #77

Open ahkhan03 opened 8 years ago

ahkhan03 commented 8 years ago

I have written code to issue the command to /tum_ardrone/com topic will running _droneautopilot and _dronestateestimation. I have written followings simple code which just take off and land the drone. When I echoed /tum_ardrone/com while issuing commands through GUI, I found same string commands as given below in the code.

std_msgs::String cpp2ros(std::string in) {
    std_msgs::String out;
    out.data = in;
    return out;
}

int main(int argc, char **argv)
{
    ros::init(argc, argv, "tumdrone");

    ros::NodeHandle tumdrone;

    cv::Mat image = cv::imread("/home/ameerhamzakhan/image.jpg");
    cv::imshow("Image", image);

    ros::Publisher pubCommand = tumdrone.advertise<std_msgs::String>("/tum_ardrone/com", 100);

    char commandKey = 0;

    while(ros::ok()) {
        if(commandKey == 'q') {
            pubCommand.publish(cpp2ros("u l Autopilot: Cleared Command Queue"));

            pubCommand.publish(cpp2ros("u l Autopilot: Start Controlling"));

            pubCommand.publish(cpp2ros("c clearCommands"));

            pubCommand.publish(cpp2ros("c takeoff"));

            pubCommand.publish(cpp2ros("c land"));
        }

        commandKey = cv::waitKey(1);
    }

    return 0;
}

Here I am using openCV image just to monitor 'q' key presses because I find it convenient this way, and it has nothing to do with the rest of code.

ahkhan03 commented 8 years ago

Btw I have found the solution. I forget to issue the following command:

pubCommand.publish(cpp2ros("c start"));