You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

814 lines
24 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. #include "objectFlyHunter.h"
  2. #define LOG(X) m_pLog->Log("FlyHunter", this, X)
  3. #define LOG_ERROR(X) m_pLog->Log("FlyHunter", this, _LOG_ERROR, X)
  4. objectFlyHunter::objectFlyHunter(config_setting_t * Settings) :
  5. basicObject()
  6. {
  7. m_pLog = basicLogCollection::getInstance();
  8. updateOrientation = NULL;
  9. m_bArmed = false;
  10. m_eCurrentMode = FH_NO_CONNECTION;
  11. m_bUAV_type = -1;
  12. m_bUAV_ctrl = -1;
  13. m_bUAV_bMODE = 0;
  14. m_nUAV_cMODE = 0;
  15. m_pSettings = basicSettingsProvider::getInstance()->getSubNode(Settings, (CSTR) "FLY_HUNTER");
  16. m_pProtocol = new protocolMAVLINK(m_pSettings);
  17. if (m_pSettings != NULL)
  18. {
  19. config_setting_t * pSetting;
  20. double tVal1, tVal2, tVal3;
  21. pSetting = config_setting_get_member(m_pSettings, "LAST_POSITION_LAT");
  22. if (pSetting == NULL)
  23. {
  24. pSetting = config_setting_add(m_pSettings, "LAST_POSITION_LAT", CONFIG_TYPE_FLOAT);
  25. tVal1 = 0.;
  26. if (pSetting != NULL)
  27. {
  28. config_setting_set_float(pSetting, tVal1);
  29. basicSettingsProvider::getInstance()->compromise();
  30. };
  31. }
  32. else
  33. {
  34. tVal1 = config_setting_get_float(pSetting);
  35. };
  36. pSetting = config_setting_get_member(m_pSettings, "LAST_POSITION_LON");
  37. if (pSetting == NULL)
  38. {
  39. pSetting = config_setting_add(m_pSettings, "LAST_POSITION_LON", CONFIG_TYPE_FLOAT);
  40. tVal2 = 0.;
  41. if (pSetting != NULL)
  42. {
  43. config_setting_set_float(pSetting, tVal2);
  44. basicSettingsProvider::getInstance()->compromise();
  45. };
  46. }
  47. else
  48. {
  49. tVal2 = config_setting_get_float(pSetting);
  50. };
  51. pSetting = config_setting_get_member(m_pSettings, "LAST_POSITION_ALT");
  52. if (pSetting == NULL)
  53. {
  54. pSetting = config_setting_add(m_pSettings, "LAST_POSITION_ALT", CONFIG_TYPE_FLOAT);
  55. tVal3 = 0.;
  56. if (pSetting != NULL)
  57. {
  58. config_setting_set_float(pSetting, tVal3);
  59. basicSettingsProvider::getInstance()->compromise();
  60. };
  61. }
  62. else
  63. {
  64. tVal3 = config_setting_get_float(pSetting);
  65. };
  66. m_oPosition.setPositionWGS84(tVal1, tVal2, tVal3);
  67. pSetting = config_setting_get_member(m_pSettings, "LAST_POSITION_ROLL");
  68. if (pSetting == NULL)
  69. {
  70. pSetting = config_setting_add(m_pSettings, "LAST_POSITION_ROLL", CONFIG_TYPE_FLOAT);
  71. tVal1 = 0.;
  72. if (pSetting != NULL)
  73. {
  74. config_setting_set_float(pSetting, tVal1);
  75. basicSettingsProvider::getInstance()->compromise();
  76. };
  77. }
  78. else
  79. {
  80. tVal1 = config_setting_get_float(pSetting);
  81. };
  82. pSetting = config_setting_get_member(m_pSettings, "LAST_POSITION_PITCH");
  83. if (pSetting == NULL)
  84. {
  85. pSetting = config_setting_add(m_pSettings, "LAST_POSITION_PITCH", CONFIG_TYPE_FLOAT);
  86. tVal2 = 0.;
  87. if (pSetting != NULL)
  88. {
  89. config_setting_set_float(pSetting, tVal2);
  90. basicSettingsProvider::getInstance()->compromise();
  91. };
  92. }
  93. else
  94. {
  95. tVal2 = config_setting_get_float(pSetting);
  96. };
  97. pSetting = config_setting_get_member(m_pSettings, "LAST_POSITION_YAW");
  98. if (pSetting == NULL)
  99. {
  100. pSetting = config_setting_add(m_pSettings, "LAST_POSITION_YAW", CONFIG_TYPE_FLOAT);
  101. tVal3 = 0.;
  102. if (pSetting != NULL)
  103. {
  104. config_setting_set_float(pSetting, tVal3);
  105. basicSettingsProvider::getInstance()->compromise();
  106. };
  107. }
  108. else
  109. {
  110. tVal3 = config_setting_get_float(pSetting);
  111. };
  112. m_oPosition.setOrientationDeg(tVal1, tVal2, tVal3);
  113. pSetting = config_setting_get_member(m_pSettings, "LAST_POSITION_SPEED");
  114. if (pSetting == NULL)
  115. {
  116. pSetting = config_setting_add(m_pSettings, "LAST_POSITION_SPEED", CONFIG_TYPE_FLOAT);
  117. tVal1 = 0.;
  118. if (pSetting != NULL)
  119. {
  120. config_setting_set_float(pSetting, tVal1);
  121. basicSettingsProvider::getInstance()->compromise();
  122. };
  123. }
  124. else
  125. {
  126. tVal1 = config_setting_get_float(pSetting);
  127. };
  128. m_oPosition.setSpeed(tVal1);
  129. basicSettingsProvider::getInstance()->validate();
  130. }
  131. else
  132. {
  133. // Set Default settings
  134. m_oPosition.setPositionWGS84(0.f, 0.f);
  135. m_oPosition.setOrientationDeg(0.f, 0.f, 0.f);
  136. m_oPosition.setSpeed(0.f);
  137. };
  138. }
  139. objectFlyHunter::~objectFlyHunter()
  140. {
  141. basicThread::waitThreadEnd(true);
  142. }
  143. bool objectFlyHunter::cerate()
  144. {
  145. bool rV = false;
  146. m_mAccessProtector.lock();
  147. if (m_pProtocol->create())
  148. {
  149. rV = basicThread::init();
  150. }
  151. m_mAccessProtector.unlock();
  152. return rV;
  153. }
  154. bool objectFlyHunter::flyToWGS84(float lat, float lon, float alt)
  155. {
  156. return true;
  157. }
  158. bool objectFlyHunter::isVehicleAttached()
  159. {
  160. bool rV = false;
  161. m_mAccessProtector.lock();
  162. if (m_pProtocol != NULL)
  163. {
  164. rV = m_pProtocol->m_bUAV_Online;
  165. };
  166. m_mAccessProtector.unlock();
  167. return rV;
  168. }
  169. bool objectFlyHunter::isPairingDone()
  170. {
  171. bool rV = false;
  172. m_mAccessProtector.lock();
  173. if (m_pProtocol != NULL)
  174. {
  175. rV = m_pProtocol->m_bPairingFinished;
  176. };
  177. m_mAccessProtector.unlock();
  178. return rV;
  179. }
  180. bool objectFlyHunter::connectVia(CSTR a)
  181. {
  182. bool rV = false;
  183. m_mAccessProtector.lock();
  184. if (m_pProtocol->setUartDevice(a))
  185. {
  186. delete(m_pProtocol);
  187. m_pProtocol = new protocolMAVLINK(m_pSettings);
  188. if (m_pProtocol != NULL)
  189. {
  190. rV = m_pProtocol->create();
  191. };
  192. };
  193. m_mAccessProtector.unlock();
  194. return rV;
  195. }
  196. bool objectFlyHunter::isRadiosConnected(void)
  197. {
  198. return (m_eCurrentMode > FH_NO_CONNECTION);
  199. }
  200. /**
  201. * @param value battery voltage
  202. */
  203. double objectFlyHunter::filterVoltage(double value) const
  204. {
  205. return m_dLpfVoltage * 0.6f + value * 0.4f;
  206. }
  207. void objectFlyHunter::m_fThreadProc(void)
  208. {
  209. FH_COMMAND * pCMD = NULL;
  210. m_bThreadStatus = TH_WORKING;
  211. pthread_setname_np(pthread_self(), "objectFlyHunter");
  212. while (m_bThreadStatus < TH_ENDED)
  213. {
  214. if (m_qQueuedCommands.size())
  215. {
  216. pCMD = m_qQueuedCommands.front();
  217. }
  218. else
  219. {
  220. pCMD = NULL;
  221. }
  222. if (m_pProtocol->getConnectionStatus() == CS_DISCONNECTED)
  223. {
  224. m_eCurrentMode = FH_CONNECTION_ERROR;
  225. };
  226. switch (m_eCurrentMode)
  227. {
  228. case FH_CONNECTION_ERROR: break;
  229. case FH_NO_CONNECTION:
  230. if (m_pProtocol->getConnectionStatus() == CS_CONNECTED)
  231. {
  232. m_eCurrentMode = FH_WAIT_FOR_UAV;
  233. }
  234. break;
  235. case FH_WAIT_FOR_UAV:
  236. if (m_pProtocol->m_bPairingFinished)
  237. {
  238. m_eCurrentMode = FH_MODE_PREFLIGHT;
  239. }
  240. break;
  241. case FH_MODE_PREFLIGHT:
  242. if (pCMD != NULL)
  243. {
  244. switch (pCMD->type)
  245. {
  246. case FH_CMD_SET_BASE_MODE:
  247. if (pCMD->data != NULL)
  248. {
  249. uint8_t tMode;
  250. tMode = m_bUAV_bMODE | *((uint8_t *) pCMD->data);
  251. m_pProtocol->broadcastSetBaseMode(tMode);
  252. };
  253. break;
  254. case FH_CMD_SET_AP_MODE:
  255. if (pCMD->data != NULL)
  256. {
  257. uint32_t tMode;
  258. tMode = m_bUAV_bMODE | *((uint32_t *) pCMD->data);
  259. m_pProtocol->broadcastSetCustomMode(tMode);
  260. };
  261. break;
  262. case FH_CMD_FORCE_ARM:
  263. {
  264. m_pProtocol->broadcastArm(true, true);
  265. m_eCurrentMode = FH_MODE_ARMING;
  266. break;
  267. };
  268. case FH_CMD_ARM:
  269. {
  270. m_pProtocol->broadcastArm(true);
  271. m_eCurrentMode = FH_MODE_ARMING;
  272. break;
  273. };
  274. case FH_CMD_DISARM:
  275. {
  276. //?? Why at preflight mode!!
  277. m_pProtocol->broadcastArm(false);
  278. m_eCurrentMode = FH_MODE_DISARMING;
  279. break;
  280. };
  281. };
  282. };
  283. break;
  284. case FH_MODE_ARMING:
  285. if (m_pProtocol->getLastCmdStatus() > -1)
  286. {
  287. if (m_pProtocol->getLastCmdStatus() == MAV_RESULT_ACCEPTED)
  288. {
  289. m_eCurrentMode = FH_MODE_ARMED;
  290. }
  291. else
  292. {
  293. m_eCurrentMode = FH_MODE_PREFLIGHT;
  294. };
  295. };
  296. break;
  297. case FH_MODE_ARMED:
  298. if (pCMD != NULL)
  299. {
  300. switch (pCMD->type)
  301. {
  302. case FH_CMD_SET_BASE_MODE:
  303. if (pCMD->data != NULL)
  304. {
  305. uint8_t tMode;
  306. tMode = m_bUAV_bMODE | *((uint8_t *) pCMD->data);
  307. m_pProtocol->setMode(tMode);
  308. };
  309. break;
  310. case FH_CMD_SET_AP_MODE:
  311. if (pCMD->data != NULL)
  312. {
  313. uint32_t tMode;
  314. tMode = m_bUAV_bMODE | *((uint32_t *) pCMD->data);
  315. m_pProtocol->broadcastSetCustomMode(tMode);
  316. };
  317. break;
  318. case FH_CMD_ARM:
  319. {
  320. //?? Why at ARMED mode!!
  321. m_pProtocol->broadcastArm(true);
  322. m_eCurrentMode = FH_MODE_ARMING;
  323. break;
  324. };
  325. case FH_CMD_DISARM:
  326. {
  327. m_pProtocol->broadcastArm(false);
  328. m_eCurrentMode = FH_MODE_DISARMING;
  329. break;
  330. };
  331. };
  332. };
  333. break;
  334. case FH_MODE_DISARMING: break;
  335. };
  336. if (m_eCurrentMode > FH_WAIT_FOR_UAV)
  337. {
  338. // Update statuses
  339. m_bUAV_type = m_pProtocol->m_sHeartBit.type;
  340. m_bUAV_ctrl = m_pProtocol->m_sHeartBit.autopilot;
  341. m_bUAV_bMODE = m_pProtocol->m_sHeartBit.base_mode;
  342. m_nUAV_cMODE = m_pProtocol->m_sHeartBit.custom_mode;
  343. // if Position Accurate
  344. float roll = 0.f, pitch = 0.f, yaw = 0.f;
  345. roll = m_pProtocol->m_sAttitude.roll;
  346. pitch = m_pProtocol->m_sAttitude.pitch;
  347. yaw = m_pProtocol->m_sAttitude.yaw;
  348. m_oPosition.setOrientationRad(roll, pitch, yaw);
  349. if (updateOrientation != NULL)
  350. {
  351. updateOrientation(m_oPosition.getRotX_deg(), m_oPosition.getRotY_deg(), m_oPosition.getRotZ_deg());
  352. }
  353. };
  354. if (pCMD != NULL)
  355. {
  356. if (pCMD->data != NULL)
  357. {
  358. free(pCMD->data);
  359. }
  360. m_qQueuedCommands.pop();
  361. };
  362. // Update Data FROM UAV
  363. if (m_pProtocol->m_bSystemStatusDataActual)
  364. {
  365. m_pProtocol->m_bSystemStatusDataActual = false;
  366. // Prepare for sending data to the realtime plotter, which is every field excluding onboard_control_sensors_present.
  367. // quint64 time = getUnixTime();
  368. // emit valueChanged(uasId, statusName().arg("Sensors Enabled"), "bits", state.onboard_control_sensors_enabled, time);
  369. // emit valueChanged(uasId, statusName().arg("Sensors Health"), "bits", state.onboard_control_sensors_health, time);
  370. // emit valueChanged(uasId, statusName().arg("Comms Errors"), "-", state.errors_comm, time);
  371. // emit valueChanged(uasId, statusName().arg("Errors Count 1"), "-", state.errors_count1, time);
  372. // emit valueChanged(uasId, statusName().arg("Errors Count 2"), "-", state.errors_count2, time);
  373. // emit valueChanged(uasId, statusName().arg("Errors Count 3"), "-", state.errors_count3, time);
  374. // emit valueChanged(uasId, statusName().arg("Errors Count 4"), "-", state.errors_count4, time);
  375. // Process CPU load.
  376. // emit loadChanged(this, m_sSystemStatus.load / 10.0);
  377. // emit valueChanged(uasId, statusName().arg("CPU Load"), "%", m_sSystemStatus.load / 10.0, time);
  378. // Battery charge/time remaining/voltage calculations
  379. double currentVoltage = m_pProtocol->m_sSystemStatus.voltage_battery / 1000.0;
  380. double lpVoltage = filterVoltage(currentVoltage);
  381. // tickLowpassVoltage = tickLowpassVoltage * 0.8 + 0.2 * currentVoltage;
  382. // We don't want to tick above the threshold
  383. // if (tickLowpassVoltage > tickVoltage) {
  384. // lastTickVoltageValue = tickLowpassVoltage;
  385. // };
  386. // if ((startVoltage > 0.0) && (tickLowpassVoltage < tickVoltage) && (fabs(lastTickVoltageValue - tickLowpassVoltage) > 0.1)
  387. /* warn if lower than treshold */
  388. // && (lpVoltage < tickVoltage)
  389. /* warn only if we have at least the voltage of an empty LiPo cell, else we're sampling something wrong */
  390. // && (currentVoltage > 3.3)
  391. /* warn only if current voltage is really still lower by a reasonable amount */
  392. // && ((currentVoltage - 0.2) < tickVoltage)
  393. /* warn only every 12 seconds */
  394. // && (QGC::groundTimeUsecs() - lastVoltageWarning) > 12000000)
  395. // {
  396. // GAudioOutput::instance()->say(QString("voltage warning: %1 volts").arg(lpVoltage, 0, 'f', 1, QChar(' ')));
  397. // lastVoltageWarning = QGC::groundTimeUsecs();
  398. // lastTickVoltageValue = tickLowpassVoltage;
  399. // }
  400. // if (startVoltage == -1.0 && currentVoltage > 0.1) startVoltage = currentVoltage;
  401. // timeRemaining = calculateTimeRemaining();
  402. // if (!batteryRemainingEstimateEnabled && chargeLevel != -1)
  403. // {
  404. // chargeLevel = m_pProtocol->m_sSystemStatus.battery_remaining;
  405. // }
  406. // emit batteryChanged(this, lpVoltage, currentCurrent, getChargeLevel(), timeRemaining);
  407. // emit voltageChanged(message.sysid, currentVoltage);
  408. // emit valueChanged(uasId, statusName().arg("Battery"), "%", m_sSystemStatus.battery_remaining, time);
  409. // emit valueChanged(uasId, statusName().arg("Voltage"), "V", m_sSystemStatus.voltage_battery / 1000.0, time);
  410. // And if the battery current draw is measured, log that also.
  411. // if (m_sSystemStatus.current_battery != -1)
  412. // {
  413. // currentCurrent = ((double)m_sSystemStatus.current_battery) / 100.0;
  414. // emit valueChanged(uasId, statusName().arg("Current"), "A", currentCurrent, time);
  415. // }
  416. // LOW BATTERY ALARM
  417. // if (lpVoltage < warnVoltage && (currentVoltage - 0.2) < warnVoltage && (currentVoltage > 3.3))
  418. // {
  419. // An audio alarm. Does not generate any signals.
  420. // startLowBattAlarm();
  421. // }
  422. // else
  423. // {
  424. // stopLowBattAlarm();
  425. // }
  426. // control_sensors_enabled:
  427. // relevant bits: 11: attitude stabilization, 12: yaw position, 13: z/altitude control, 14: x/y position control
  428. // emit attitudeControlEnabled(m_sSystemStatus.onboard_control_sensors_enabled & (1 << 11));
  429. // emit positionYawControlEnabled(m_sSystemStatus.onboard_control_sensors_enabled & (1 << 12));
  430. // emit positionZControlEnabled(m_sSystemStatus.onboard_control_sensors_enabled & (1 << 13));
  431. // emit positionXYControlEnabled(m_sSystemStatus.onboard_control_sensors_enabled & (1 << 14));
  432. // Trigger drop rate updates as needed. Here we convert the incoming
  433. // drop_rate_comm value from 1/100 of a percent in a uint16 to a true
  434. // percentage as a float. We also cap the incoming value at 100% as defined
  435. // by the MAVLink specifications.
  436. // if (m_sSystemStatus.drop_rate_comm > 10000) {
  437. // m_sSystemStatus.drop_rate_comm = 10000;
  438. // };
  439. // emit dropRateChanged(this->getUASID(), m_sSystemStatus.drop_rate_comm / 100.0);
  440. // emit valueChanged(uasId, statusName().arg("Comms Drop Rate"), "%", m_sSystemStatus.drop_rate_comm / 100.0, time);
  441. }
  442. SLEEP(20);
  443. };
  444. }
  445. CSTR objectFlyHunter::getVehicleName()
  446. {
  447. if (m_eCurrentMode > FH_WAIT_FOR_UAV)
  448. {
  449. switch (m_bUAV_type)
  450. {
  451. case MAV_TYPE_GENERIC : return (CSTR) "Generic micro air vehicle";
  452. case MAV_TYPE_FIXED_WING : return (CSTR) "Fixed wing aircraft.";
  453. case MAV_TYPE_QUADROTOR : return (CSTR) "Quadrotor";
  454. case MAV_TYPE_COAXIAL : return (CSTR) "Coaxial helicopter";
  455. case MAV_TYPE_HELICOPTER : return (CSTR) "Normal helicopter with tail rotor.";
  456. case MAV_TYPE_ANTENNA_TRACKER : return (CSTR) "Ground installation";
  457. case MAV_TYPE_GCS : return (CSTR) "Operator control unit / ground control station";
  458. case MAV_TYPE_AIRSHIP : return (CSTR) "Airship, controlled";
  459. case MAV_TYPE_FREE_BALLOON : return (CSTR) "Free balloon, uncontrolled";
  460. case MAV_TYPE_ROCKET : return (CSTR) "Rocket";
  461. case MAV_TYPE_GROUND_ROVER : return (CSTR) "Ground rover";
  462. case MAV_TYPE_SURFACE_BOAT : return (CSTR) "Surface vessel, boat, ship";
  463. case MAV_TYPE_SUBMARINE : return (CSTR) "Submarine";
  464. case MAV_TYPE_HEXAROTOR : return (CSTR) "Hexarotor";
  465. case MAV_TYPE_OCTOROTOR : return (CSTR) "Octorotor";
  466. case MAV_TYPE_TRICOPTER : return (CSTR) "Tricopter";
  467. case MAV_TYPE_FLAPPING_WING : return (CSTR) "Flapping wing";
  468. case MAV_TYPE_KITE : return (CSTR) "Kite";
  469. case MAV_TYPE_ONBOARD_CONTROLLER: return (CSTR) "Onboard companion controller";
  470. case MAV_TYPE_VTOL_DUOROTOR : return (CSTR) "Two-rotor VTOL using control surfaces in vertical operation in addition. Tailsitter.";
  471. case MAV_TYPE_VTOL_QUADROTOR : return (CSTR) "Quad-rotor VTOL using a V-shaped quad config in vertical operation. Tailsitter.";
  472. case MAV_TYPE_VTOL_TILTROTOR : return (CSTR) "Tiltrotor VTOL";
  473. case MAV_TYPE_VTOL_RESERVED2 : return (CSTR) "VTOL reserved 2";
  474. case MAV_TYPE_VTOL_RESERVED3 : return (CSTR) "VTOL reserved 3";
  475. case MAV_TYPE_VTOL_RESERVED4 : return (CSTR) "VTOL reserved 4";
  476. case MAV_TYPE_VTOL_RESERVED5 : return (CSTR) "VTOL reserved 5";
  477. case MAV_TYPE_GIMBAL : return (CSTR) "Gimbal";
  478. case MAV_TYPE_ADSB : return (CSTR) "ADSB system";
  479. case MAV_TYPE_PARAFOIL : return (CSTR) "Steerable, nonrigid airfoil";
  480. case MAV_TYPE_DODECAROTOR : return (CSTR) "Dodecarotor";
  481. case MAV_TYPE_CAMERA : return (CSTR) "Camera";
  482. case MAV_TYPE_CHARGING_STATION : return (CSTR) "Charging station";
  483. case MAV_TYPE_FLARM : return (CSTR) "FLARM collision avoidance system";
  484. case MAV_TYPE_SERVO : return (CSTR) "Servo";
  485. };
  486. return (CSTR) "Unknown Type";
  487. };
  488. return (CSTR) "Not Connected";
  489. }
  490. CSTR objectFlyHunter::getCtrlName()
  491. {
  492. if (m_eCurrentMode > FH_WAIT_FOR_UAV)
  493. {
  494. switch (m_bUAV_ctrl)
  495. {
  496. case MAV_AUTOPILOT_GENERIC : return (CSTR) "Generic autopilot, full support for everything";
  497. case MAV_AUTOPILOT_RESERVED : return (CSTR) "Reserved for future use.";
  498. case MAV_AUTOPILOT_SLUGS : return (CSTR) "SLUGS autopilot";
  499. case MAV_AUTOPILOT_ARDUPILOTMEGA : return (CSTR) "ArduPilot - Plane/Copter/Rover/Sub/Tracker";
  500. case MAV_AUTOPILOT_OPENPILOT : return (CSTR) "OpenPilot";
  501. case MAV_AUTOPILOT_GENERIC_WAYPOINTS_ONLY : return (CSTR) "Generic autopilot only supporting simple waypoints";
  502. case MAV_AUTOPILOT_GENERIC_WAYPOINTS_AND_SIMPLE_NAVIGATION_ONLY: return (CSTR) "Generic autopilot supporting waypoints and other simple navigation commands";
  503. case MAV_AUTOPILOT_GENERIC_MISSION_FULL : return (CSTR) "Generic autopilot supporting the full mission command set";
  504. case MAV_AUTOPILOT_INVALID : return (CSTR) "No valid autopilot, e.g. a GCS or other MAVLink component";
  505. case MAV_AUTOPILOT_PPZ : return (CSTR) "PPZ UAV";
  506. case MAV_AUTOPILOT_UDB : return (CSTR) "UAV Dev Board";
  507. case MAV_AUTOPILOT_FP : return (CSTR) "FlexiPilot";
  508. case MAV_AUTOPILOT_PX4 : return (CSTR) "PX4 Autopilot";
  509. case MAV_AUTOPILOT_SMACCMPILOT : return (CSTR) "SMACCMPilot";
  510. case MAV_AUTOPILOT_AUTOQUAD : return (CSTR) "AutoQuad";
  511. case MAV_AUTOPILOT_ARMAZILA : return (CSTR) "Armazila";
  512. case MAV_AUTOPILOT_AEROB : return (CSTR) "Aerob";
  513. case MAV_AUTOPILOT_ASLUAV : return (CSTR) "ASLUAV autopilot";
  514. case MAV_AUTOPILOT_SMARTAP : return (CSTR) "SmartAP Autopilot";
  515. case MAV_AUTOPILOT_AIRRAILS : return (CSTR) "AirRails";
  516. };
  517. return (CSTR) "Unknown Control Module";
  518. };
  519. return (CSTR) "Not Connected";
  520. }
  521. bool objectFlyHunter::arm()
  522. {
  523. FH_COMMAND * tPtr;
  524. tPtr = (FH_COMMAND *) malloc(sizeof(FH_COMMAND));
  525. if (tPtr != NULL)
  526. {
  527. tPtr->data = NULL;
  528. tPtr->type = FH_CMD_ARM;
  529. m_qQueuedCommands.push(tPtr);
  530. return true;
  531. };
  532. return false;
  533. }
  534. bool objectFlyHunter::forceArm()
  535. {
  536. FH_COMMAND * tPtr;
  537. tPtr = (FH_COMMAND *) malloc(sizeof(FH_COMMAND));
  538. if (tPtr != NULL)
  539. {
  540. tPtr->data = NULL;
  541. tPtr->type = FH_CMD_FORCE_ARM;
  542. m_qQueuedCommands.push(tPtr);
  543. return true;
  544. };
  545. return false;
  546. }
  547. bool objectFlyHunter::disarm()
  548. {
  549. FH_COMMAND * tPtr;
  550. tPtr = (FH_COMMAND *) malloc(sizeof(FH_COMMAND));
  551. if (tPtr != NULL)
  552. {
  553. tPtr->data = NULL;
  554. tPtr->type = FH_CMD_DISARM;
  555. m_qQueuedCommands.push(tPtr);
  556. return true;
  557. };
  558. return false;
  559. }
  560. bool objectFlyHunter::reset()
  561. {
  562. FH_COMMAND * tPtr;
  563. tPtr = (FH_COMMAND *) malloc(sizeof(FH_COMMAND));
  564. if (tPtr != NULL)
  565. {
  566. tPtr->data = NULL;
  567. tPtr->type = FH_CMD_RESET;
  568. m_qQueuedCommands.push(tPtr);
  569. return true;
  570. };
  571. return false;
  572. }
  573. bool objectFlyHunter::takeOff()
  574. {
  575. FH_COMMAND * tPtr;
  576. tPtr = (FH_COMMAND *) malloc(sizeof(FH_COMMAND));
  577. if (tPtr != NULL)
  578. {
  579. tPtr->data = NULL;
  580. tPtr->type = FH_CMD_TAKEOFF;
  581. m_qQueuedCommands.push(tPtr);
  582. return true;
  583. };
  584. return false;
  585. }
  586. bool objectFlyHunter::land()
  587. {
  588. FH_COMMAND * tPtr;
  589. tPtr = (FH_COMMAND *) malloc(sizeof(FH_COMMAND));
  590. if (tPtr != NULL)
  591. {
  592. tPtr->data = NULL;
  593. tPtr->type = FH_CMD_LAND;
  594. m_qQueuedCommands.push(tPtr);
  595. return true;
  596. };
  597. return false;
  598. }
  599. uint8_t objectFlyHunter::getVehicleSystemMode()
  600. {
  601. return m_bUAV_bMODE;
  602. }
  603. uint32_t objectFlyHunter::getVehicleAutoPilotMode()
  604. {
  605. return m_nUAV_cMODE;
  606. }
  607. CSTR objectFlyHunter::getVehicleSystemModeName()
  608. {
  609. if (m_eCurrentMode > FH_WAIT_FOR_UAV)
  610. {
  611. char tBuffer[256];
  612. sprintf(tBuffer, "%s%s%s%s%s%s%s%s", (m_bUAV_bMODE & MAV_MODE_FLAG_CUSTOM_MODE_ENABLED) ? "CUS_" : "", (m_bUAV_bMODE & MAV_MODE_FLAG_MANUAL_INPUT_ENABLED) ? "MAN_" : "", (m_bUAV_bMODE & MAV_MODE_FLAG_HIL_ENABLED) ? "HIL_" : "",
  613. (m_bUAV_bMODE & MAV_MODE_FLAG_STABILIZE_ENABLED) ? "STB_" : "", (m_bUAV_bMODE & MAV_MODE_FLAG_GUIDED_ENABLED) ? "GID_" : "", (m_bUAV_bMODE & MAV_MODE_FLAG_AUTO_ENABLED) ? "AUT_" : "",
  614. (m_bUAV_bMODE & MAV_MODE_FLAG_TEST_ENABLED) ? "TST_" : "", (m_bUAV_bMODE & MAV_MODE_FLAG_SAFETY_ARMED) ? "ARM" : "");
  615. return _strdup(tBuffer);
  616. };
  617. return NULL;
  618. }
  619. CSTR objectFlyHunter::getVehicleAutoPilotModeName(int32_t c_mode)
  620. {
  621. if (m_eCurrentMode > FH_WAIT_FOR_UAV)
  622. {
  623. switch (m_nUAV_cMODE)
  624. {
  625. case STABILIZE: return (CSTR) "STABILIZE: hold level position";
  626. case ACRO : return (CSTR) "ACRO: hold rate control";
  627. case ALT_HOLD : return (CSTR) "ALT_HOLD: hold altitude";
  628. case AUTO : return (CSTR) "AUTO: RC";
  629. case GUIDED : return (CSTR) "GUIDED: auto";
  630. case LOITER : return (CSTR) "LOITER: hold a single location";
  631. case RTL : return (CSTR) "RTL: auto";
  632. case CIRCLE : return (CSTR) "CIRCLE: auto";
  633. // case POSITION: return (CSTR)"POSITION: deprecated";
  634. case LAND: return (CSTR) "LAND: auto";
  635. // case OF_LOITER: return (CSTR)"OF_LOITER: deprecated";
  636. case DRIFT: return (CSTR) "DRIFT: drift 'Car Like' mode";
  637. // case RESERVED_12: return (CSTR)"RESERVED_12: FU";
  638. case SPORT : return (CSTR) "SPORT: auto";
  639. case FLIP : return (CSTR) "FLIP: auto";
  640. case AUTOTUNE: return (CSTR) "AUTOTUNE: auto";
  641. // case POS_HOLD: return (CSTR)"POS_HOLD: HYBRID LOITER";
  642. case BRAKE : return (CSTR) "BRAKE: auto";
  643. case THROW : return (CSTR) "THROW: auto";
  644. case AVOID_ADSB : return (CSTR) "AVOID_ADSB: auto";
  645. case GUIDED_NOGPS: return (CSTR) "GUIDED_NOGPS: auto";
  646. case SMART_RTL : return (CSTR) "SMART_RTL: returns to home by retracing its steps";
  647. case FLOWHOLD : return (CSTR) "FLOWHOLD: holds position with optical flow without rangefinder";
  648. case FOLLOW : return (CSTR) "FOLLOW: attempts to follow another vehicle or ground station";
  649. case ZIGZAG : return (CSTR) "ZIGZAG: auto";
  650. };
  651. };
  652. return NULL;
  653. }
  654. bool objectFlyHunter::isGpsPresent()
  655. {
  656. bool rV = false;
  657. m_mAccessProtector.lock();
  658. if (m_pProtocol != NULL)
  659. {
  660. if (m_pProtocol->m_bUAV_Online)
  661. {
  662. rV = m_pProtocol->m_bGpsStatusDataActual || m_pProtocol->m_bGpsRawIntDataActual;
  663. }
  664. };
  665. m_mAccessProtector.unlock();
  666. return rV;
  667. }
  668. bool objectFlyHunter::isPositionAccurate()
  669. {
  670. bool rV = false;
  671. m_mAccessProtector.lock();
  672. if (m_pProtocol != NULL)
  673. {
  674. if (m_pProtocol->m_bUAV_Online && m_pProtocol->m_bGpsRawIntDataActual)
  675. {
  676. rV = m_pProtocol->m_sGpsRaw.fix_type > GPS_FIX_TYPE_NO_FIX;
  677. };
  678. };
  679. m_mAccessProtector.unlock();
  680. return rV;
  681. }
  682. bool objectFlyHunter::isPositionIs3D()
  683. {
  684. bool rV = false;
  685. m_mAccessProtector.lock();
  686. if (m_pProtocol != NULL)
  687. {
  688. if (m_pProtocol->m_bUAV_Online && m_pProtocol->m_bGpsRawIntDataActual)
  689. {
  690. rV = m_pProtocol->m_sGpsRaw.fix_type > GPS_FIX_TYPE_2D_FIX;
  691. };
  692. };
  693. m_mAccessProtector.unlock();
  694. return rV;
  695. }
  696. mavlink_vfr_hud_t * objectFlyHunter::getVFRData()
  697. {
  698. mavlink_vfr_hud_t * rV = NULL;
  699. m_mAccessProtector.lock();
  700. if (m_pProtocol != NULL)
  701. {
  702. if (m_pProtocol->m_bUAV_Online && m_pProtocol->m_bGpsRawIntDataActual)
  703. {
  704. rV = &m_pProtocol->m_sVFR_Hud;
  705. };
  706. };
  707. m_mAccessProtector.unlock();
  708. return rV;
  709. }
  710. mavlink_power_status_t * objectFlyHunter::getPowerStatusData()
  711. {
  712. mavlink_power_status_t * rV = NULL;
  713. m_mAccessProtector.lock();
  714. if (m_pProtocol != NULL)
  715. {
  716. if (m_pProtocol->m_bUAV_Online && m_pProtocol->m_bGpsRawIntDataActual)
  717. {
  718. rV = &m_pProtocol->m_sPowerStatus;
  719. };
  720. };
  721. m_mAccessProtector.unlock();
  722. return rV;
  723. }
  724. float objectFlyHunter::getBodyRoll()
  725. {
  726. float rV = 0.f;
  727. m_mAccessProtector.lock();
  728. if (m_pProtocol != NULL)
  729. {
  730. // rV = m_pProtocol->m_sRawIMU.xgyro;
  731. rV = m_pProtocol->m_sScaledIMU.xgyro / 1000.f;
  732. };
  733. m_mAccessProtector.unlock();
  734. return rV;
  735. }
  736. float objectFlyHunter::getBodyPitch()
  737. {
  738. float rV = 0.f;
  739. m_mAccessProtector.lock();
  740. if (m_pProtocol != NULL)
  741. {
  742. // rV = m_pProtocol->m_sRawIMU.ygyro;
  743. rV = m_pProtocol->m_sScaledIMU.ygyro / 1000.f;
  744. };
  745. m_mAccessProtector.unlock();
  746. return rV;
  747. }
  748. float objectFlyHunter::getBodyYaw()
  749. {
  750. float rV = 0.f;
  751. m_mAccessProtector.lock();
  752. if (m_pProtocol != NULL)
  753. {
  754. // rV = m_pProtocol->m_sRawIMU.zgyro;
  755. rV = m_pProtocol->m_sScaledIMU.zgyro / 1000.f;
  756. };
  757. m_mAccessProtector.unlock();
  758. return rV;
  759. }
  760. void objectFlyHunter::setJoystickRoll(int16_t value) {}
  761. void objectFlyHunter::setJoystickPitch(int16_t value) {}
  762. void objectFlyHunter::setJoystickYaw(int16_t value) {}
  763. void objectFlyHunter::setJoistickThrottle(int16_t value) {}
  764. #undef LOG
  765. #undef LOG_ERROR