Skip to content

Commit 100f301

Browse files
committed
px4_command 2.0
1 parent 851e022 commit 100f301

File tree

61 files changed

+2769
-2238
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+2769
-2238
lines changed
8 Bytes
Binary file not shown.
8 Bytes
Binary file not shown.
8 Bytes
Binary file not shown.
8 Bytes
Binary file not shown.
8 Bytes
Binary file not shown.
8 Bytes
Binary file not shown.
8 Bytes
Binary file not shown.
8 Bytes
Binary file not shown.
8 Bytes
Binary file not shown.
8 Bytes
Binary file not shown.
8 Bytes
Binary file not shown.
8 Bytes
Binary file not shown.
8 Bytes
Binary file not shown.
8 Bytes
Binary file not shown.
8 Bytes
Binary file not shown.
8 Bytes
Binary file not shown.
8 Bytes
Binary file not shown.
8 Bytes
Binary file not shown.
8 Bytes
Binary file not shown.
8 Bytes
Binary file not shown.
8 Bytes
Binary file not shown.
8 Bytes
Binary file not shown.
8 Bytes
Binary file not shown.
8 Bytes
Binary file not shown.
8 Bytes
Binary file not shown.
8 Bytes
Binary file not shown.
8 Bytes
Binary file not shown.
8 Bytes
Binary file not shown.
8 Bytes
Binary file not shown.

CMakeLists.txt

