reset.cpp
Go to the documentation of this file.
00001 /*
00002 Parker Conroy
00003 Algorithmic Robotics Lab @ University of Utah
00004 
00005 This program resets the ardrone, generally used after a crash.
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 <cstdlib>
00011 #include <ardrone_autonomy/Navdata.h>
00012 
00013 std_msgs::Empty emp_msg;
00014 ardrone_autonomy::Navdata msg_in;
00015 int drone_state;
00016 
00017 void nav_callback(const ardrone_autonomy::Navdata& msg_in)
00018 {
00019                 //Take in state of ardrone      
00020         drone_state=msg_in.state;       
00021 }
00022 
00023 int main(int argc, char** argv)
00024 {
00025         using namespace std;
00026         ROS_INFO("Reseting ARdrone");
00027         ros::init(argc, argv,"ARDrone_test");
00028     ros::NodeHandle node;
00029     ros::Rate loop_rate(50);
00030         ros::Publisher pub_empty;
00031         ros::Subscriber nav_sub;
00032 
00033         nav_sub = node.subscribe("/ardrone/navdata", 1, nav_callback);
00034         pub_empty = node.advertise<std_msgs::Empty>("/ardrone/reset", 1); /* Message queue length is just 1 */
00035         
00036         while (ros::ok()) {
00037                 double time_start=(double)ros::Time::now().toSec();
00038                                 
00039                 while ((double)ros::Time::now().toSec()< time_start+1.0 || drone_state == 0)
00040                                 {                               
00041                                 pub_empty.publish(emp_msg); //launches the droe
00042                                 ROS_INFO("Sending Reset Signal");
00043                                 ros::spinOnce();
00044                                 loop_rate.sleep();
00045                                         if((double)ros::Time::now().toSec()> time_start+3.0){                                   
00046                                         
00047                                                 ROS_ERROR("Time limit reached, unable to set state of ardrone");
00048                                                 exit(0);
00049                                         }//end if
00050                                 
00051                                 }//while time or state
00052                 system("rosservice  call /ardrone/setledanimation 1 5 2");
00053                 ROS_INFO("ARdrone reset");
00054                 exit(0);
00055                 }//ros::ok
00056 }//main


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