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.

813 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. while (m_bThreadStatus < TH_ENDED)
  212. {
  213. if (m_qQueuedCommands.size())
  214. {
  215. pCMD = m_qQueuedCommands.front();
  216. }
  217. else
  218. {
  219. pCMD = NULL;
  220. }
  221. if (m_pProtocol->getConnectionStatus() == CS_DISCONNECTED)
  222. {
  223. m_eCurrentMode = FH_CONNECTION_ERROR;
  224. };
  225. switch (m_eCurrentMode)
  226. {
  227. case FH_CONNECTION_ERROR: break;
  228. case FH_NO_CONNECTION:
  229. if (m_pProtocol->getConnectionStatus() == CS_CONNECTED)
  230. {
  231. m_eCurrentMode = FH_WAIT_FOR_UAV;
  232. }
  233. break;
  234. case FH_WAIT_FOR_UAV:
  235. if (m_pProtocol->m_bPairingFinished)
  236. {
  237. m_eCurrentMode = FH_MODE_PREFLIGHT;
  238. }
  239. break;
  240. case FH_MODE_PREFLIGHT:
  241. if (pCMD != NULL)
  242. {
  243. switch (pCMD->type)
  244. {
  245. case FH_CMD_SET_BASE_MODE:
  246. if (pCMD->data != NULL)
  247. {
  248. uint8_t tMode;
  249. tMode = m_bUAV_bMODE | *((uint8_t *) pCMD->data);
  250. m_pProtocol->broadcastSetBaseMode(tMode);
  251. };
  252. break;
  253. case FH_CMD_SET_AP_MODE:
  254. if (pCMD->data != NULL)
  255. {
  256. uint32_t tMode;
  257. tMode = m_bUAV_bMODE | *((uint32_t *) pCMD->data);
  258. m_pProtocol->broadcastSetCustomMode(tMode);
  259. };
  260. break;
  261. case FH_CMD_FORCE_ARM:
  262. {
  263. m_pProtocol->broadcastArm(true, true);
  264. m_eCurrentMode = FH_MODE_ARMING;
  265. break;
  266. };
  267. case FH_CMD_ARM:
  268. {
  269. m_pProtocol->broadcastArm(true);
  270. m_eCurrentMode = FH_MODE_ARMING;
  271. break;
  272. };
  273. case FH_CMD_DISARM:
  274. {
  275. //?? Why at preflight mode!!
  276. m_pProtocol->broadcastArm(false);
  277. m_eCurrentMode = FH_MODE_DISARMING;
  278. break;
  279. };
  280. };
  281. };
  282. break;
  283. case FH_MODE_ARMING:
  284. if (m_pProtocol->getLastCmdStatus() > -1)
  285. {
  286. if (m_pProtocol->getLastCmdStatus() == MAV_RESULT_ACCEPTED)
  287. {
  288. m_eCurrentMode = FH_MODE_ARMED;
  289. }
  290. else
  291. {
  292. m_eCurrentMode = FH_MODE_PREFLIGHT;
  293. };
  294. };
  295. break;
  296. case FH_MODE_ARMED:
  297. if (pCMD != NULL)
  298. {
  299. switch (pCMD->type)
  300. {
  301. case FH_CMD_SET_BASE_MODE:
  302. if (pCMD->data != NULL)
  303. {
  304. uint8_t tMode;
  305. tMode = m_bUAV_bMODE | *((uint8_t *) pCMD->data);
  306. m_pProtocol->setMode(tMode);
  307. };
  308. break;
  309. case FH_CMD_SET_AP_MODE:
  310. if (pCMD->data != NULL)
  311. {
  312. uint32_t tMode;
  313. tMode = m_bUAV_bMODE | *((uint32_t *) pCMD->data);
  314. m_pProtocol->broadcastSetCustomMode(tMode);
  315. };
  316. break;
  317. case FH_CMD_ARM:
  318. {
  319. //?? Why at ARMED mode!!
  320. m_pProtocol->broadcastArm(true);
  321. m_eCurrentMode = FH_MODE_ARMING;
  322. break;
  323. };
  324. case FH_CMD_DISARM:
  325. {
  326. m_pProtocol->broadcastArm(false);
  327. m_eCurrentMode = FH_MODE_DISARMING;
  328. break;
  329. };
  330. };
  331. };
  332. break;
  333. case FH_MODE_DISARMING: break;
  334. };
  335. if (m_eCurrentMode > FH_WAIT_FOR_UAV)
  336. {
  337. // Update statuses
  338. m_bUAV_type = m_pProtocol->m_sHeartBit.type;
  339. m_bUAV_ctrl = m_pProtocol->m_sHeartBit.autopilot;
  340. m_bUAV_bMODE = m_pProtocol->m_sHeartBit.base_mode;
  341. m_nUAV_cMODE = m_pProtocol->m_sHeartBit.custom_mode;
  342. // if Position Accurate
  343. float roll = 0.f, pitch = 0.f, yaw = 0.f;
  344. roll = m_pProtocol->m_sAttitude.roll;
  345. pitch = m_pProtocol->m_sAttitude.pitch;
  346. yaw = m_pProtocol->m_sAttitude.yaw;
  347. m_oPosition.setOrientationRad(roll, pitch, yaw);
  348. if (updateOrientation != NULL)
  349. {
  350. updateOrientation(m_oPosition.getRotX_deg(), m_oPosition.getRotY_deg(), m_oPosition.getRotZ_deg());
  351. }
  352. };
  353. if (pCMD != NULL)
  354. {
  355. if (pCMD->data != NULL)
  356. {
  357. free(pCMD->data);
  358. }
  359. m_qQueuedCommands.pop();
  360. };
  361. // Update Data FROM UAV
  362. if (m_pProtocol->m_bSystemStatusDataActual)
  363. {
  364. m_pProtocol->m_bSystemStatusDataActual = false;
  365. // Prepare for sending data to the realtime plotter, which is every field excluding onboard_control_sensors_present.
  366. // quint64 time = getUnixTime();
  367. // emit valueChanged(uasId, statusName().arg("Sensors Enabled"), "bits", state.onboard_control_sensors_enabled, time);
  368. // emit valueChanged(uasId, statusName().arg("Sensors Health"), "bits", state.onboard_control_sensors_health, time);
  369. // emit valueChanged(uasId, statusName().arg("Comms Errors"), "-", state.errors_comm, time);
  370. // emit valueChanged(uasId, statusName().arg("Errors Count 1"), "-", state.errors_count1, time);
  371. // emit valueChanged(uasId, statusName().arg("Errors Count 2"), "-", state.errors_count2, time);
  372. // emit valueChanged(uasId, statusName().arg("Errors Count 3"), "-", state.errors_count3, time);
  373. // emit valueChanged(uasId, statusName().arg("Errors Count 4"), "-", state.errors_count4, time);
  374. // Process CPU load.
  375. // emit loadChanged(this, m_sSystemStatus.load / 10.0);
  376. // emit valueChanged(uasId, statusName().arg("CPU Load"), "%", m_sSystemStatus.load / 10.0, time);
  377. // Battery charge/time remaining/voltage calculations
  378. double currentVoltage = m_pProtocol->m_sSystemStatus.voltage_battery / 1000.0;
  379. double lpVoltage = filterVoltage(currentVoltage);
  380. // tickLowpassVoltage = tickLowpassVoltage * 0.8 + 0.2 * currentVoltage;
  381. // We don't want to tick above the threshold
  382. // if (tickLowpassVoltage > tickVoltage) {
  383. // lastTickVoltageValue = tickLowpassVoltage;
  384. // };
  385. // if ((startVoltage > 0.0) && (tickLowpassVoltage < tickVoltage) && (fabs(lastTickVoltageValue - tickLowpassVoltage) > 0.1)
  386. /* warn if lower than treshold */
  387. // && (lpVoltage < tickVoltage)
  388. /* warn only if we have at least the voltage of an empty LiPo cell, else we're sampling something wrong */
  389. // && (currentVoltage > 3.3)
  390. /* warn only if current voltage is really still lower by a reasonable amount */
  391. // && ((currentVoltage - 0.2) < tickVoltage)
  392. /* warn only every 12 seconds */
  393. // && (QGC::groundTimeUsecs() - lastVoltageWarning) > 12000000)
  394. // {
  395. // GAudioOutput::instance()->say(QString("voltage warning: %1 volts").arg(lpVoltage, 0, 'f', 1, QChar(' ')));
  396. // lastVoltageWarning = QGC::groundTimeUsecs();
  397. // lastTickVoltageValue = tickLowpassVoltage;
  398. // }
  399. // if (startVoltage == -1.0 && currentVoltage > 0.1) startVoltage = currentVoltage;
  400. // timeRemaining = calculateTimeRemaining();
  401. // if (!batteryRemainingEstimateEnabled && chargeLevel != -1)
  402. // {
  403. // chargeLevel = m_pProtocol->m_sSystemStatus.battery_remaining;
  404. // }
  405. // emit batteryChanged(this, lpVoltage, currentCurrent, getChargeLevel(), timeRemaining);
  406. // emit voltageChanged(message.sysid, currentVoltage);
  407. // emit valueChanged(uasId, statusName().arg("Battery"), "%", m_sSystemStatus.battery_remaining, time);
  408. // emit valueChanged(uasId, statusName().arg("Voltage"), "V", m_sSystemStatus.voltage_battery / 1000.0, time);
  409. // And if the battery current draw is measured, log that also.
  410. // if (m_sSystemStatus.current_battery != -1)
  411. // {
  412. // currentCurrent = ((double)m_sSystemStatus.current_battery) / 100.0;
  413. // emit valueChanged(uasId, statusName().arg("Current"), "A", currentCurrent, time);
  414. // }
  415. // LOW BATTERY ALARM
  416. // if (lpVoltage < warnVoltage && (currentVoltage - 0.2) < warnVoltage && (currentVoltage > 3.3))
  417. // {
  418. // An audio alarm. Does not generate any signals.
  419. // startLowBattAlarm();
  420. // }
  421. // else
  422. // {
  423. // stopLowBattAlarm();
  424. // }
  425. // control_sensors_enabled:
  426. // relevant bits: 11: attitude stabilization, 12: yaw position, 13: z/altitude control, 14: x/y position control
  427. // emit attitudeControlEnabled(m_sSystemStatus.onboard_control_sensors_enabled & (1 << 11));
  428. // emit positionYawControlEnabled(m_sSystemStatus.onboard_control_sensors_enabled & (1 << 12));
  429. // emit positionZControlEnabled(m_sSystemStatus.onboard_control_sensors_enabled & (1 << 13));
  430. // emit positionXYControlEnabled(m_sSystemStatus.onboard_control_sensors_enabled & (1 << 14));
  431. // Trigger drop rate updates as needed. Here we convert the incoming
  432. // drop_rate_comm value from 1/100 of a percent in a uint16 to a true
  433. // percentage as a float. We also cap the incoming value at 100% as defined
  434. // by the MAVLink specifications.
  435. // if (m_sSystemStatus.drop_rate_comm > 10000) {
  436. // m_sSystemStatus.drop_rate_comm = 10000;
  437. // };
  438. // emit dropRateChanged(this->getUASID(), m_sSystemStatus.drop_rate_comm / 100.0);
  439. // emit valueChanged(uasId, statusName().arg("Comms Drop Rate"), "%", m_sSystemStatus.drop_rate_comm / 100.0, time);
  440. }
  441. SLEEP(20);
  442. };
  443. }
  444. CSTR objectFlyHunter::getVehicleName()
  445. {
  446. if (m_eCurrentMode > FH_WAIT_FOR_UAV)
  447. {
  448. switch (m_bUAV_type)
  449. {
  450. case MAV_TYPE_GENERIC : return (CSTR) "Generic micro air vehicle";
  451. case MAV_TYPE_FIXED_WING : return (CSTR) "Fixed wing aircraft.";
  452. case MAV_TYPE_QUADROTOR : return (CSTR) "Quadrotor";
  453. case MAV_TYPE_COAXIAL : return (CSTR) "Coaxial helicopter";
  454. case MAV_TYPE_HELICOPTER : return (CSTR) "Normal helicopter with tail rotor.";
  455. case MAV_TYPE_ANTENNA_TRACKER : return (CSTR) "Ground installation";
  456. case MAV_TYPE_GCS : return (CSTR) "Operator control unit / ground control station";
  457. case MAV_TYPE_AIRSHIP : return (CSTR) "Airship, controlled";
  458. case MAV_TYPE_FREE_BALLOON : return (CSTR) "Free balloon, uncontrolled";
  459. case MAV_TYPE_ROCKET : return (CSTR) "Rocket";
  460. case MAV_TYPE_GROUND_ROVER : return (CSTR) "Ground rover";
  461. case MAV_TYPE_SURFACE_BOAT : return (CSTR) "Surface vessel, boat, ship";
  462. case MAV_TYPE_SUBMARINE : return (CSTR) "Submarine";
  463. case MAV_TYPE_HEXAROTOR : return (CSTR) "Hexarotor";
  464. case MAV_TYPE_OCTOROTOR : return (CSTR) "Octorotor";
  465. case MAV_TYPE_TRICOPTER : return (CSTR) "Tricopter";
  466. case MAV_TYPE_FLAPPING_WING : return (CSTR) "Flapping wing";
  467. case MAV_TYPE_KITE : return (CSTR) "Kite";
  468. case MAV_TYPE_ONBOARD_CONTROLLER: return (CSTR) "Onboard companion controller";
  469. case MAV_TYPE_VTOL_DUOROTOR : return (CSTR) "Two-rotor VTOL using control surfaces in vertical operation in addition. Tailsitter.";
  470. case MAV_TYPE_VTOL_QUADROTOR : return (CSTR) "Quad-rotor VTOL using a V-shaped quad config in vertical operation. Tailsitter.";
  471. case MAV_TYPE_VTOL_TILTROTOR : return (CSTR) "Tiltrotor VTOL";
  472. case MAV_TYPE_VTOL_RESERVED2 : return (CSTR) "VTOL reserved 2";
  473. case MAV_TYPE_VTOL_RESERVED3 : return (CSTR) "VTOL reserved 3";
  474. case MAV_TYPE_VTOL_RESERVED4 : return (CSTR) "VTOL reserved 4";
  475. case MAV_TYPE_VTOL_RESERVED5 : return (CSTR) "VTOL reserved 5";
  476. case MAV_TYPE_GIMBAL : return (CSTR) "Gimbal";
  477. case MAV_TYPE_ADSB : return (CSTR) "ADSB system";
  478. case MAV_TYPE_PARAFOIL : return (CSTR) "Steerable, nonrigid airfoil";
  479. case MAV_TYPE_DODECAROTOR : return (CSTR) "Dodecarotor";
  480. case MAV_TYPE_CAMERA : return (CSTR) "Camera";
  481. case MAV_TYPE_CHARGING_STATION : return (CSTR) "Charging station";
  482. case MAV_TYPE_FLARM : return (CSTR) "FLARM collision avoidance system";
  483. case MAV_TYPE_SERVO : return (CSTR) "Servo";
  484. };
  485. return (CSTR) "Unknown Type";
  486. };
  487. return (CSTR) "Not Connected";
  488. }
  489. CSTR objectFlyHunter::getCtrlName()
  490. {
  491. if (m_eCurrentMode > FH_WAIT_FOR_UAV)
  492. {
  493. switch (m_bUAV_ctrl)
  494. {
  495. case MAV_AUTOPILOT_GENERIC : return (CSTR) "Generic autopilot, full support for everything";
  496. case MAV_AUTOPILOT_RESERVED : return (CSTR) "Reserved for future use.";
  497. case MAV_AUTOPILOT_SLUGS : return (CSTR) "SLUGS autopilot";
  498. case MAV_AUTOPILOT_ARDUPILOTMEGA : return (CSTR) "ArduPilot - Plane/Copter/Rover/Sub/Tracker";
  499. case MAV_AUTOPILOT_OPENPILOT : return (CSTR) "OpenPilot";
  500. case MAV_AUTOPILOT_GENERIC_WAYPOINTS_ONLY : return (CSTR) "Generic autopilot only supporting simple waypoints";
  501. case MAV_AUTOPILOT_GENERIC_WAYPOINTS_AND_SIMPLE_NAVIGATION_ONLY: return (CSTR) "Generic autopilot supporting waypoints and other simple navigation commands";
  502. case MAV_AUTOPILOT_GENERIC_MISSION_FULL : return (CSTR) "Generic autopilot supporting the full mission command set";
  503. case MAV_AUTOPILOT_INVALID : return (CSTR) "No valid autopilot, e.g. a GCS or other MAVLink component";
  504. case MAV_AUTOPILOT_PPZ : return (CSTR) "PPZ UAV";
  505. case MAV_AUTOPILOT_UDB : return (CSTR) "UAV Dev Board";
  506. case MAV_AUTOPILOT_FP : return (CSTR) "FlexiPilot";
  507. case MAV_AUTOPILOT_PX4 : return (CSTR) "PX4 Autopilot";
  508. case MAV_AUTOPILOT_SMACCMPILOT : return (CSTR) "SMACCMPilot";
  509. case MAV_AUTOPILOT_AUTOQUAD : return (CSTR) "AutoQuad";
  510. case MAV_AUTOPILOT_ARMAZILA : return (CSTR) "Armazila";
  511. case MAV_AUTOPILOT_AEROB : return (CSTR) "Aerob";
  512. case MAV_AUTOPILOT_ASLUAV : return (CSTR) "ASLUAV autopilot";
  513. case MAV_AUTOPILOT_SMARTAP : return (CSTR) "SmartAP Autopilot";
  514. case MAV_AUTOPILOT_AIRRAILS : return (CSTR) "AirRails";
  515. };
  516. return (CSTR) "Unknown Control Module";
  517. };
  518. return (CSTR) "Not Connected";
  519. }
  520. bool objectFlyHunter::arm()
  521. {
  522. FH_COMMAND * tPtr;
  523. tPtr = (FH_COMMAND *) malloc(sizeof(FH_COMMAND));
  524. if (tPtr != NULL)
  525. {
  526. tPtr->data = NULL;
  527. tPtr->type = FH_CMD_ARM;
  528. m_qQueuedCommands.push(tPtr);
  529. return true;
  530. };
  531. return false;
  532. }
  533. bool objectFlyHunter::forceArm()
  534. {
  535. FH_COMMAND * tPtr;
  536. tPtr = (FH_COMMAND *) malloc(sizeof(FH_COMMAND));
  537. if (tPtr != NULL)
  538. {
  539. tPtr->data = NULL;
  540. tPtr->type = FH_CMD_FORCE_ARM;
  541. m_qQueuedCommands.push(tPtr);
  542. return true;
  543. };
  544. return false;
  545. }
  546. bool objectFlyHunter::disarm()
  547. {
  548. FH_COMMAND * tPtr;
  549. tPtr = (FH_COMMAND *) malloc(sizeof(FH_COMMAND));
  550. if (tPtr != NULL)
  551. {
  552. tPtr->data = NULL;
  553. tPtr->type = FH_CMD_DISARM;
  554. m_qQueuedCommands.push(tPtr);
  555. return true;
  556. };
  557. return false;
  558. }
  559. bool objectFlyHunter::reset()
  560. {
  561. FH_COMMAND * tPtr;
  562. tPtr = (FH_COMMAND *) malloc(sizeof(FH_COMMAND));
  563. if (tPtr != NULL)
  564. {
  565. tPtr->data = NULL;
  566. tPtr->type = FH_CMD_RESET;
  567. m_qQueuedCommands.push(tPtr);
  568. return true;
  569. };
  570. return false;
  571. }
  572. bool objectFlyHunter::takeOff()
  573. {
  574. FH_COMMAND * tPtr;
  575. tPtr = (FH_COMMAND *) malloc(sizeof(FH_COMMAND));
  576. if (tPtr != NULL)
  577. {
  578. tPtr->data = NULL;
  579. tPtr->type = FH_CMD_TAKEOFF;
  580. m_qQueuedCommands.push(tPtr);
  581. return true;
  582. };
  583. return false;
  584. }
  585. bool objectFlyHunter::land()
  586. {
  587. FH_COMMAND * tPtr;
  588. tPtr = (FH_COMMAND *) malloc(sizeof(FH_COMMAND));
  589. if (tPtr != NULL)
  590. {
  591. tPtr->data = NULL;
  592. tPtr->type = FH_CMD_LAND;
  593. m_qQueuedCommands.push(tPtr);
  594. return true;
  595. };
  596. return false;
  597. }
  598. uint8_t objectFlyHunter::getVehicleSystemMode()
  599. {
  600. return m_bUAV_bMODE;
  601. }
  602. uint32_t objectFlyHunter::getVehicleAutoPilotMode()
  603. {
  604. return m_nUAV_cMODE;
  605. }
  606. CSTR objectFlyHunter::getVehicleSystemModeName()
  607. {
  608. if (m_eCurrentMode > FH_WAIT_FOR_UAV)
  609. {
  610. char tBuffer[256];
  611. 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_" : "",
  612. (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_" : "",
  613. (m_bUAV_bMODE & MAV_MODE_FLAG_TEST_ENABLED) ? "TST_" : "", (m_bUAV_bMODE & MAV_MODE_FLAG_SAFETY_ARMED) ? "ARM" : "");
  614. return _strdup(tBuffer);
  615. };
  616. return NULL;
  617. }
  618. CSTR objectFlyHunter::getVehicleAutoPilotModeName(int32_t c_mode)
  619. {
  620. if (m_eCurrentMode > FH_WAIT_FOR_UAV)
  621. {
  622. switch (m_nUAV_cMODE)
  623. {
  624. case STABILIZE: return (CSTR) "STABILIZE: hold level position";
  625. case ACRO : return (CSTR) "ACRO: hold rate control";
  626. case ALT_HOLD : return (CSTR) "ALT_HOLD: hold altitude";
  627. case AUTO : return (CSTR) "AUTO: RC";
  628. case GUIDED : return (CSTR) "GUIDED: auto";
  629. case LOITER : return (CSTR) "LOITER: hold a single location";
  630. case RTL : return (CSTR) "RTL: auto";
  631. case CIRCLE : return (CSTR) "CIRCLE: auto";
  632. // case POSITION: return (CSTR)"POSITION: deprecated";
  633. case LAND: return (CSTR) "LAND: auto";
  634. // case OF_LOITER: return (CSTR)"OF_LOITER: deprecated";
  635. case DRIFT: return (CSTR) "DRIFT: drift 'Car Like' mode";
  636. // case RESERVED_12: return (CSTR)"RESERVED_12: FU";
  637. case SPORT : return (CSTR) "SPORT: auto";
  638. case FLIP : return (CSTR) "FLIP: auto";
  639. case AUTOTUNE: return (CSTR) "AUTOTUNE: auto";
  640. // case POS_HOLD: return (CSTR)"POS_HOLD: HYBRID LOITER";
  641. case BRAKE : return (CSTR) "BRAKE: auto";
  642. case THROW : return (CSTR) "THROW: auto";
  643. case AVOID_ADSB : return (CSTR) "AVOID_ADSB: auto";
  644. case GUIDED_NOGPS: return (CSTR) "GUIDED_NOGPS: auto";
  645. case SMART_RTL : return (CSTR) "SMART_RTL: returns to home by retracing its steps";
  646. case FLOWHOLD : return (CSTR) "FLOWHOLD: holds position with optical flow without rangefinder";
  647. case FOLLOW : return (CSTR) "FOLLOW: attempts to follow another vehicle or ground station";
  648. case ZIGZAG : return (CSTR) "ZIGZAG: auto";
  649. };
  650. };
  651. return NULL;
  652. }
  653. bool objectFlyHunter::isGpsPresent()
  654. {
  655. bool rV = false;
  656. m_mAccessProtector.lock();
  657. if (m_pProtocol != NULL)
  658. {
  659. if (m_pProtocol->m_bUAV_Online)
  660. {
  661. rV = m_pProtocol->m_bGpsStatusDataActual || m_pProtocol->m_bGpsRawIntDataActual;
  662. }
  663. };
  664. m_mAccessProtector.unlock();
  665. return rV;
  666. }
  667. bool objectFlyHunter::isPositionAccurate()
  668. {
  669. bool rV = false;
  670. m_mAccessProtector.lock();
  671. if (m_pProtocol != NULL)
  672. {
  673. if (m_pProtocol->m_bUAV_Online && m_pProtocol->m_bGpsRawIntDataActual)
  674. {
  675. rV = m_pProtocol->m_sGpsRaw.fix_type > GPS_FIX_TYPE_NO_FIX;
  676. };
  677. };
  678. m_mAccessProtector.unlock();
  679. return rV;
  680. }
  681. bool objectFlyHunter::isPositionIs3D()
  682. {
  683. bool rV = false;
  684. m_mAccessProtector.lock();
  685. if (m_pProtocol != NULL)
  686. {
  687. if (m_pProtocol->m_bUAV_Online && m_pProtocol->m_bGpsRawIntDataActual)
  688. {
  689. rV = m_pProtocol->m_sGpsRaw.fix_type > GPS_FIX_TYPE_2D_FIX;
  690. };
  691. };
  692. m_mAccessProtector.unlock();
  693. return rV;
  694. }
  695. mavlink_vfr_hud_t * objectFlyHunter::getVFRData()
  696. {
  697. mavlink_vfr_hud_t * rV = NULL;
  698. m_mAccessProtector.lock();
  699. if (m_pProtocol != NULL)
  700. {
  701. if (m_pProtocol->m_bUAV_Online && m_pProtocol->m_bGpsRawIntDataActual)
  702. {
  703. rV = &m_pProtocol->m_sVFR_Hud;
  704. };
  705. };
  706. m_mAccessProtector.unlock();
  707. return rV;
  708. }
  709. mavlink_power_status_t * objectFlyHunter::getPowerStatusData()
  710. {
  711. mavlink_power_status_t * rV = NULL;
  712. m_mAccessProtector.lock();
  713. if (m_pProtocol != NULL)
  714. {
  715. if (m_pProtocol->m_bUAV_Online && m_pProtocol->m_bGpsRawIntDataActual)
  716. {
  717. rV = &m_pProtocol->m_sPowerStatus;
  718. };
  719. };
  720. m_mAccessProtector.unlock();
  721. return rV;
  722. }
  723. float objectFlyHunter::getBodyRoll()
  724. {
  725. float rV = 0.f;
  726. m_mAccessProtector.lock();
  727. if (m_pProtocol != NULL)
  728. {
  729. // rV = m_pProtocol->m_sRawIMU.xgyro;
  730. rV = m_pProtocol->m_sScaledIMU.xgyro / 1000.f;
  731. };
  732. m_mAccessProtector.unlock();
  733. return rV;
  734. }
  735. float objectFlyHunter::getBodyPitch()
  736. {
  737. float rV = 0.f;
  738. m_mAccessProtector.lock();
  739. if (m_pProtocol != NULL)
  740. {
  741. // rV = m_pProtocol->m_sRawIMU.ygyro;
  742. rV = m_pProtocol->m_sScaledIMU.ygyro / 1000.f;
  743. };
  744. m_mAccessProtector.unlock();
  745. return rV;
  746. }
  747. float objectFlyHunter::getBodyYaw()
  748. {
  749. float rV = 0.f;
  750. m_mAccessProtector.lock();
  751. if (m_pProtocol != NULL)
  752. {
  753. // rV = m_pProtocol->m_sRawIMU.zgyro;
  754. rV = m_pProtocol->m_sScaledIMU.zgyro / 1000.f;
  755. };
  756. m_mAccessProtector.unlock();
  757. return rV;
  758. }
  759. void objectFlyHunter::setJoystickRoll(int16_t value) {}
  760. void objectFlyHunter::setJoystickPitch(int16_t value) {}
  761. void objectFlyHunter::setJoystickYaw(int16_t value) {}
  762. void objectFlyHunter::setJoistickThrottle(int16_t value) {}
  763. #undef LOG
  764. #undef LOG_ERROR