Go to the documentation of this file.00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 #include <ros/ros.h>
00010 #include <std_msgs/Empty.h>
00011 #include <geometry_msgs/Twist.h>
00012 
00013         geometry_msgs::Twist twist_msg;
00014         geometry_msgs::Twist twist_msg_neg;
00015         geometry_msgs::Twist twist_msg_hover;
00016         geometry_msgs::Twist twist_msg_up;
00017         std_msgs::Empty emp_msg;
00018         
00019 
00020 int main(int argc, char** argv)
00021 {
00022 
00023         ROS_INFO("ARdrone Test Back and Forth Starting");
00024         ros::init(argc, argv,"ARDrone_test");
00025     ros::NodeHandle node;
00026     ros::Rate loop_rate(50);
00027 
00028         ros::Publisher pub_empty_land;
00029         ros::Publisher pub_twist;
00030         ros::Publisher pub_empty_takeoff;
00031         ros::Publisher pub_empty_reset;
00032         double start_time;
00033 
00034 
00035                         twist_msg_hover.linear.x=0.0; 
00036                         twist_msg_hover.linear.y=0.0;
00037                         twist_msg_hover.linear.z=0.0;
00038                         twist_msg_hover.angular.x=0.0; 
00039                         twist_msg_hover.angular.y=0.0;
00040                         twist_msg_hover.angular.z=0.0;  
00041 
00042                         twist_msg_up.linear.x=0.0; 
00043                         twist_msg_up.linear.y=0.0;
00044                         twist_msg_up.linear.z=0.5;
00045                         twist_msg_up.angular.x=0.0; 
00046                         twist_msg_up.angular.y=0.0;
00047                         twist_msg_up.angular.z=0.0;
00048 
00049                         float takeoff_time=5.0;
00050                         float fly_time=7.0;
00051                         float land_time=3.0;
00052                         float kill_time =2.0;   
00053                         
00054                         
00055                         twist_msg.linear.x=0.0; 
00056                         twist_msg.linear.y=0.25;
00057                         twist_msg.linear.z=0.0;
00058                         twist_msg.angular.x=0.0; 
00059                         twist_msg.angular.y=0.0;
00060                         twist_msg.angular.z=0.0;
00061 
00062                         twist_msg_neg.linear.x=-twist_msg.linear.x; 
00063                         twist_msg_neg.linear.y=-twist_msg.linear.y;
00064                         twist_msg_neg.linear.z=-twist_msg.linear.z;
00065                         twist_msg_neg.angular.x=-twist_msg.angular.x; 
00066                         twist_msg_neg.angular.y=-twist_msg.angular.y;
00067                         twist_msg_neg.angular.z=-twist_msg.angular.z;
00068 
00069 
00070         
00071     pub_twist = node.advertise<geometry_msgs::Twist>("/cmd_vel", 1); 
00072         pub_empty_takeoff = node.advertise<std_msgs::Empty>("/ardrone/takeoff", 1); 
00073         pub_empty_land = node.advertise<std_msgs::Empty>("/ardrone/land", 1); 
00074 pub_empty_reset = node.advertise<std_msgs::Empty>("/ardrone/reset", 1); 
00075 
00076         
00077         start_time =(double)ros::Time::now().toSec();   
00078         ROS_INFO("Starting ARdrone_test loop");
00079 
00080 
00081 while (ros::ok()) {
00082                 while ((double)ros::Time::now().toSec()< start_time+takeoff_time){ 
00083                 
00084                         pub_empty_takeoff.publish(emp_msg); 
00085                                 pub_twist.publish(twist_msg_hover); 
00086                         ROS_INFO("Taking off");
00087                         ros::spinOnce();
00088                         loop_rate.sleep();
00089                         }
00090 
00091                 while  ((double)ros::Time::now().toSec()> start_time+takeoff_time+fly_time){
00092                 
00093                         pub_twist.publish(twist_msg_hover); 
00094                         pub_empty_land.publish(emp_msg); 
00095                         ROS_INFO("Landing");
00096                         
00097                                         
00098                         if ((double)ros::Time::now().toSec()> takeoff_time+start_time+fly_time+land_time+kill_time){
00099                 
00100                                 ROS_INFO("Closing Node");
00101                                 
00102                                 exit(0);        }
00103                         ros::spinOnce();
00104                         loop_rate.sleep();                      
00105 }
00106 
00107                 while ( (double)ros::Time::now().toSec()> start_time+takeoff_time &&                                            (double)ros::Time::now().toSec()< start_time+takeoff_time+fly_time){    
00108                 
00109 
00110                         if((double)ros::Time::now().toSec()< start_time+takeoff_time+fly_time/2){
00111                         pub_twist.publish(twist_msg);
00112                         ROS_INFO("Flying +ve");
00113 
00114                         }
00115                         
00116                         if((double)ros::Time::now().toSec()> start_time+takeoff_time+fly_time/2){
00117                         pub_twist.publish(twist_msg_neg);
00118                         ROS_INFO("Flying -ve");
00119 
00120                         }
00121                         
00122                         ros::spinOnce();
00123                 loop_rate.sleep();
00124                         }
00125 
00126         ros::spinOnce();
00127         loop_rate.sleep();
00128 
00129 }
00130 
00131 }