+8-34
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ project(px4_command)
88
## if COMPONENTS list like find_package(catkin REQUIRED COMPONENTS xyz)
99
## is used, also find other catkin packages
1010
find_package(catkin REQUIRED COMPONENTS
11+
message_generation
1112
roscpp
1213
geometry_msgs
1314
sensor_msgs
@@ -18,7 +19,6 @@ find_package(catkin REQUIRED COMPONENTS
1819
tf2_ros
1920
tf2_eigen
2021
mavros_msgs
21-
message_generation
2222
)
2323

2424
## System dependencies are found with CMake's conventions
@@ -34,54 +34,28 @@ find_package(Boost REQUIRED COMPONENTS system)
3434
add_message_files(
3535
DIRECTORY msg
3636
FILES
37-
command.msg
37+
ControlCommand.msg
3838
data_log.msg
39+
TrajectoryPoint.msg
40+
Trajectory.msg
41+
AttitudeReference.msg
42+
DroneState.msg
3943
)
4044

4145
## Generate added messages and services with any dependencies listed here
4246
generate_messages(
4347
DEPENDENCIES
48+
geometry_msgs
49+
sensor_msgs
4450
std_msgs
4551
)
4652

47-
################################################
48-
## Declare ROS dynamic reconfigure parameters ##
49-
################################################
50-
51-
## To declare and build dynamic reconfigure parameters within this
52-
## package, follow these steps:
53-
## * In the file package.xml:
54-
## * add a build_depend and a exec_depend tag for "dynamic_reconfigure"
55-
## * In this file (CMakeLists.txt):
56-
## * add "dynamic_reconfigure" to
57-
## find_package(catkin REQUIRED COMPONENTS ...)
58-
## * uncomment the "generate_dynamic_reconfigure_options" section below
59-
## and list every .cfg file to be processed
60-
61-
## Generate dynamic reconfigure parameters in the 'cfg' folder
62-
# generate_dynamic_reconfigure_options(
63-
# cfg/DynReconf1.cfg
64-
# cfg/DynReconf2.cfg
65-
# )
66-
67-
###################################
68-
## catkin specific configuration ##
69-
###################################
70-
## The catkin_package macro generates cmake config files for your package
71-
## Declare things to be passed to dependent projects
72-
## INCLUDE_DIRS: uncomment this if your package contains header files
73-
## LIBRARIES: libraries you create in this project that dependent projects also need
74-
## CATKIN_DEPENDS: catkin_packages dependent projects also need
75-
## DEPENDS: system dependencies of this project that dependent projects also need
76-
7753
catkin_package(
7854
INCLUDE_DIRS include
7955
CATKIN_DEPENDS message_runtime
8056
)
8157

8258

83-
84-
8559
###########
8660
## Build ##
8761
###########

config/Parameter_for_control.yaml

+34-15
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,28 @@ geo_fence:
1515

1616
## 限制参数
1717
Limit:
18+
pxy_error_max: 0.8
19+
vxy_error_max: 1.0
20+
pz_error_max: 0.5
21+
vz_error_max: 1.0
22+
pxy_int_max : 5.0
23+
pz_int_max : 5.0
1824
tilt_max: 20.0
1925
THR_MIN: 0.1
2026
THR_MAX: 0.9
27+
int_start_error: 100.0
28+
2129
XY_VEL_MAX : 0.8
2230
Z_VEL_MAX : 0.5
23-
31+
32+
2433
## 起飞高度
2534
Takeoff_height : 0.8
2635
Disarm_height : 0.15
27-
flag_att_sp : 1
36+
Use_mocap_raw : 0
37+
2838
# 位置环参数
29-
Pos_pid:
39+
Pos_cascade_pid:
3040
Kp_xy : 0.95
3141
Kp_z : 1.0
3242
Kp_vxvy : 0.09
@@ -38,6 +48,16 @@ Pos_pid:
3848
Hover_throttle : 0.5
3949
MPC_VELD_LP: 5.0
4050

51+
# 位置环参数
52+
Pos_pid:
53+
Kp_xy : 2.5
54+
Kp_z : 2.5
55+
Ki_xy : 0.5
56+
Ki_z : 0.5
57+
Kd_xy : 3.0
58+
Kd_vz : 3.0
59+
60+
4161
# 位置环参数 for ude
4262
Pos_ude:
4363
Kp_xy : 0.5
@@ -46,9 +66,6 @@ Pos_ude:
4666
Kd_Zz : 2.0
4767
T_ude_xy : 1.0
4868
T_ude_z : 1.0
49-
INT_LIM_X : 5.0
50-
INT_LIM_Y : 5.0
51-
INT_LIM_Z : 10.0
5269

5370
# 位置环参数 for passivity
5471
Pos_passivity:
@@ -58,10 +75,7 @@ Pos_passivity:
5875
Kd_z : 2.0
5976
T_ude_xy : 1.0
6077
T_ude_z : 1.0
61-
T1: 0.1
62-
INT_LIM_X : 5.0
63-
INT_LIM_Y : 5.0
64-
INT_LIM_Z : 10.0
78+
T_ps: 0.1
6579

6680
# 位置环参数 for ne
6781
Pos_ne:
@@ -71,12 +85,17 @@ Pos_ne:
7185
Kd_z : 2.0
7286
T_ude_xy : 1.0
7387
T_ude_z : 1.0
74-
Tn: 0.1
75-
INT_LIM_X : 5.0
76-
INT_LIM_Y : 5.0
77-
INT_LIM_Z : 10.0
78-
88+
T_ne: 0.1
7989

90+
# 圆轨迹参数 for Circle_Trajectory
91+
Circle_Trajectory:
92+
Center_x: 0.0
93+
Center_y: 0.0
94+
Center_z: 1.0
95+
radius: 1.0
96+
linear_vel: 0.31415926
97+
time_total: 50.0
98+
direction: 1.0
8099

81100

82101

include/circle_trajectory.h

+155
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
1+
/***************************************************************************************************************************
2+
* circle_trajectory.h
3+
*
4+
* Author: Qyp
5+
*
6+
* Update Time: 2019.6.28
7+
*
8+
* Introduction: Circle trajectory generation code
9+
* 1. Generating the circle trajectory
10+
* 2. Parameter: center, radius, linear_vel, time_total, direction
11+
* 3. Input: time_from_start
12+
* 4. Output: position, velocity, acceleration, jerk, snap
13+
***************************************************************************************************************************/
14+
#ifndef CIRCLE_TRAJECTORY_H
15+
#define CIRCLE_TRAJECTORY_H
16+
17+
#include <Eigen/Eigen>
18+
#include <math.h>
19+
#include <math_utils.h>
20+
#include <px4_command/TrajectoryPoint.h>
21+
using namespace std;
22+
23+
class Circle_Trajectory
24+
{
25+
//public表明该数据成员、成员函数是对全部用户开放的。全部用户都能够直接进行调用,在程序的不论什么其他地方訪问。
26+
public:
27+
28+
//构造函数
29+
Circle_Trajectory(void):
30+
Circle_Trajectory_nh("~")
31+
{
32+
Circle_Trajectory_nh.param<float>("Circle_Trajectory/Center_x", center[0], 0.0);
33+
Circle_Trajectory_nh.param<float>("Circle_Trajectory/Center_y", center[1], 0.0);
34+
Circle_Trajectory_nh.param<float>("Circle_Trajectory/Center_z", center[2], 1.0);
35+
Circle_Trajectory_nh.param<float>("Circle_Trajectory/radius", radius, 1.0);
36+
Circle_Trajectory_nh.param<float>("Circle_Trajectory/linear_vel", linear_vel, 0.5);
37+
Circle_Trajectory_nh.param<float>("Circle_Trajectory/time_total", time_total, 10.0);
38+
Circle_Trajectory_nh.param<float>("Circle_Trajectory/direction", direction, 1.0);
39+
40+
time_from_start = 0.0;
41+
}
42+
43+
// Parameter
44+
Eigen::Vector3f center;
45+
float radius;
46+
float linear_vel;
47+
float time_total;
48+
float direction; //direction = 1 for CCW 逆时针, direction = -1 for CW 顺时针
49+
50+
// Input
51+
float time_from_start;
52+
53+
// Output: position, velocity, acceleration, jerk, snap
54+
px4_command::TrajectoryPoint Circle_trajectory;
55+
56+
//Printf the Circle_Trajectory parameter
57+
void printf_param();
58+
59+
//Printf the Circle_Trajectory result
60+
void printf_result();
61+
62+
//Circle_Trajectory Calculation [Input: time_from_start; Output: Circle_trajectory;]
63+
px4_command::TrajectoryPoint Circle_trajectory_generation(float time_from_start);
64+
65+
private:
66+
67+
ros::NodeHandle Circle_Trajectory_nh;
68+
69+
};
70+
71+
72+
px4_command::TrajectoryPoint Circle_Trajectory::Circle_trajectory_generation(float time_from_start)
73+
{
74+
const float omega = direction * fabs(linear_vel / radius);
75+
const float angle = time_from_start * omega;
76+
const float cos_angle = cos(angle);
77+
const float sin_angle = sin(angle);
78+
79+
// cout << "omega : " << omega * 180/M_PI <<" [deg/s] " <<endl;
80+
// cout << "angle : " << angle * 180/M_PI <<" [deg] " <<endl;
81+
82+
Circle_trajectory.time_from_start = time_from_start;
83+
84+
Circle_trajectory.position_ref[0] = radius * cos_angle + center[0];
85+
Circle_trajectory.position_ref[1] = radius * sin_angle + center[1];
86+
Circle_trajectory.position_ref[2] = center[2];
87+
88+
Circle_trajectory.velocity_ref[0] = - radius * omega * sin_angle;
89+
Circle_trajectory.velocity_ref[1] = radius * omega * cos_angle;
90+
Circle_trajectory.velocity_ref[2] = 0;
91+
92+
Circle_trajectory.acceleration_ref[0] = - radius * pow(omega, 2.0) * cos_angle;
93+
Circle_trajectory.acceleration_ref[1] = - radius * pow(omega, 2.0) * sin_angle;
94+
Circle_trajectory.acceleration_ref[2] = 0;
95+
96+
Circle_trajectory.jerk_ref[0] = radius * pow(omega, 3.0) * sin_angle;
97+
Circle_trajectory.jerk_ref[1] = - radius * pow(omega, 3.0) * cos_angle;
98+
Circle_trajectory.jerk_ref[2] = 0;
99+
100+
Circle_trajectory.snap_ref[0] = radius * pow(omega, 4.0) * cos_angle;
101+
Circle_trajectory.snap_ref[1] = radius * pow(omega, 4.0) * sin_angle;
102+
Circle_trajectory.snap_ref[2] = 0;
103+
104+
Circle_trajectory.yaw_ref = 0;
105+
Circle_trajectory.yaw_rate_ref = 0;
106+
Circle_trajectory.yaw_acceleration_ref = 0;
107+
return Circle_trajectory;
108+
}
109+
110+
111+
void Circle_Trajectory::printf_result()
112+
{
113+
cout <<">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>Circle_Trajectory<<<<<<<<<<<<<<<<<<<<<<<<<<<" <<endl;
114+
115+
//固定的浮点显示
116+
cout.setf(ios::fixed);
117+
//左对齐
118+
cout.setf(ios::left);
119+
// 强制显示小数点
120+
cout.setf(ios::showpoint);
121+
// 强制显示符号
122+
cout.setf(ios::showpos);
123+
124+
cout<<setprecision(2);
125+
126+
cout << "time_from_start : " << Circle_trajectory.time_from_start<< " [s] " <<endl;
127+
128+
cout << "position [X Y Z] : " << Circle_trajectory.position_ref[0] << " [m] "<< Circle_trajectory.position_ref[1]<<" [m] "<<Circle_trajectory.position_ref[2]<<" [m] "<<endl;
129+
130+
cout << "velocity [X Y Z] : " << Circle_trajectory.velocity_ref[0] << " [m/s] "<< Circle_trajectory.velocity_ref[1]<<" [m/s] "<<Circle_trajectory.velocity_ref[2]<<" [m/s] "<<endl;
131+
132+
cout << "acceleration [X Y Z] : " << Circle_trajectory.acceleration_ref[0] << " [m/s^2] "<< Circle_trajectory.acceleration_ref[1]<<" [m/s^2] "<< Circle_trajectory.acceleration_ref[2]<<" [m/s^2] "<<endl;
133+
134+
cout << "jerk [X Y Z] : " << Circle_trajectory.jerk_ref[0] << " [m/s^3] "<< Circle_trajectory.jerk_ref[1]<<" [m/s^3] "<<Circle_trajectory.jerk_ref[2]<<" [m/s^3] "<<endl;
135+
136+
cout << "snap [X Y Z] : " << Circle_trajectory.snap_ref[0] << " [m/s^4] "<< Circle_trajectory.snap_ref[1]<<" [m/s^4] "<<Circle_trajectory.snap_ref[2]<<" [m/s^4] "<<endl;
137+
138+
}
139+
140+
// 【打印参数函数】
141+
void Circle_Trajectory::printf_param()
142+
{
143+
cout <<">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>Circle_Trajectory Parameter <<<<<<<<<<<<<<<<<<<<<<<<<<<" <<endl;
144+
145+
cout <<"center : "<< center <<endl;
146+
cout <<"radius : "<< radius << endl;
147+
cout <<"linear_vel : "<< linear_vel << endl;
148+
cout <<"time_total : "<< time_total << endl;
149+
cout <<"direction : "<< direction << endl;
150+
//direction = 1 for CCW 逆时针, direction = -1 for CW 顺时针
151+
}
152+
153+
154+
155+
#endif

0 commit comments

Comments
 (0)