forked from glennliu/uavformation
-
Notifications
You must be signed in to change notification settings - Fork 0
/
uav1_pathplan.cpp
56 lines (44 loc) · 1.63 KB
/
uav1_pathplan.cpp
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
#include "ros/ros.h"
#include "pidcontrol.h"
#include "sensorcallback.h"
#include <sstream>
#include <iostream>
using namespace std;
double loop_period;
int main(int argc, char** argv)
{
pidcontrol longitude, latitude, altitude, yaw_angle; //init pid control for longitude, latitude and altitude
//set pid control parameter
longitude.setparam(1.2,0,0.5,3,6);
latitude.setparam(1.2,0,0.5,3,6);
altitude.setparam(0.2,0,0.1,2,3);
geometry_msgs::Twist msg;
ros::init(argc, argv, "uav1_pathplan");
ros::NodeHandle nh("~");
ros::Publisher pub = nh.advertise<geometry_msgs::Twist>("/uav/uav1/cmd_vel",1000);
ros::Subscriber sub_loca= nh.subscribe<geometry_msgs::PoseStamped>("/uav/uav1/ground_truth_to_tf/pose",1,poseCallback);
ros::Subscriber sub_destination= nh.subscribe<geometry_msgs::Polygon>("/uav_positions",1,destCallback1);
ros::Rate loop_rate(100);
while (ros::ok())
{
error.x=destination.x-location.x;
error.y=destination.y-location.y;
error.z=destination.z-location.z;
longitude.updatePid3(error.x,state_error.x,ros::Duration(0.01));
latitude.updatePid3(error.y,state_error.y,ros::Duration(0.01));
altitude.updatePid3(error.z,state_error.z,ros::Duration(0.01));
msg.linear.x=longitude.cmd_;
msg.linear.y=latitude.cmd_;
msg.linear.z=altitude.cmd_;
msg.angular.x=0;
msg.angular.y=0;
msg.angular.z=0;;
state_error.x=error.x;
state_error.y=error.y;
state_error.z=error.z;
pub.publish(msg);
ros::spinOnce();
loop_rate.sleep();
}
return 0;
}