test_fly.cpp
Go to the documentation of this file.
00001 /*
00002 Parker Conroy
00003 Algorithmic Robotics Lab @ University of Utah
00004 
00005 This code sends simple commands to fly the AR Drone. 
00006 It is intended as a simple example for those starting with the AR Drone platform.
00007 */
00008 #include <ros/ros.h>
00009 #include <std_msgs/Empty.h>
00010 #include <geometry_msgs/Twist.h>
00011 
00012         geometry_msgs::Twist twist_msg;
00013         geometry_msgs::Twist twist_msg_hover;
00014         geometry_msgs::Twist twist_msg_pshover;
00015         std_msgs::Empty emp_msg;
00016         
00017 
00018 int main(int argc, char** argv)
00019 {
00020 
00021         printf("Manual Test Node Starting");
00022         ros::init(argc, argv,"ARDrone_manual_test");
00023     ros::NodeHandle node;
00024     ros::Rate loop_rate(50);
00025 
00026         ros::Publisher pub_empty_land;
00027         ros::Publisher pub_twist;
00028         ros::Publisher pub_empty_takeoff;
00029         ros::Publisher pub_empty_reset;
00030         double time;
00031 
00032 //hover message
00033                         twist_msg_hover.linear.x=0.0; 
00034                         twist_msg_hover.linear.y=0.0;
00035                         twist_msg_hover.linear.z=0.0;
00036                         twist_msg_hover.angular.x=0.0; 
00037                         twist_msg_hover.angular.y=0.0;
00038                         twist_msg_hover.angular.z=0.0;  
00039 
00040 //psudo-hover message
00041                         twist_msg_pshover.linear.x=0.00001; // lowest value for psudo hover to work
00042                         twist_msg_pshover.linear.y=0.0;
00043                         twist_msg_pshover.linear.z=0.0;
00044                         twist_msg_pshover.angular.x=0.0; 
00045                         twist_msg_pshover.angular.y=0.0;
00046                         twist_msg_pshover.angular.z=0.0; 
00047 
00048 //command message
00049                         float fly_time=9.0;
00050                         float land_time=5.0;
00051                         float kill_time =2.0;   
00052 
00053                         twist_msg.linear.x=0.0; 
00054                         twist_msg.linear.y=-0.0001;
00055                         twist_msg.linear.z=0.0;
00056                         twist_msg.angular.x=0.0; 
00057                         twist_msg.angular.y=0.0;
00058                         twist_msg.angular.z=0.0;
00059 
00060 
00061         
00062     pub_twist = node.advertise<geometry_msgs::Twist>("/cmd_vel", 1); /* Message queue length is just 1 */
00063         pub_empty_takeoff = node.advertise<std_msgs::Empty>("/ardrone/takeoff", 1); /* Message queue length is just 1 */
00064         pub_empty_land = node.advertise<std_msgs::Empty>("/ardrone/land", 1); /* Message queue length is just 1 */
00065 pub_empty_reset = node.advertise<std_msgs::Empty>("/ardrone/reset", 1); /* Message queue length is just 1 */
00066 
00067         
00068         time =(double)ros::Time::now().toSec(); 
00069         ROS_INFO("Starting ARdrone_test loop");
00070 
00071 
00072 while (ros::ok()) {
00073                 
00074                 if (     (double)ros::Time::now().toSec()< time+5.0){
00075                 
00076                         pub_empty_takeoff.publish(emp_msg); //launches the drone
00077                         pub_twist.publish(twist_msg_hover); //drone is flat
00078                         ROS_INFO("Taking off");
00079                         }//takeoff before t+5
00080 
00081                 else if (        (double)ros::Time::now().toSec()> time+fly_time+land_time+kill_time){
00082                 
00083                         ROS_INFO("Closing Node");
00084                         pub_empty_reset.publish(emp_msg); //kills the drone             
00085                         break; 
00086                         
00087                         }//kill node
00088 
00089                 else if (        ((double)ros::Time::now().toSec()> time+fly_time+land_time)){
00090                 
00091                         pub_twist.publish(twist_msg_hover); //drone is flat
00092                         pub_empty_land.publish(emp_msg); //lands the drone
00093                         ROS_INFO("Landing");
00094                         }//land after t+15
00095                 
00096                 else
00097                         {       
00098                         //pub_twist.publish(twist_msg_pshover);
00099                         pub_twist.publish(twist_msg_hover);
00100                         ROS_INFO("Flying");
00101                         }//fly according to desired twist
00102 
00103         ros::spinOnce();
00104         loop_rate.sleep();
00105 
00106 }//ros::ok
00107 
00108 }//main


arl_ardrone_examples
Author(s): parcon
autogenerated on Mon Jan 6 2014 11:03:12