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.

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