ddrone_task_manager.cpp
Go to the documentation of this file.
1 
6 #include "ddrone_task_manager.h"
7 
8 // using namespace task_manager;
9 TaskManager::TaskManager(ros::NodeHandle &nodeHandle) : _nh(nodeHandle)
10 {
11  // initialize all the state
14  m_jump = false;
15  m_swarm.data = false;
16  m_approach = false;
17  _points_id = 0;
18  yaw_initialized = false;
19  ui_points_selected = false;
20  // publish way points
21  m_pos_cmd_pub = _nh.advertise<geometry_msgs::Point>("/dummy/pos_cmd", 1);
22  // publish target
23  m_tgt_pub = _nh.advertise<common_msgs::target>("/nndp_cpp/tgt", 1);
24  // publish refrence from file
25  m_ref_pub =
26  _nh.advertise<common_msgs::state>("/task_manager/current_state", 1);
27  // trigger swarm
28  m_swarm_pub = _nh.advertise<std_msgs::Bool>("/task_manager/swarm", 1);
29  // send error to UI
31  _nh.advertise<std_msgs::Byte>("/task_manager/error_state", 1);
32  //
33  m_mpc_pos_init_pub = _nh.advertise<geometry_msgs::PoseStamped>(
34  "/task_manager/mpc_init_position_nwu", 1);
35  swarm_pos_pub = _nh.advertise<geometry_msgs::PoseStamped>(
36  "/task_manager/position_nwu", 1);
37  // Publish Setpoints to MAVROS
38  Position_Setpoint_Pub = _nh.advertise<mavros_msgs::PositionTarget>(
39  "/mavros/setpoint_raw/local", 10);
40 
41  // subscribe refrence
42  m_current_state_sub = _nh.subscribe<common_msgs::state>(
43  "/rt_ref_gen/current_state", 1, &TaskManager::currentStateCallback,
44  this);
45  // subscribe mission from UI
46  m_mission_sub = _nh.subscribe<std_msgs::Byte>(
47  "/mission_from_ui", 1, &TaskManager::webCmdCallback, this);
48 
49  // subscribe points from UI
50  m_ui_points_sub = _nh.subscribe<geometry_msgs::Polygon>(
51  "/points_from_ui", 1, &TaskManager::uiPointsCallback, this);
52  m_skipCurPoint_sub = _nh.subscribe<std_msgs::Bool>(
53  "/mission_skip_point", 1, &TaskManager::jumpWpCallback, this);
54  // subscribe diagnostics from mavros
55  m_diagnostics_sub = _nh.subscribe<diagnostic_msgs::DiagnosticArray>(
56  "/diagnostics", 10, &TaskManager::diagnosticsCallback, this);
57 
58  // get current uav pose
59  m_uav_pose_sub = _nh.subscribe<geometry_msgs::PoseStamped>(
60  "/mavros/local_position/pose", 1, &TaskManager::uavPoseCallback, this);
61 
62  m_approach_cmd_sub = _nh.subscribe<std_msgs::Bool>(
63  "/swarm/approach", 1, &TaskManager::approachCallback, this);
64  m_online_status_sub = _nh.subscribe<std_msgs::Bool>(
65  "/swarm/online", 1, &TaskManager::onlineCallback, this);
66 
67  m_gps_home_sub = _nh.subscribe<mavros_msgs::HomePosition>(
68  "/mavros/home_position/home", 1, &TaskManager::gpsHomeCb, this);
69  m_gps_cur_sub = _nh.subscribe<sensor_msgs::NavSatFix>(
70  "/mavros/global_position/global", 1, &TaskManager::gpsCurCb, this);
71  uav_state_sub = _nh.subscribe<mavros_msgs::State>(
72  "/mavros/state", 10, &TaskManager::uavStateCb, this);
73 
74  // publish file timer
75  _nh.param("missionPeriod", _missionPeriod, 0.2);
76  std::cout << "missionPeriod: " << _missionPeriod << std::endl;
78  _nh.createTimer(ros::Duration(_missionPeriod),
79  &TaskManager::missionTimer, this, false, false);
80  // set waypoints and refrence file location
81  _nh.param("simulation", _simulation, false);
82  std::cout << "_simulation: " << _simulation << std::endl;
83  _nh.param<std::string>("WP_Location", m_points_location, "/home/nvidia");
84  std::cout << "WP_Location: " << m_points_location << std::endl;
85  _nh.param("pointsSource", _points_source_param, 0);
86  std::cout << "pointsSource: " << _points_source_param << std::endl;
87  _nh.param("flightHeight", _flightHeight, 1.5);
88  std::cout << "flightHeight: " << _flightHeight << std::endl;
89  _nh.param("yaw_control", yaw_control_, false);
90  std::cout << "yaw_control: " << yaw_control_ << std::endl;
91 
92  // mPointsFrom = _points_source_param;
93  client_engine0 = _nh.serviceClient<std_srvs::Trigger>("/mavros/engine0");
94  client_home =
95  _nh.serviceClient<mavros_msgs::CommandHome>("/mavros/cmd/set_home");
96  land_client =
97  _nh.serviceClient<mavros_msgs::CommandTOL>("/mavros/cmd/land");
99  _nh.serviceClient<mavros_msgs::CommandBool>("/mavros/cmd/arming");
101  _nh.serviceClient<mavros_msgs::SetMode>("/mavros/set_mode");
102 
103  TaskTerminateFlag = false;
106  inPcmdMode = false;
107  ROS_INFO("Task manager is ready!");
108 }
109 
111 {
112  // ROS_INFO("Bye task manager~");
113 }
114 
116  const geometry_msgs::PoseStamped::ConstPtr &msg)
117 {
118  m_uav_pose = *msg;
119 
120  geometry_msgs::PoseStamped pos_nwu;
122  swarm_pos_pub.publish(pos_nwu);
123  m_uav_pose_nwu = pos_nwu;
124 }
125 
126 void TaskManager::pubTarget(bool controlMode, float tgtX, float tgtY,
127  float tgtZ)
128 {
129  common_msgs::target tgt;
130  tgt.controller = controlMode;
131  tgt.tgt.x = tgtX;
132  tgt.tgt.y = tgtY;
133  tgt.tgt.z = tgtZ;
134  m_tgt_pub.publish(tgt);
135 }
136 
137 void TaskManager::pubTargetWYaw(bool controlMode, float tgtX, float tgtY,
138  float tgtZ, float yaw)
139 {
140  common_msgs::target tgt;
141  tgt.controller = controlMode;
142  tgt.tgt.x = tgtX;
143  tgt.tgt.y = tgtY;
144  tgt.tgt.z = tgtZ;
145  tgt.yaw_tgt = yaw;
146  m_tgt_pub.publish(tgt);
147 }
148 
149 void TaskManager::velYawTgtCallback(const common_msgs::target::ConstPtr &msg)
150 {
151  common_msgs::target tgt = *msg;
152  m_tgt_pub.publish(tgt);
153 }
154 
155 void TaskManager::posYawTgtCallback(const common_msgs::target::ConstPtr &msg)
156 {
157  common_msgs::target tgt = *msg;
158  gpsToEnu.GeodeticToEnu(msg->tgt.x, msg->tgt.y, msg->tgt.z,
159  m_gps_home.geo.latitude, m_gps_home.geo.longitude,
160  m_gps_home.geo.altitude);
161  gpsToEnuCur.GeodeticToEnu(m_gps_cur.latitude, m_gps_cur.longitude,
162  m_gps_cur.altitude, m_gps_home.geo.latitude,
163  m_gps_home.geo.longitude,
164  m_gps_home.geo.altitude);
165  geometry_msgs::Point deltaP;
166  deltaP.x = gpsToEnu.yNorth - gpsToEnuCur.yNorth;
167  deltaP.y = -(gpsToEnu.xEast - gpsToEnuCur.xEast);
168  deltaP.z = gpsToEnu.zUp - gpsToEnuCur.zUp;
169 
170  tgt.tgt.x = m_uav_pose.pose.position.y + deltaP.x;
171  tgt.tgt.y = -m_uav_pose.pose.position.x + deltaP.y;
172  tgt.tgt.z = m_uav_pose.pose.position.z + deltaP.z;
173  m_tgt_pub.publish(tgt);
174 }
175 
176 void TaskManager::velTgtCallback(const geometry_msgs::Point::ConstPtr &msg)
177 {
178  pubTarget(VEL_CONTROL, msg->x, msg->y, msg->z);
179  // if(inPcmdMode)
180  // inPcmdMode = false;
181 }
182 
183 void TaskManager::posTgtCallback(const geometry_msgs::Point::ConstPtr &msg)
184 {
185  gpsToEnu.GeodeticToEnu(msg->x, msg->y, msg->z, m_gps_home.geo.latitude,
186  m_gps_home.geo.longitude, m_gps_home.geo.altitude);
187  gpsToEnuCur.GeodeticToEnu(m_gps_cur.latitude, m_gps_cur.longitude,
188  m_gps_cur.altitude, m_gps_home.geo.latitude,
189  m_gps_home.geo.longitude,
190  m_gps_home.geo.altitude);
191  geometry_msgs::Point deltP;
192  deltP.x = gpsToEnu.yNorth - gpsToEnuCur.yNorth;
193  deltP.y = -(gpsToEnu.xEast - gpsToEnuCur.xEast);
194  deltP.z = gpsToEnu.zUp - gpsToEnuCur.zUp;
195 
196  pubTarget(POS_CONTROL, m_uav_pose.pose.position.y + deltP.x,
197  -m_uav_pose.pose.position.x + deltP.y,
198  m_uav_pose.pose.position.z + deltP.z);
199 }
200 
202 {
203  // send swarm off
204  m_swarm.data = false;
205  m_swarm_pub.publish(m_swarm);
206  m_vcmd_sub.shutdown();
207  m_pcmd_sub.shutdown();
208  ROS_INFO("Shut down swarm Algo.");
209 }
210 
211 void TaskManager::approachCallback(const std_msgs::Bool::ConstPtr &msg)
212 {
213  if (msg->data && !m_approach)
214  {
215  m_approach = true;
216  ROS_WARN("APPROACH");
217  shutdownSwarm();
218  ROS_INFO("Flying 15m to south.");
219  // fly 15m to south
220  m_tgt.tgt.x = m_uav_pose_nwu.pose.position.x - 15.0;
221  m_tgt.tgt.y = m_uav_pose_nwu.pose.position.y;
222  pubTarget(POS_CONTROL, m_tgt.tgt.x, m_tgt.tgt.y,
223  m_uav_pose_nwu.pose.position.z);
224  m_mission_timer.start();
225  }
226 }
227 
228 void TaskManager::onlineCallback(const std_msgs::Bool::ConstPtr &msg)
229 {
230  if (!msg->data)
231  {
232  missionCallback(5);
233  ROS_INFO("Landing triggered by offline status.");
234  }
235 }
236 
237 void TaskManager::gpsHomeCb(const mavros_msgs::HomePosition::ConstPtr &msg)
238 {
239  m_gps_home = *msg;
240 }
241 
242 void TaskManager::gpsCurCb(const sensor_msgs::NavSatFix::ConstPtr &msg)
243 {
244  m_gps_cur = *msg;
245 }
246 void TaskManager::uavStateCb(const mavros_msgs::State::ConstPtr &msg)
247 {
248  uav_current_state = *msg;
249 }
250 
251 // void TaskManager::gcsCmdCallback(const mavros::Cmd::ConstPtr& msg){
252 
253 // int8_t msg_from_qt_gcs;
254 // msg_from_qt_gcs = msg->param1;
255 // ROS_INFO("Got command from QT GCS");
256 // missionCallback(msg_from_qt_gcs);
257 
258 // }
259 
260 void TaskManager::webCmdCallback(const std_msgs::Byte::ConstPtr &msg)
261 {
262  ROS_INFO("Got command from web GCS");
263  missionCallback(msg->data);
264 }
265 
267 {
268  switch (msg)
269  {
270  // No need for engine0 in 1.8 firmware
271 
272  // case ENGINE0:
273  // ROS_INFO("ENGINE0 is sent!");
274  // // calculateYaw();
275  // engine0();
276  // break;
277 
278  case TAKEOFF:
279  takeoff();
281  ROS_WARN("TAKEOFF");
282  ROS_INFO("UAV is taking off!");
283 
284  break;
285 
286  case MISSION:
287  if (mUavTaskState == kTakeOff)
288  {
289  if (loadMission())
290  {
291  ROS_INFO("Mission starts!");
293  m_mission_timer.start();
294  ROS_WARN("MISSION");
295  }
296  else
297  {
298  ROS_ERROR("Mission Load failed!");
299  }
300  }
301  else
302  {
303  ROS_ERROR("Please send takeoff command first!");
304  }
305  break;
306 
307  case SWARM:
309  {
310  clearMission();
311  ROS_INFO_STREAM("Switch from " << mUavTaskState << "to SWARM");
312  ROS_WARN("SWARM");
313  // start swarm
314  m_swarm.data = true;
315  m_swarm_pub.publish(m_swarm);
317  // get cmd from swarm algo
318  if (yaw_control_)
319  {
320  m_vcmd_sub = _nh.subscribe<common_msgs::target>(
321  "/velTgtFromSwarm", 10, &TaskManager::velYawTgtCallback,
322  this);
323  m_pcmd_sub = _nh.subscribe<common_msgs::target>(
324  "/posTgtFromSwarm", 10, &TaskManager::posYawTgtCallback,
325  this);
326  }
327  else
328  {
329  m_vcmd_sub = _nh.subscribe<geometry_msgs::Point>(
330  "/velTgtFromSwarm", 10, &TaskManager::velTgtCallback, this);
331  m_pcmd_sub = _nh.subscribe<geometry_msgs::Point>(
332  "/posTgtFromSwarm", 10, &TaskManager::posTgtCallback, this);
333  }
334  }
335  else
336  {
337  ROS_ERROR("Please send takeoff command first!");
338  }
339  break;
340 
341  case HOVER:
342  ROS_WARN("HOVER");
344  // take over control
345  shutdownSwarm();
346  clearMission();
347  pubTargetWYaw(POS_CONTROL, m_uav_pose.pose.position.y,
348  -m_uav_pose.pose.position.x, m_uav_pose.pose.position.z,
349  yaw_);
350  break;
351 
352  case LAND:
354  shutdownSwarm();
355  if (landCb())
356  {
358  ROS_WARN("DDrone: LAND");
359  }
360  break;
361 
362  default:
363  break;
364  }
365 }
366 
368 {
369  ROS_INFO("Initialize Setpoints...");
370  calculateYaw();
371  ros::Rate rate(20.0);
372  ros::Time last_request = ros::Time::now();
373  // Make Sure FCU is connected, wait for 5s if not connected.
374  while (ros::ok() && !uav_current_state.connected)
375  {
376  ros::spinOnce();
377  rate.sleep();
378  if (ros::Time::now() - last_request > ros::Duration(5.0))
379  {
380  ROS_ERROR("FCU not connect for 5s. Stop takeoff procedure.");
381  return;
382  }
383  }
384  ROS_INFO("FCU Connected");
385  // send a few setpoints before starting
386  mavros_msgs::PositionTarget init_sp;
387  init_sp.coordinate_frame = mavros_msgs::PositionTarget::FRAME_LOCAL_NED; // To be converted to NED in setpoint_raw plugin
388  init_sp.position.x = m_uav_pose.pose.position.x;
389  init_sp.position.y = m_uav_pose.pose.position.y;
390  init_sp.position.z = m_uav_pose.pose.position.z;
391  init_sp.velocity.x = 0;
392  init_sp.velocity.y = 0;
393  init_sp.velocity.z = 0;
394  init_sp.acceleration_or_force.x = 0;
395  init_sp.acceleration_or_force.y = 0;
396  init_sp.acceleration_or_force.z = 0;
397  init_sp.yaw = yaw_init;
398 
399  // set the inital position of mission start;
400  pos_init.x = m_uav_pose.pose.position.y;
401  pos_init.y = -m_uav_pose.pose.position.x;
402  pos_init.z = m_uav_pose.pose.position.z;
403 
404  // set MPC Initial
405  // MPC Initial as NWU
406  geometry_msgs::PoseStamped mpc_init_pos;
408  m_mpc_pos_init_pub.publish(mpc_init_pos);
409 
410  for (int i = 10; ros::ok() && i > 0; --i)
411  {
412  // Position_Setpoint_Pub.publish(init_sp);
413  ros::spinOnce();
414  rate.sleep();
415  }
416  mavros_msgs::SetMode offb_set_mode;
417  offb_set_mode.request.custom_mode = "OFFBOARD";
418 
419  mavros_msgs::CommandBool arm_cmd;
420  arm_cmd.request.value = true;
421 
422  bool is_mode_ready = false;
423  bool is_armed = false;
424  last_request = ros::Time::now();
425  // Set UAV mode to offboard and arm the vehicle
426  if (_simulation)
427  {
428  is_mode_ready = true;
429  is_armed = true;
430  }
431 
432  while (!(is_mode_ready && is_armed))
433  {
434  if (uav_current_state.mode != "OFFBOARD" &&
435  (ros::Time::now() - last_request > ros::Duration(1.0)))
436  {
437  ROS_INFO("try set offboard");
438  if (set_mode_client.call(offb_set_mode) &&
439  offb_set_mode.response.mode_sent)
440  {
441  ROS_INFO("Offboard enabled");
442  }
443  last_request = ros::Time::now();
444  }
445  else
446  {
447  if (!uav_current_state.armed &&
448  (ros::Time::now() - last_request > ros::Duration(1.0)))
449  {
450  ROS_INFO("try arm");
451  if (arming_client.call(arm_cmd) && arm_cmd.response.success)
452  {
453  ROS_INFO("Vehicle armed");
454  }
455  last_request = ros::Time::now();
456  }
457  is_mode_ready = (uav_current_state.mode == "OFFBOARD");
458  is_armed = uav_current_state.armed;
459  }
460  Position_Setpoint_Pub.publish(init_sp);
461  ros::spinOnce();
462  rate.sleep();
463  }
464  _relativeHeight = mpc_init_pos.pose.position.z + _flightHeight;
465 
466  pubTargetWYaw(POS_CONTROL, mpc_init_pos.pose.position.x,
467  mpc_init_pos.pose.position.y, _relativeHeight, yaw_init_nwu);
468 }
469 
471 {
472  // TODO:
473  // 2020-Mar-05: Land cmd request check
474  // 2019-Sep-25, only land at current location is supported by flight
475  // controller. msg data is only used for data package, all data will be
476  // ignored in flight control ROS_INFO("trying to land");
477  mavros_msgs::CommandTOL land_cmd;
478  land_cmd.request.yaw = 0;
479  land_cmd.request.latitude = 0;
480  land_cmd.request.longitude = 0;
481  land_cmd.request.altitude = 0;
482  if (_simulation == 0)
483  {
484  land_client.call(land_cmd);
485  if (land_cmd.response.success)
486  {
487  ROS_INFO("land command succeed");
488  return true;
489  }
490  else
491  {
492  ROS_ERROR("LAND Command Failed!");
493  return false;
494  }
495  }
496  else
497  {
498  // in Simulation, using position targte to achieve land
499  pubTargetWYaw(POS_CONTROL, m_uav_pose.pose.position.x,
500  m_uav_pose.pose.position.y, -10.0, yaw_);
501  return true;
502  }
503  return false;
504 }
505 
507 {
508  // TODO:
509  // 1. move takeoff to set-home
510  // 2. remove engine0 func
511  std_srvs::Trigger srv;
512  if (client_engine0.call(srv))
513  {
514  if (srv.response.success || _simulation)
515  {
516  ROS_WARN("ENGINE0");
517  mUavTaskState = kReady; // set it here cos the the set home may fail
518  // in inddor environment
519  }
520  }
521  else
522  {
523  ROS_ERROR("Failed to activate engine0");
524  return;
525  }
526 
527  // call set home in mavros
528  mavros_msgs::CommandHome mavros_set_home_srv;
529  mavros_set_home_srv.request.current_gps = true;
530  if (client_home.call(mavros_set_home_srv))
531  {
532  if (mavros_set_home_srv.response.success)
533  {
534  std::string info_string(" Set home succeed!");
535  ROS_INFO_STREAM(info_string);
536  }
537  else
538  {
539  std::string info_string(" Set home failed!");
540  ROS_INFO_STREAM(info_string);
541  }
542  }
543  else
544  {
545  std::string info_string(" Failed to call service "
546  "mavros_set_home!");
547  ROS_INFO_STREAM(info_string);
548  }
549 }
550 
551 // TODO:
552 // Do we need this function anymore?
553 void TaskManager::uiPointsCallback(const geometry_msgs::Polygon::ConstPtr &msg)
554 {
555  m_ui_points = *msg;
556  ui_points_selected = true;
557  ROS_INFO("Got polygon with %d points", int(m_ui_points.points.size()));
558 }
559 
560 void TaskManager::jumpWpCallback(const std_msgs::Bool::ConstPtr &msg)
561 {
562  m_jump = msg->data;
563  ROS_INFO("Skip current point!");
564 }
565 
567 {
568  tf::Quaternion q(
569  m_uav_pose.pose.orientation.x, m_uav_pose.pose.orientation.y,
570  m_uav_pose.pose.orientation.z, m_uav_pose.pose.orientation.w);
571  //std::cout << "=> m_uav_pose Quaternion ={" << m_uav_pose.pose.orientation.x << ", " << m_uav_pose.pose.orientation.y
572  // << ", " << m_uav_pose.pose.orientation.z << ", " << m_uav_pose.pose.orientation.w << "}\n";
573  tf::Matrix3x3 m(q);
574  double roll, pitch, yaw;
575  m.getRPY(roll, pitch, yaw);
576  cos_y = cos(yaw);
577  sin_y = sin(yaw);
578  ROS_INFO("Initialized yaw value %f: ", yaw);
579  yaw_initialized = true;
580  yaw_init = yaw;
581  yaw_init_enu = yaw;
582 
583  // Calculate yaw in NWU frame for take-off cmd
584  tf::Matrix3x3 R_enu2nwu;
585  R_enu2nwu.setRPY(0.0, 0.0, -3.1415926 / 2);
586  tf::Matrix3x3 R_nwu = R_enu2nwu * m;
587  double yaw_nwu;
588  R_nwu.getRPY(roll, pitch, yaw_nwu);
589  yaw_init_nwu = yaw_nwu;
590 }
591 
593 {
595  _wp_list[_points_id].z, m_gps_home.geo.latitude,
596  m_gps_home.geo.longitude, m_gps_home.geo.altitude);
597 
598  m_tgt.controller = POS_CONTROL;
599  m_tgt.tgt.x = gpsToEnu.yNorth;
600  m_tgt.tgt.y = -gpsToEnu.xEast;
601  // m_tgt.tgt.z = gpsToEnu.zUp;
602  m_tgt.tgt.z = _relativeHeight;
603  m_tgt_pub.publish(m_tgt);
604 }
605 
607 {
608  _wp_list.clear();
609  _ref_list.clear();
610  _points_id = 0;
611  m_tgt.tgt.x = m_uav_pose_nwu.pose.position.x;
612  m_tgt.tgt.y = m_uav_pose_nwu.pose.position.y;
613  ROS_INFO("Clear Mission");
614 }
615 
617 {
618  // //Read in the file for waypoints
619  std::ifstream infile(m_points_location);
620  std::string line;
621  clearMission();
622  bool succeed = false;
623  switch (_points_source_param)
624  {
625  case 0:
626  ROS_INFO("Loading from local waypoints file");
627 
628  while (std::getline(infile, line))
629  {
630  std::istringstream iss(line);
631  double _1, _2, _3;
632  if (!(iss >> _1 >> _2 >> _3))
633  {
634  ROS_ERROR("The data size is not correct!");
635  return false;
636  break;
637  } // error
638  geometry_msgs::Point p;
639  p.x = _1;
640  p.y = _2;
641  p.z = _3;
642  _wp_list.push_back(p);
643  }
644  if (_wp_list.size() > 0)
645  {
646  ROS_INFO("Goto wp: 0");
647  // m_pos_cmd_pub.publish(_wp_list[_points_id]);
648  // pubGpstgt();
651  // Update m_tgt.tgt (NWU) for checking target reach
652  m_tgt.tgt.x = _wp_list[_points_id].x;
653  m_tgt.tgt.y = _wp_list[_points_id].y;
654  m_tgt.tgt.z = _wp_list[_points_id].z;
655  succeed = true;
656  std::cout << " _wp_list[" << _points_id << "] = " << _wp_list[_points_id].x << " " << _wp_list[_points_id].y
657  << " " << _wp_list[_points_id].z << std::endl;
658  ROS_INFO("Points have been loaded!");
659  }
660  break;
661 
662  // case 1:
663  // ROS_INFO("Loading from refrence waypoints file");
664  // while (std::getline(infile, line))
665  // {
666  // std::istringstream iss(line);
667  // double _1, _2, _3, _4, _5, _6, _7, _8, _9;
668  // if (!(iss >> _1 >> _2 >> _3>> _4 >> _5 >> _6>> _7 >> _8 >>
669  // _9))
670  // {
671  // ROS_ERROR("The data size is not correct!");
672  // return false;
673  // break;
674  // } // error
675  // common_msgs::state p;
676  // p.pos.x = _1;
677  // p.pos.y = _2;
678  // p.pos.z = _3;
679  // p.vel.x = _4;
680  // p.vel.y = _5;
681  // p.vel.z = _6;
682  // p.acc.x = _7;
683  // p.acc.y = _8;
684  // p.acc.z = _9;
685  // _ref_list.push_back(p);
686 
687  // }
688  // ROS_INFO("Points have been loaded!");
689  // succeed = true;
690  // break;
691  // case 2:
692 
693  // if(ui_points_selected)
694  // {
695  // ROS_INFO("Loading from ui selected waypoints");
696  // int p_i = 0;
697  // while (p_i<m_ui_points.points.size())
698  // {
699  // geometry_msgs::Point p;
700  // p.x = m_ui_points.points[p_i].x * cos_y -
701  // m_ui_points.points[p_i].y * sin_y; p.y =
702  // m_ui_points.points[p_i].x * sin_y +
703  // m_ui_points.points[p_i].y * cos_y; p.z =
704  // m_ui_points.points[p_i].z; _wp_list.push_back(p); p_i +=
705  // 1;
706 
707  // }
708 
709  // if (_wp_list.size()>0)
710  // {
711  // ROS_INFO("Goto wp: 0");
712  // m_pos_cmd_pub.publish(_wp_list[_points_id]);
713  // succeed = true;
714  // ROS_INFO("Points have been loaded!");
715  // }
716  // }
717  // else{
718  // ROS_ERROR("Please select points from the UI first!");
719  // succeed = false;
720  // }
721  // break;
722 
723  case 3:
724  ROS_INFO("Loading from velocity points from file");
725  while (std::getline(infile, line))
726  {
727  std::istringstream iss(line);
728  double _1, _2, _3, _4;
729  if (!(iss >> _1 >> _2 >> _3 >> _4))
730  {
731  ROS_ERROR("The data size is not correct!");
732  return false;
733  break;
734  } // error
735  geometry_msgs::Point p;
736  p.x = _2;
737  p.y = _3;
738  p.z = _4;
739  _wp_list.push_back(p);
740  }
741  ROS_INFO("Points have been loaded!");
742  succeed = true;
743  break;
744 
745  default:
746  ROS_ERROR("Please choose the correct mission points formation!");
747  succeed = false;
748  break;
749  }
750  return succeed;
751 }
752 
753 void TaskManager::currentStateCallback(const common_msgs::state::ConstPtr &msg)
754 {
755  // // update the current uav position
756  _curr.x = msg->pos.x;
757  _curr.y = msg->pos.y;
758  _curr.z = msg->pos.z;
759 
760  mavros_msgs::PositionTarget pos_sp;
761  // MAVROS pos_sp in ENU frame, msg is in NWU frame
762  pos_sp.coordinate_frame = mavros_msgs::PositionTarget::FRAME_LOCAL_NED; // To be converted to NED in setpoint_raw plugin
763  pos_sp.position.x = -msg->pos.y;
764  pos_sp.position.y = msg->pos.x;
765  pos_sp.position.z = msg->pos.z;
766  pos_sp.velocity.x = -msg->vel.y;
767  pos_sp.velocity.y = msg->vel.x;
768  pos_sp.velocity.z = msg->vel.z;
769  pos_sp.acceleration_or_force.x = -msg->acc.y;
770  pos_sp.acceleration_or_force.y = msg->acc.x;
771  pos_sp.acceleration_or_force.z = msg->acc.z;
772  double yaw_sp_enu = msg->yaw.x + 1.5708;
773  // ensure yaw is in range of (-pi, pi)
774  if (yaw_sp_enu > 3.1415926)
775  {
776  yaw_sp_enu -= 3.1415926 * 2;
777  }
778  else if (yaw_sp_enu < -3.1415926)
779  {
780  yaw_sp_enu += 3.1415926 * 2;
781  }
782  pos_sp.yaw = yaw_sp_enu;
783  // typemask 32768 will request rpt controller in px4
784  pos_sp.type_mask = 32768;
785  Position_Setpoint_Pub.publish(pos_sp);
786 }
787 
788 void TaskManager::missionTimer(const ros::TimerEvent &)
789 {
790  switch (_points_source_param)
791  {
792  case 0:
793 
794  case 2:
795  checkReached();
796  break;
797  case 1:
798  if (_points_id < _ref_list.size() - 1)
799  {
800  m_ref_pub.publish(_ref_list[_points_id]);
801  std::cout << "Goto next ref: " << _points_id << std::endl;
802  std::cout << _ref_list[_points_id].pos.x << " "
803  << _ref_list[_points_id].pos.y << " "
804  << _ref_list[_points_id].pos.z << std::endl;
805  _points_id++;
806  }
807 
808  case 3: // vcmd
809  if (_points_id < _wp_list.size() - 1)
810  {
813  std::cout << "Goto next ref: " << _points_id << std::endl;
814  std::cout << _wp_list[_points_id].x << " " << _wp_list[_points_id].y
815  << " " << _wp_list[_points_id].z << std::endl;
816  _points_id++;
817  }
818  break;
819  default:
820  ROS_ERROR("Please choose the correct mission points formation!");
821  break;
822  }
823 }
824 
826 {
827  // calculate the distance between the current position to the wp (NWU)
828  geometry_msgs::Point dist;
829  dist.x = m_uav_pose_nwu.pose.position.x - m_tgt.tgt.x;
830  dist.y = m_uav_pose_nwu.pose.position.y - m_tgt.tgt.y;
831  // dist.z = m_uav_pose.pose_nwu.position.z - m_tgt.tgt.z;
832 
833  // if dist is small enough
834  if (dist.x * dist.x + dist.y * dist.y < 2.0 || m_jump)
835  {
836  // land when approach target reached
837  if (m_approach)
838  {
839  m_mission_timer.stop();
840  if (landCb())
841  {
842  ROS_INFO("UAV is landing!");
843  }
844  }
845  else if (_points_id < _wp_list.size() - 1)
846  {
847  _points_id++;
848  // m_pos_cmd_pub.publish(_wp_list[_points_id]);
849  // pubGpstgt();
852  // Update m_tgt.tgt (NWU) for checking target reach
853  m_tgt.tgt.x = _wp_list[_points_id].x;
854  m_tgt.tgt.y = _wp_list[_points_id].y;
855  m_tgt.tgt.z = _wp_list[_points_id].z;
856  std::cout << "Goto wp: " << _points_id << std::endl;
857  std::cout << " _wp_list[" << _points_id << "] = " << _wp_list[_points_id].x << " " << _wp_list[_points_id].y
858  << " " << _wp_list[_points_id].z << std::endl;
859  }
860  m_jump = false;
861  }
862 }
863 
864 void TaskManager::pubErrorState(std::int8_t val)
865 {
866  std_msgs::Byte uav_error;
867  uav_error.data = val;
868  m_error_state_pub.publish(uav_error);
869 }
870 
871 // TODO:
872 // revise or remove
873 void TaskManager::preFlightCheck(uint16_t &pre_flight_check)
874 {
875  for (int position = 0; position < 16; position++)
876  {
877  bool is_set = (pre_flight_check & (1 << position)) >> position;
878  if (is_set)
879  {
880  pubErrorState(position); // send error to GCS
881  switch (position)
882  {
883  case kAttitudeRollError:
884  ROS_ERROR("Attitude Roll Error");
885  break;
886  case kAttitudePitchError:
887  ROS_ERROR("Attitude Pitch Error");
888  break;
889  case kMagNError:
890  ROS_ERROR("Attitude Mag North Error");
891  break;
892  case kMagEError:
893  ROS_ERROR("Attitude Mag East Error");
894  break;
895  case kMagDError:
896  ROS_ERROR("Attitude Mag Z Error");
897  break;
898  case kAccNError:
899  ROS_ERROR("Attitude Acc North Error");
900  break;
901  case kAccEError:
902  ROS_ERROR("Attitude Acc East Error");
903  break;
904  case kAccDError:
905  ROS_ERROR("Attitude Acc Z Error");
906  break;
907  case kGPSEphError:
908  ROS_ERROR("Attitude GPS EPH Error");
909  break;
910  case kGPSEpvError:
911  ROS_ERROR("Attitude GPS EPV Error");
912  break;
913  case kGPSVelNError:
914  ROS_ERROR("Attitude GPS Velocity North Error");
915  break;
916  case kGPSVelEError:
917  ROS_ERROR("Attitude GPS Velocity East Error");
918  break;
919  case kGPSVelDError:
920  ROS_ERROR("Attitude GPS Velocity Z Error");
921  break;
922  case kGPSTError:
923  ROS_ERROR("Attitude GPS Time Error");
924  break;
925  case kImuError:
926  ROS_ERROR("Attitude IMU stuck Error");
927  break;
928  case kHealth:
929  ROS_INFO("All Good!");
930  break;
931  }
932  }
933  }
934 }
935 
936 // TODO:
937 // Revise or remove
938 void TaskManager::inFlightCheck(uint16_t &in_flight_check)
939 {
940  // In flight Error for GCS
941  // "Arm Error", // 16
942  // "return home", // 17
943  // "Auto-Land", // 18
944  // "IFC: Flight termination mode triggered.", // 19
945  // "IFC: Soft Geo-fence Violated.", // 20
946  // "IFC: Hard Geo-fence Violated.", // 21
947  // "IFC: Battery Low!", // 22
948  // "IFC: GPS Failed.", // 23
949  // "IFC:Large Attitude!"]; //24
950 
951  uint16_t error_state = 0;
952  for (int position = 0; position < 10; position++)
953  {
954  // handle info stored in bits 1,2, 4 and 6
955  if (position == 0 || position == 4)
956  {
957  continue;
958  }
959  else if (position == 1)
960  {
961  error_state = (in_flight_check & 0x03); // get last 2 bits
962  switch (int(error_state))
963  {
964  case 0:
965  ROS_ERROR("Arm Error");
966  pubErrorState(16);
967  break;
968  case 1:
969  ROS_WARN("Disarmed");
970  break;
971  case 2:
972  ROS_WARN("Armed");
973  break;
974  case 3:
975  ROS_WARN("Pre-Armed");
976  break;
977  }
978  continue; // exit current loop
979  }
980  else if (position == 5)
981  {
982  error_state = (in_flight_check & 0x30) >> 4; // get 5th and 6th bits
983  switch (int(error_state))
984  {
985  case 0:
986  break;
987  case 1:
988  // ROS_ERROR("RTL");
989  std::cout << ros::Time::now() << " IFC: RTL "
990  << "\n";
991  pubErrorState(17);
992  TaskTerminateFlag = true;
993  break;
994  case 2:
995  // ROS_ERROR("Auto-Land");
996  std::cout << ros::Time::now() << " IFC:Auto-Land "
997  << "\n";
998  pubErrorState(18);
999  TaskTerminateFlag = true;
1000  break;
1001  case 3:
1002  ROS_ERROR("IFC: Flight termination mode triggered.");
1003  pubErrorState(19);
1004  TaskTerminateFlag = true;
1005  break;
1006  }
1007  continue; // exit current loop
1008  }
1009  // handle others
1010  bool is_set = (in_flight_check & (1 << position)) >> position;
1011  if (is_set)
1012  {
1013  switch (position)
1014  {
1015  case kSoftGeoViolated:
1016  ROS_ERROR("IFC: Soft Geo-fence Violated.");
1017  pubErrorState(20);
1018  break;
1019  case kHardGeoViolated:
1020  ROS_ERROR("IFC: Hard Geo-fence Violated.");
1021  pubErrorState(21);
1022  break;
1023  case kBatteryLow:
1024  ROS_ERROR("IFC: Battery Low!");
1025  pubErrorState(22);
1026  break;
1027  case kGPSFail:
1028  ROS_ERROR("IFC: GPS Failed.");
1029  pubErrorState(23);
1030  TaskTerminateFlag = true;
1031  break;
1032  case kAttituteOutofRange:
1033  ROS_ERROR("IFC:Large Attitude!");
1034  pubErrorState(24);
1035  break;
1036  }
1037  }
1038  }
1039 }
1040 
1042  const diagnostic_msgs::DiagnosticArray::ConstPtr &msg)
1043 {
1044 
1045  uint16_t pre_flight_check = 0;
1046  uint16_t in_flight_check = 0;
1047 
1048  for (int i = 0; i < msg->status.size(); i++)
1049  {
1050  if (msg->status[i].name == "mavros: System")
1051  {
1052  for (int val = 0; val < msg->status[i].values.size(); val++)
1053  {
1054  if (msg->status[i].values[val].key == "Errors count #3")
1055  {
1056  pre_flight_check =
1057  std::stoi(msg->status[i].values[val].value);
1058  // ROS_INFO_STREAM("pre_flight_check: " <<
1059  // pre_flight_check);
1060  if (pre_flight_check &&
1061  (pre_flight_check != last_pre_flight_check))
1062  {
1063  last_pre_flight_check = pre_flight_check;
1064  preFlightCheck(pre_flight_check);
1065  }
1066  }
1067  if (msg->status[i].values[val].key == "Errors count #4")
1068  {
1069  in_flight_check =
1070  std::stoi(msg->status[i].values[val].value);
1071  // ROS_INFO_STREAM("in_flight_check: " << in_flight_check);
1072 
1073  if (in_flight_check &&
1074  (in_flight_check != last_in_flight_check))
1075  {
1076  last_in_flight_check = in_flight_check;
1077  if (int(in_flight_check) <= 3)
1078  {
1079  TaskTerminateFlag = false;
1080  }
1081  inFlightCheck(in_flight_check);
1082  }
1083 
1084  if ((mUavTaskState != kIdle) && (_simulation == 0) &&
1086  {
1087  ROS_ERROR("Task Termination is Activated!");
1088  m_swarm.data = false;
1089  m_swarm_pub.publish(m_swarm);
1090  }
1091  }
1092  }
1093  break;
1094  }
1095  }
1096 }
1097 
1098 geometry_msgs::PoseStamped
1099 TaskManager::transform_orientation_enu_nwu(geometry_msgs::PoseStamped msg)
1100 {
1101  tf::Matrix3x3 R_enu2nwu;
1102  R_enu2nwu.setRPY(0.0, 0.0, -3.1415926 / 2);
1103  // convert position
1104  // testing:
1105  tf::Vector3 pos(msg.pose.position.x, msg.pose.position.y,
1106  msg.pose.position.z);
1107  tf::Vector3 pos_nwu = R_enu2nwu * pos;
1108  // convert orientation
1109  tf::Quaternion quat(msg.pose.orientation.x, msg.pose.orientation.y,
1110  msg.pose.orientation.z, msg.pose.orientation.w);
1111  tf::Matrix3x3 R(quat);
1112  tf::Matrix3x3 R_nwu = R_enu2nwu * R;
1113  tf::Quaternion quat_nwu;
1114  R_nwu.getRotation(quat_nwu);
1115 
1116  geometry_msgs::PoseStamped msg_nwu;
1117 
1118  // data in NWU
1119  msg_nwu.pose.position.x = pos_nwu[0];
1120  msg_nwu.pose.position.y = pos_nwu[1];
1121  msg_nwu.pose.position.z = pos_nwu[2];
1122  msg_nwu.pose.orientation.x = quat_nwu[0];
1123  msg_nwu.pose.orientation.y = quat_nwu[1];
1124  msg_nwu.pose.orientation.z = quat_nwu[2];
1125  msg_nwu.pose.orientation.w = quat_nwu[3];
1126 
1127  return msg_nwu;
1128 }
kAttituteOutofRange
@ kAttituteOutofRange
Definition: ddrone_task_manager.h:101
TaskManager::_ref_list
std::vector< common_msgs::state > _ref_list
reference list from file
Definition: ddrone_task_manager.h:335
SWARM
#define SWARM
Definition: ddrone_task_manager.h:39
kGPSTError
@ kGPSTError
13: gpsT
Definition: ddrone_task_manager.h:80
POS_CONTROL
#define POS_CONTROL
Definition: ddrone_task_manager.h:42
kAttitudeRollError
@ kAttitudeRollError
0: roll
Definition: ddrone_task_manager.h:67
TaskManager::m_tgt_pub
ros::Publisher m_tgt_pub
target publisher: /nndp_cpp/tgt
Definition: ddrone_task_manager.h:310
HOVER
#define HOVER
Definition: ddrone_task_manager.h:40
kIdle
@ kIdle
Definition: ddrone_task_manager.h:52
kMagEError
@ kMagEError
3: magE
Definition: ddrone_task_manager.h:70
TaskManager::velYawTgtCallback
void velYawTgtCallback(const common_msgs::target::ConstPtr &msg)
get velocity and yaw command
Definition: ddrone_task_manager.cpp:149
GpsUtils::xEast
double xEast
East-North-Up coordinates x in a Local Tangent Plane.
Definition: gpsUtils.h:112
TaskManager::m_pcmd_sub
ros::Subscriber m_pcmd_sub
subscribe /posTgtFromSwarm
Definition: ddrone_task_manager.h:325
TaskManager::last_in_flight_check
uint16_t last_in_flight_check
previous inflight check
Definition: ddrone_task_manager.h:379
kTakeOff
@ kTakeOff
Definition: ddrone_task_manager.h:54
MISSION
#define MISSION
Definition: ddrone_task_manager.h:38
TaskManager::m_diagnostics_sub
ros::Subscriber m_diagnostics_sub
subscribe /diagnostics
Definition: ddrone_task_manager.h:329
TaskManager::m_mission_sub
ros::Subscriber m_mission_sub
subscribe mission from UI: /mission_from_ui
Definition: ddrone_task_manager.h:320
kMission
@ kMission
Definition: ddrone_task_manager.h:56
TaskManager::m_error_state_pub
ros::Publisher m_error_state_pub
error stater publisher (for UI): /task_manager/error_state
Definition: ddrone_task_manager.h:313
TaskManager::_nh
ros::NodeHandle _nh
ros node handle
Definition: ddrone_task_manager.h:307
kHealth
@ kHealth
15: no error
Definition: ddrone_task_manager.h:82
TaskManager::uav_state_sub
ros::Subscriber uav_state_sub
subscribe /mavros/state
Definition: ddrone_task_manager.h:332
TaskManager::currentStateCallback
void currentStateCallback(const common_msgs::state::ConstPtr &msg)
obtain current uav state
Definition: ddrone_task_manager.cpp:753
TaskManager::mUavTaskState
UavTaskState mUavTaskState
UAV current state: checkout enum UavTaskState.
Definition: ddrone_task_manager.h:347
TaskManager::missionCallback
void missionCallback(int8_t msg)
mission handler
Definition: ddrone_task_manager.cpp:266
TaskManager::m_uav_pose_sub
ros::Subscriber m_uav_pose_sub
subscribe current uav pose: /mavros/local_position/pose to update m_uav_pose
Definition: ddrone_task_manager.h:322
kAttitudePitchError
@ kAttitudePitchError
1: pitch
Definition: ddrone_task_manager.h:68
TaskManager::yaw_init_nwu
double yaw_init_nwu
initial yaw in nwu frame
Definition: ddrone_task_manager.h:366
TaskManager::gpsHomeCb
void gpsHomeCb(const mavros_msgs::HomePosition::ConstPtr &msg)
Get GPS home location.
Definition: ddrone_task_manager.cpp:237
kGPSVelDError
@ kGPSVelDError
12: velD
Definition: ddrone_task_manager.h:79
kAccEError
@ kAccEError
6: accE
Definition: ddrone_task_manager.h:73
TaskManager::velTgtCallback
void velTgtCallback(const geometry_msgs::Point::ConstPtr &msg)
get velocity command
Definition: ddrone_task_manager.cpp:176
TaskManager::gpsToEnuCur
GpsUtils gpsToEnuCur
current gps(from px4) to enu local frame
Definition: ddrone_task_manager.h:376
TaskManager::clearMission
void clearMission()
Clear misson.
Definition: ddrone_task_manager.cpp:606
TaskManager::yaw_control_
bool yaw_control_
flag set to control yaw
Definition: ddrone_task_manager.h:381
TaskManager::TaskTerminateFlag
bool TaskTerminateFlag
task terminate flag when inflight or preflight check failed
Definition: ddrone_task_manager.h:377
TaskManager::_wp_list
std::vector< geometry_msgs::Point > _wp_list
waypoint list from file
Definition: ddrone_task_manager.h:334
TaskManager::pubGpstgt
void pubGpstgt()
Convert target from GPS into ENU coordinate.
Definition: ddrone_task_manager.cpp:592
TaskManager::ui_points_selected
bool ui_points_selected
flag showing points selected from UI
Definition: ddrone_task_manager.h:371
TaskManager::m_points_location
std::string m_points_location
set waypoint location: /home/nvidia(default)
Definition: ddrone_task_manager.h:355
kAccDError
@ kAccDError
7: accD
Definition: ddrone_task_manager.h:74
TaskManager::m_mission_timer
ros::Timer m_mission_timer
mission call back timer
Definition: ddrone_task_manager.h:351
TaskManager::m_uav_pose_nwu
geometry_msgs::PoseStamped m_uav_pose_nwu
current pose in nwu
Definition: ddrone_task_manager.h:341
GpsUtils::yNorth
double yNorth
East-North-Up coordinates y in a Local Tangent Plane.
Definition: gpsUtils.h:113
kAccNError
@ kAccNError
5: accN
Definition: ddrone_task_manager.h:72
kGPSFail
@ kGPSFail
Definition: ddrone_task_manager.h:100
TaskManager::yaw_init
double yaw_init
initial yaw in enu frame
Definition: ddrone_task_manager.h:368
TaskManager::m_vcmd_sub
ros::Subscriber m_vcmd_sub
subscribe /velTgtFromSwarm
Definition: ddrone_task_manager.h:324
TaskManager::m_gps_cur
sensor_msgs::NavSatFix m_gps_cur
current gps location
Definition: ddrone_task_manager.h:364
TaskManager::yaw_initialized
bool yaw_initialized
flag showing yaw is initialized
Definition: ddrone_task_manager.h:370
ddrone_task_manager.h
kMagNError
@ kMagNError
2: magN
Definition: ddrone_task_manager.h:69
TaskManager::m_online_status_sub
ros::Subscriber m_online_status_sub
subscribe /swarm/online
Definition: ddrone_task_manager.h:331
TaskManager::uavPoseCallback
void uavPoseCallback(const geometry_msgs::PoseStamped::ConstPtr &msg)
get current uav pose
Definition: ddrone_task_manager.cpp:115
TaskManager::m_approach_cmd_sub
ros::Subscriber m_approach_cmd_sub
subscribe /swarm/approach
Definition: ddrone_task_manager.h:328
TaskManager::pubTarget
void pubTarget(bool controlMode, float tgtX, float tgtY, float tgtZ)
publish local target with control mode:
Definition: ddrone_task_manager.cpp:126
TaskManager::checkReached
void checkReached()
check if the uav reached the waypoint
Definition: ddrone_task_manager.cpp:825
TaskManager::m_gps_home
mavros_msgs::HomePosition m_gps_home
GPS home location.
Definition: ddrone_task_manager.h:363
TaskManager::sin_y
double sin_y
Definition: ddrone_task_manager.h:365
TaskManager::client_engine0
ros::ServiceClient client_engine0
removed service
Definition: ddrone_task_manager.h:356
TaskManager::swarm_pos_pub
ros::Publisher swarm_pos_pub
publish position in nwu: /task_manager/position_nwu
Definition: ddrone_task_manager.h:317
TaskManager::_simulation
bool _simulation
simulation mode is on if true
Definition: ddrone_task_manager.h:372
TaskManager::yaw_init_enu
double yaw_init_enu
initial yaw in enu frame
Definition: ddrone_task_manager.h:367
TaskManager::m_swarm
std_msgs::Bool m_swarm
swarm flag
Definition: ddrone_task_manager.h:373
TaskManager::pos_init
geometry_msgs::Point pos_init
the inital position of mission;
Definition: ddrone_task_manager.h:369
TaskManager::m_gps_home_sub
ros::Subscriber m_gps_home_sub
subscribe /mavros/home_position/home
Definition: ddrone_task_manager.h:326
kMagDError
@ kMagDError
4: magD
Definition: ddrone_task_manager.h:71
kSwarm
@ kSwarm
Definition: ddrone_task_manager.h:57
TaskManager::preFlightCheck
void preFlightCheck(uint16_t &pre_flight_check)
preflight Check
Definition: ddrone_task_manager.cpp:873
TaskManager::transform_orientation_enu_nwu
geometry_msgs::PoseStamped transform_orientation_enu_nwu(geometry_msgs::PoseStamped)
transform orientation from enu to nwu
Definition: ddrone_task_manager.cpp:1099
TaskManager::loadMission
bool loadMission()
load mission from UI or files
Definition: ddrone_task_manager.cpp:616
TaskManager::m_tgt
common_msgs::target m_tgt
current target point
Definition: ddrone_task_manager.h:343
TaskManager::m_skipCurPoint_sub
ros::Subscriber m_skipCurPoint_sub
subscribe /mission_skip_point
Definition: ddrone_task_manager.h:323
TaskManager::_points_source_param
int _points_source_param
Points from 0: local waypoints file; 1: refrence waypoints file; 2: ui selected waypoints; 3:velocity...
Definition: ddrone_task_manager.h:354
TaskManager::uiPointsCallback
void uiPointsCallback(const geometry_msgs::Polygon::ConstPtr &msg)
points for UI (lagacy function)
Definition: ddrone_task_manager.cpp:553
TaskManager::Position_Setpoint_Pub
ros::Publisher Position_Setpoint_Pub
Setpoints to MAVROS publisher: /mavros/setpoint_raw/local.
Definition: ddrone_task_manager.h:315
TaskManager::uavStateCb
void uavStateCb(const mavros_msgs::State::ConstPtr &msg)
Get UAV hardware state: connected/armed/guided/mode.
Definition: ddrone_task_manager.cpp:246
kBatteryLow
@ kBatteryLow
Definition: ddrone_task_manager.h:99
TaskManager::client_home
ros::ServiceClient client_home
/mavros/cmd/set_home service
Definition: ddrone_task_manager.h:357
TaskManager::engine0
void engine0()
removed for px4 1.8 version
Definition: ddrone_task_manager.cpp:506
TaskManager::onlineCallback
void onlineCallback(const std_msgs::Bool::ConstPtr &msg)
Landing triggered by offline status (msg: false)
Definition: ddrone_task_manager.cpp:228
TaskManager::m_gps_cur_sub
ros::Subscriber m_gps_cur_sub
subscribe /mavros/global_position/global
Definition: ddrone_task_manager.h:327
TaskManager::uav_current_state
mavros_msgs::State uav_current_state
uav hardware sate from /mavros/state
Definition: ddrone_task_manager.h:382
TaskManager::m_current_state_sub
ros::Subscriber m_current_state_sub
subscribe refrence: /rt_ref_gen/current_state
Definition: ddrone_task_manager.h:319
kGPSVelEError
@ kGPSVelEError
11: velE
Definition: ddrone_task_manager.h:78
kHover
@ kHover
Definition: ddrone_task_manager.h:55
kImuError
@ kImuError
14: imuStuck
Definition: ddrone_task_manager.h:81
TaskManager::m_jump
bool m_jump
Definition: ddrone_task_manager.h:350
VEL_CONTROL
#define VEL_CONTROL
Definition: ddrone_task_manager.h:43
TaskManager::m_swarm_pub
ros::Publisher m_swarm_pub
trigger swarm publisher: /task_manager/swarm
Definition: ddrone_task_manager.h:312
TaskManager::last_pre_flight_check
uint16_t last_pre_flight_check
precious preflight check
Definition: ddrone_task_manager.h:380
TAKEOFF
#define TAKEOFF
Definition: ddrone_task_manager.h:37
TaskManager::posTgtCallback
void posTgtCallback(const geometry_msgs::Point::ConstPtr &msg)
get gps position command and transfer it into UAV local coordinate
Definition: ddrone_task_manager.cpp:183
TaskManager::pubTargetWYaw
void pubTargetWYaw(bool controlMode, float tgtX, float tgtY, float tgtZ, float yaw)
publish local target with yaw, and set control mode:
Definition: ddrone_task_manager.cpp:137
TaskManager::yaw_
double yaw_
param for calculating yaw
Definition: ddrone_task_manager.h:365
kSoftGeoViolated
@ kSoftGeoViolated
Definition: ddrone_task_manager.h:93
TaskManager::m_ref_pub
ros::Publisher m_ref_pub
refrence from file publisher: /task_manager/current_state
Definition: ddrone_task_manager.h:309
TaskManager::TaskManager
TaskManager(ros::NodeHandle &nodeHandle)
Definition: ddrone_task_manager.cpp:9
TaskManager::set_mode_client
ros::ServiceClient set_mode_client
/mavros/set_mode service
Definition: ddrone_task_manager.h:360
TaskManager::inPcmdMode
bool inPcmdMode
position command flag
Definition: ddrone_task_manager.h:378
TaskManager::m_mpc_pos_init_pub
ros::Publisher m_mpc_pos_init_pub
mpc initial position publisher: /task_manager/mpc_init_position_nwu
Definition: ddrone_task_manager.h:314
TaskManager::m_pos_cmd_pub
ros::Publisher m_pos_cmd_pub
way points publisher: /dummy/pos_cmd
Definition: ddrone_task_manager.h:308
kGPSVelNError
@ kGPSVelNError
10: velN
Definition: ddrone_task_manager.h:77
TaskManager::land_client
ros::ServiceClient land_client
/mavros/cmd/land service
Definition: ddrone_task_manager.h:358
TaskManager::missionTimer
void missionTimer(const ros::TimerEvent &)
callback function for running mission (default: 0.2)
Definition: ddrone_task_manager.cpp:788
TaskManager::_points_id
int _points_id
Using this value to label points read from a file.
Definition: ddrone_task_manager.h:353
LAND
#define LAND
Definition: ddrone_task_manager.h:41
TaskManager::m_uav_pose
geometry_msgs::PoseStamped m_uav_pose
current pose(enu) from /mavros/local_position/pose
Definition: ddrone_task_manager.h:338
TaskManager::_flightHeight
double _flightHeight
takeoff flight height
Definition: ddrone_task_manager.h:344
TaskManager::cos_y
double cos_y
Definition: ddrone_task_manager.h:365
TaskManager::~TaskManager
~TaskManager()
Definition: ddrone_task_manager.cpp:110
TaskManager::landCb
bool landCb()
call landing service
Definition: ddrone_task_manager.cpp:470
TaskManager::m_ui_points_sub
ros::Subscriber m_ui_points_sub
subscribe points from UI: /points_from_ui
Definition: ddrone_task_manager.h:321
kHardGeoViolated
@ kHardGeoViolated
Definition: ddrone_task_manager.h:94
TaskManager::inFlightCheck
void inFlightCheck(uint16_t &in_flight_check)
inflight Check
Definition: ddrone_task_manager.cpp:938
TaskManager::arming_client
ros::ServiceClient arming_client
/mavros/cmd/arming service
Definition: ddrone_task_manager.h:359
TaskManager::calculateYaw
void calculateYaw()
Calculate yaw angle from current attitude.
Definition: ddrone_task_manager.cpp:566
GpsUtils::GeodeticToEnu
void GeodeticToEnu(double lat, double lon, double h, double lat0, double lon0, double h0)
Converts the geodetic WGS-84 coordinated (lat, lon, h) to East-North-Up coordinates in a Local Tangen...
Definition: gpsUtils.h:90
GpsUtils::zUp
double zUp
East-North-Up coordinates z in a Local Tangent Plane.
Definition: gpsUtils.h:114
TaskManager::jumpWpCallback
void jumpWpCallback(const std_msgs::Bool::ConstPtr &msg)
Skip current waypoint.
Definition: ddrone_task_manager.cpp:560
kGPSEphError
@ kGPSEphError
8: eph
Definition: ddrone_task_manager.h:75
TaskManager::diagnosticsCallback
void diagnosticsCallback(const diagnostic_msgs::DiagnosticArray::ConstPtr &msg)
Analyse preflight and inflight check for UAV.
Definition: ddrone_task_manager.cpp:1041
TaskManager::takeoff
void takeoff()
Take off.
Definition: ddrone_task_manager.cpp:367
TaskManager::m_approach
bool m_approach
approach flag
Definition: ddrone_task_manager.h:374
TaskManager::gpsCurCb
void gpsCurCb(const sensor_msgs::NavSatFix::ConstPtr &msg)
Get UAV current GPS location.
Definition: ddrone_task_manager.cpp:242
kLand
@ kLand
Definition: ddrone_task_manager.h:58
kReady
@ kReady
Definition: ddrone_task_manager.h:53
TaskManager::_relativeHeight
double _relativeHeight
height relative to the ground
Definition: ddrone_task_manager.h:345
TaskManager::_curr
geometry_msgs::Point _curr
current uav position
Definition: ddrone_task_manager.h:336
TaskManager::pubErrorState
void pubErrorState(std::int8_t val)
Publish Error State from preflight and inflight state.
Definition: ddrone_task_manager.cpp:864
TaskManager::_missionPeriod
double _missionPeriod
mission call back period: 0.2s
Definition: ddrone_task_manager.h:352
kGPSEpvError
@ kGPSEpvError
9: epv
Definition: ddrone_task_manager.h:76
TaskManager::shutdownSwarm
void shutdownSwarm()
shutdown Swarm
Definition: ddrone_task_manager.cpp:201
TaskManager::posYawTgtCallback
void posYawTgtCallback(const common_msgs::target::ConstPtr &msg)
get position and yaw command
Definition: ddrone_task_manager.cpp:155
TaskManager::webCmdCallback
void webCmdCallback(const std_msgs::Byte::ConstPtr &msg)
Get command from web GCS and pass to mission callback.
Definition: ddrone_task_manager.cpp:260
TaskManager::gpsToEnu
GpsUtils gpsToEnu
current gps target(from user) to enu local frame
Definition: ddrone_task_manager.h:375
TaskManager::approachCallback
void approachCallback(const std_msgs::Bool::ConstPtr &msg)
approach command for kerrigan project
Definition: ddrone_task_manager.cpp:211
TaskManager::m_ui_points
geometry_msgs::Polygon m_ui_points
polygon points from UI
Definition: ddrone_task_manager.h:362


ddrone_task_manager
Author(s):
autogenerated on Thu Jul 30 2020 17:17:03