Texas Aerial Robotics Documentation
controlAPIExample.cpp
Go to the documentation of this file.
1 #include <control_functions.hpp>
2 //include API
3 
4 int main(int argc, char** argv)
5 {
6  //initialize ros
7  ros::init(argc, argv, "offb_node");
8  ros::NodeHandle controlnode;
9 
10  //initialize control publisher/subscribers
11  init_publisher_subscriber(controlnode);
12 
13  //specify some waypoints
14  std::vector<control_api_waypoint> waypointList;
15  control_api_waypoint nextWayPoint;
16  nextWayPoint.x = 0;
17  nextWayPoint.y = 0;
18  nextWayPoint.z = 3;
19  nextWayPoint.psi = 0;
20  waypointList.push_back(nextWayPoint);
21  nextWayPoint.x = 5;
22  nextWayPoint.y = 0;
23  nextWayPoint.z = 3;
24  nextWayPoint.psi = -90;
25  waypointList.push_back(nextWayPoint);
26  nextWayPoint.x = 5;
27  nextWayPoint.y = 5;
28  nextWayPoint.z = 3;
29  nextWayPoint.psi = 0;
30  waypointList.push_back(nextWayPoint);
31  nextWayPoint.x = 0;
32  nextWayPoint.y = 5;
33  nextWayPoint.z = 3;
34  nextWayPoint.psi = 90;
35  waypointList.push_back(nextWayPoint);
36  nextWayPoint.x = 0;
37  nextWayPoint.y = 0;
38  nextWayPoint.z = 3;
39  nextWayPoint.psi = 180;
40  waypointList.push_back(nextWayPoint);
41 
42  // wait for FCU connection
43  wait4connect();
44 
45  //wait for used to switch to mode GUIDED
46  wait4start();
47 
48  //create local reference frame
50 
51  //request takeoff
52  takeoff(3);
53 
54  //specify control loop rate. We recommend a low frequency to not over load the FCU with messages. Too many messages will cause the drone to be sluggish
55  ros::Rate rate(2.0);
56  int counter = 0;
57  while(ros::ok())
58  {
59  ros::spinOnce();
60  rate.sleep();
61  if(check_waypoint_reached() == 1)
62  {
63  if (counter < waypointList.size())
64  {
65  set_destination(waypointList[counter].x,waypointList[counter].y,waypointList[counter].z, waypointList[counter].psi);
66  counter++;
67  }else{
68  //land after all waypoints are reached
69  land();
70  }
71  }
72 
73  }
74  return 0;
75 }
76 
float y
distance in y with respect to your reference frame
float psi
rotation about the third axis of your reference frame
void set_destination(float x, float y, float z, float psi)
int check_waypoint_reached()
int init_publisher_subscriber(ros::NodeHandle controlnode)
int takeoff(float takeoff_alt)
float z
distance in z with respect to your reference frame
int land()
int wait4connect()
int initialize_local_frame()
int wait4start()
float x
distance in x with respect to your reference frame
int main(int argc, char **argv)