MCPcopy Create free account
hub / github.com/amov-lab/Prometheus / main

Function main

Modules/control/src/px4_pos_controller.cpp:108–428  ·  view source on GitHub ↗

>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>主 函 数<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

Source from the content-addressed store, hash-verified

106
107//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>主 函 数<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
108int main(int argc, char **argv)
109{
110 ros::init(argc, argv, "px4_pos_controller");
111 ros::NodeHandle nh("~");
112
113 //【订阅】指令
114 // 本话题为任务模块生成的控制指令
115 ros::Subscriber Command_sub = nh.subscribe<prometheus_msgs::ControlCommand>("/prometheus/control_command", 10, Command_cb);
116
117 //【订阅】指令
118 // 本话题为Prometheus地面站发送的控制指令
119 ros::Subscriber station_command_sub = nh.subscribe<prometheus_msgs::ControlCommand>("/prometheus/control_command_station", 10, station_command_cb);
120
121 //【订阅】无人机状态
122 // 本话题来自px4_pos_estimator.cpp
123 ros::Subscriber drone_state_sub = nh.subscribe<prometheus_msgs::DroneState>("/prometheus/drone_state", 10, drone_state_cb);
124
125 //【发布】位置控制器的输出量:期望姿态
126 att_ref_pub = nh.advertise<prometheus_msgs::AttitudeReference>("/prometheus/control/attitude_reference", 10);
127
128 //【发布】参考位姿 RVIZ显示用
129 rivz_ref_pose_pub = nh.advertise<geometry_msgs::PoseStamped>("/prometheus/control/ref_pose_rviz", 10);
130
131 // 【发布】用于地面站显示的提示消息
132 message_pub = nh.advertise<prometheus_msgs::Message>("/prometheus/message/main", 10);
133
134 // 【发布】用于log的消息
135 log_message_pub = nh.advertise<prometheus_msgs::LogMessageControl>("/prometheus/log/control", 10);
136
137 // 10秒定时打印,以确保程序在正确运行
138 ros::Timer timer = nh.createTimer(ros::Duration(10.0), timerCallback);
139
140 // 参数读取
141 nh.param<string>("controller_type", controller_type, "default");
142 nh.param<float>("Takeoff_height", Takeoff_height, 1.5);
143 nh.param<float>("Disarm_height", Disarm_height, 0.15);
144 nh.param<float>("Land_speed", Land_speed, 0.2);
145
146 nh.param<float>("geo_fence/x_min", geo_fence_x[0], -100.0);
147 nh.param<float>("geo_fence/x_max", geo_fence_x[1], 100.0);
148 nh.param<float>("geo_fence/y_min", geo_fence_y[0], -100.0);
149 nh.param<float>("geo_fence/y_max", geo_fence_y[1], 100.0);
150 nh.param<float>("geo_fence/z_min", geo_fence_z[0], -100.0);
151 nh.param<float>("geo_fence/z_max", geo_fence_z[1], 100.0);
152
153 // 位置控制一般选取为50Hz,主要取决于位置状态的更新频率
154 ros::Rate rate(50.0);
155
156 float time_trajectory = 0.0;
157
158 // 用于与mavros通讯的类,通过mavros发送控制指令至飞控【本程序->mavros->飞控】
159 command_to_mavros _command_to_mavros;
160
161 // 位置控制器声明
162 pos_controller_cascade_PID pos_controller_cascade_pid;
163 // 可以设置自定义位置环控制算法
164 pos_controller_PID pos_controller_pid;
165 pos_controller_passivity pos_controller_passivity;

Callers

nothing calls this directly

Calls 12

pub_messageFunction · 0.85
ThrottleToAttitudeFunction · 0.85
printf_paramFunction · 0.70
check_failsafeFunction · 0.70
Body_to_ENUFunction · 0.70
get_ref_pose_rvizFunction · 0.70
get_time_in_secFunction · 0.50
constrain_function2Function · 0.50
printf_paramMethod · 0.45
idleMethod · 0.45
pos_controllerMethod · 0.45

Tested by

no test coverage detected