1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84
| #include <ros/ros.h>
#include <iostream> #include <cmath> #include <stdlib.h> #include <px4_command/command.h> #include <geometry_msgs/Pose.h> #include <geometry_msgs/PoseStamped.h>
using namespace std;
enum Command { Move_ENU, Move_Body, Hold, Takeoff, Land, Arm, Disarm, Failsafe_land, Idle };
px4_command::command Command_now;
int main(int argc, char **argv) { ros::init(argc, argv, "auto_takeoff"); ros::NodeHandle nh("~"); ros::Rate rate(20.0); ros::Publisher command_pub = nh.advertise<px4_command::command>("/px4/command", 10);
int check_flag; cout << "Please check the parameter and setting,1 for go on, else for quit: "<<endl; cin >> check_flag; if(check_flag != 1) return -1;
int Arm_flag; cout<<"Whether choose to Arm? 1 for Arm, 0 for quit"<<endl; cin >> Arm_flag; if(Arm_flag == 1) { Command_now.command = Arm; command_pub.publish(Command_now); } else return -1;
int Take_off_flag; cout<<"Whether choose to Takeoff? 1 for Takeoff, 0 for quit"<<endl; cin >> Take_off_flag; if(Take_off_flag == 1) { Command_now.command = Takeoff; command_pub.publish(Command_now); } else return -1;
int Land_flag; cout<<"Whether choose to Land? 1 for Land, 0 for quit"<<endl; cin >> Land_flag; if(Land_flag == 1) { Command_now.command = Land; while (ros::ok()) { command_pub.publish(Command_now); rate.sleep(); cout << "Land"<<endl; } } else return -1;
cout<<"Program finish, exiting....."; return 0; }
|